i18n

package module
v0.0.0-...-987a633 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2017 License: Apache-2.0 Imports: 5 Imported by: 47

README

i18n GoDoc build status

Package i18n is for app Internationalization and Localization.

This package is a fork of the https://github.com/Unknwon/i18n.

It's heavly used inside the https://github.com/kataras/iris/tree/master/middleware/i18n middleware.

Changes

This package provides some additional functionality compared to the original one;

PATCH by @j-lenoch at L129:

// IsExistSimilar returns true if the language, or something similar
// exists (e.g. en-US maps to en).
// it returns the found name and whether it was able to match something.
func IsExistSimilar(lang string) (string, bool) {
_, ok := locales.store[lang]
if ok {
    return lang, true
}

// remove the internationalization element from the IETF code
code := strings.Split(lang, "-")[0]

for _, lc := range locales.store {
    if strings.Contains(lc.lang, code) {
        return lc.lang, true
    }
}

return "", false
}

A full Patch by @kataras to support multi languages, look the `localeFiles` new type
and the `GetKey, Reload` and improvement of `locales.Add` and more.

Documentation

Overview

Package i18n is for app Internationalization and Localization.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLangAlreadyExist throwed when language is already exists.
	ErrLangAlreadyExist = errors.New("lang already exists")
)

Functions

func Count

func Count() int

Count returns number of languages that are registered.

func GetDescriptionByIndex

func GetDescriptionByIndex(index int) string

func GetDescriptionByLang

func GetDescriptionByLang(lang string) string

func GetLangByIndex

func GetLangByIndex(index int) string

GetLangByIndex return language by given index.

func IndexLang

func IndexLang(lang string) int

IndexLang returns index of language locale, it returns -1 if locale not exists.

func IsExist

func IsExist(lang string) bool

IsExist returns true if given language locale exists.

func IsExistSimilar

func IsExistSimilar(lang string) (string, bool)

IsExistSimilar returns true if the language, or something similar exists (e.g. en-US maps to en). it returns the found name and whether it was able to match something. - PATCH by @j-lenoch.

func ListLangDescs

func ListLangDescs() []string

func ListLangs

func ListLangs() []string

ListLangs returns list of all locale languages.

func ReloadLangs

func ReloadLangs(langs ...string) error

ReloadLangs reloads locale files.

func SetDefaultLang

func SetDefaultLang(lang string)

SetDefaultLang sets default language which is a indicator that when target language is not found, try find in default language again.

func SetMessage

func SetMessage(lang string, localeFile interface{}, otherLocaleFiles ...interface{}) error

SetMessage sets the message file for localization.

func SetMessageWithDesc

func SetMessageWithDesc(lang, langDesc string, localeFile interface{}, otherLocaleFiles ...interface{}) error

func Tr

func Tr(lang, format string, args ...interface{}) string

Tr translates content to target language.

Types

type Locale

type Locale struct {
	Lang string
}

Locale represents the information of localization.

func (Locale) Index

func (l Locale) Index() int

Index returns lang index of LangStore.

func (Locale) Tr

func (l Locale) Tr(format string, args ...interface{}) string

Tr translates content to target language.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL