i18n

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTranslation

func AddTranslation(lang *language.Language, translations ...translation.Translation)

AddTranslation adds translations for a language.

It is useful if your translations are in a format not supported by LoadTranslationFile.

func LanguageTags

func LanguageTags() []string

LanguageTags returns the tags of all languages that have been added.

func LanguageTranslationIDs

func LanguageTranslationIDs(languageTag string) []string

LanguageTranslationIDs returns the ids of all translations that have been added for a given language.

func LoadTranslationFile

func LoadTranslationFile(filename string) error

LoadTranslationFile loads the translations from filename into memory.

The language that the translations are associated with is parsed from the filename (e.g. en-US.json).

Generally you should load translation files once during your program's initialization.

func MustLoadTranslationFile

func MustLoadTranslationFile(filename string)

MustLoadTranslationFile is similar to LoadTranslationFile except it panics if an error happens.

func ParseTranslationFileBytes

func ParseTranslationFileBytes(filename string, buf []byte) error

ParseTranslationFileBytes is similar to LoadTranslationFile except it parses the bytes in buf.

It is useful for parsing translation files embedded with go-bindata.

Types

type TranslateFunc

type TranslateFunc func(translationID string, args ...interface{}) string

TranslateFunc returns the translation of the string identified by translationID.

If there is no translation for translationID, then the translationID itself is returned. This makes it easy to identify missing translations in your app.

If translationID is a non-plural form, then the first variadic argument may be a map[string]interface{} or struct that contains template data.

If translationID is a plural form, the function accepts two parameter signatures 1. T(count int, data struct{}) The first variadic argument must be an integer type (int, int8, int16, int32, int64) or a float formatted as a string (e.g. "123.45"). The second variadic argument may be a map[string]interface{} or struct{} that contains template data. 2. T(data struct{}) data must be a struct{} or map[string]interface{} that contains a Count field and the template data, Count field must be an integer type (int, int8, int16, int32, int64) or a float formatted as a string (e.g. "123.45").

func IdentityTfunc

func IdentityTfunc() TranslateFunc

IdentityTfunc returns a TranslateFunc that always returns the translationID passed to it.

It is a useful placeholder when parsing a text/template or html/template before the actual Tfunc is available.

func MustTfunc

func MustTfunc(languageSource string, languageSources ...string) TranslateFunc

MustTfunc is similar to Tfunc except it panics if an error happens.

func MustTfuncAndLanguage

func MustTfuncAndLanguage(languageSource string, languageSources ...string) (TranslateFunc, *language.Language)

MustTfuncAndLanguage is similar to TfuncAndLanguage except it panics if an error happens.

func Tfunc

func Tfunc(languageSource string, languageSources ...string) (TranslateFunc, error)

Tfunc returns a TranslateFunc that will be bound to the first language which has a non-zero number of translations.

It can parse languages from Accept-Language headers (RFC 2616).

func TfuncAndLanguage

func TfuncAndLanguage(languageSource string, languageSources ...string) (TranslateFunc, *language.Language, error)

TfuncAndLanguage is similar to Tfunc except it also returns the language which TranslateFunc is bound to.

Directories

Path Synopsis
Package language defines languages that implement CLDR pluralization.
Package language defines languages that implement CLDR pluralization.

Jump to

Keyboard shortcuts

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