i18n

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Langs is the list of all loaded languages in the application
	Langs []string
)

Functions

func BootStrap

func BootStrap()

BootStrap initializes available languages

func GetAllCustomTranslations

func GetAllCustomTranslations() map[string]map[string]map[string]string

GetAllCustomTranslations returns all custom translations by lang and by modules

func GetAllLanguageList

func GetAllLanguageList() []string

GetAllLanguageList returns a slice containing all known language codes

func LoadPOFile

func LoadPOFile(fileName string)

LoadPOFile load the file with the given filename into the Registry. This function is meant to be called several times to load all translations across all languages and modules. It panics in case of errors in the PO file.

func OverrideLocale

func OverrideLocale(loc *Locale) error

OverrideLocale overrides the locale with the same ISO code as loc with loc. If such a locale does not exist, an error is returned and the locale is not registered.

func RegisterLocale

func RegisterLocale(loc *Locale) error

RegisterLocale registers a new locale

func TranslateCode

func TranslateCode(lang, context, src string) string

TranslateCode returns the translation for the given src in the given lang, in the given context. If no translation is found or if the translation is the empty string src is returned.

func TranslateCustom

func TranslateCustom(lang, id, moduleName string) string

TranslateCustom returns the custom translation for the given id

func TranslateFieldDescription

func TranslateFieldDescription(lang, model, field, defaultValue string) string

TranslateFieldDescription returns the translation for the given model field name in the given lang, using the default translation Registry. If no translation is found or if the translation is the empty string defaultValue is returned.

func TranslateFieldHelp

func TranslateFieldHelp(lang, model, field, defaultValue string) string

TranslateFieldHelp returns the translation for the given model field help in the given lang, using the default translation Registry. If no translation is found or if the translation is the empty string defaultValue is returned.

func TranslateFieldSelection

func TranslateFieldSelection(lang, model, field string, selection types.Selection) types.Selection

TranslateFieldSelection returns the translated version of the given selection in the given lang, using the default translation Registry. When no translation is found for an item, the original string is used.

func TranslateResourceItem

func TranslateResourceItem(lang, resourceID, src string) string

TranslateResourceItem returns the translation for the given src of the given resource in the given lang using the default translation Registry. If no translation is found or if the translation is the empty string src is returned.

Types

type LangDirection

type LangDirection string

A LangDirection defines the direction of a language either left-to-right or right-to-left

const (
	// LangDirectionLTR defines a language written from left to right
	LangDirectionLTR LangDirection = "ltr"
	// LangDirectionRTL defines a language written from right to left
	LangDirectionRTL LangDirection = "rtl"
)

type Locale

type Locale struct {
	Name         string        `json:"name"`
	Code         string        `json:"code"`
	ISOCode      string        `json:"iso_code"`
	WeekStart    time.Weekday  `json:"week_start"`
	DateFormat   string        `json:"date_format"`
	Direction    LangDirection `json:"lang_direction"`
	ThousandsSep string        `json:"thousands_sep"`
	TimeFormat   string        `json:"time_format"`
	DecimalPoint string        `json:"decimal_point"`
	Grouping     string        `json:"grouping"`
}

Locale defines the parameters of a language locale

func GetLocale

func GetLocale(lang string) *Locale

GetLocale returns a Locale struct describing a language's rules at first call, the data file containing all languages parameters is read if the language is not loaded, it returns a Locale similar to English (en_US)

func (*Locale) Check

func (l *Locale) Check() error

Check returns an error if this locale is not valid

type Translation

type Translation struct {
	// contains filtered or unexported fields
}

A Translation holds all the translations for a given language

type TranslationsCollection

type TranslationsCollection struct {
	// contains filtered or unexported fields
}

A TranslationsCollection holds all the translations of the application

var Registry *TranslationsCollection

Registry holds all the translation of the application

func NewTranslationsCollection

func NewTranslationsCollection() *TranslationsCollection

NewTranslationsCollection returns a pointer to a new TranslationsCollection ready for use

func (*TranslationsCollection) LoadPOFile

func (tc *TranslationsCollection) LoadPOFile(fileName string)

LoadPOFile load the file with the given filename into the TranslationsCollection. This function can be called several times to iteratively load translations. It panics in case of errors in the PO file.

func (*TranslationsCollection) TranslateCode

func (tc *TranslationsCollection) TranslateCode(lang, context, src string) string

TranslateCode returns the translation for the given src in the given lang, in the given context. If no translation is found or if the translation is the empty string src is returned.

func (*TranslationsCollection) TranslateCustom

func (tc *TranslationsCollection) TranslateCustom(lang, id, moduleName string) string

TranslateCustom returns the translation for the given src of the given custom po string in the given lang. If no translation is found or if the translation is the empty string src is returned.

func (*TranslationsCollection) TranslateFieldDescription

func (tc *TranslationsCollection) TranslateFieldDescription(lang, model, field, defaultValue string) string

TranslateFieldDescription returns the translation for the given model field name in the given lang. If no translation is found or if the translation is the empty string defaultValue is returned.

func (*TranslationsCollection) TranslateFieldHelp

func (tc *TranslationsCollection) TranslateFieldHelp(lang, model, field, defaultValue string) string

TranslateFieldHelp returns the translation for the given model field help in the given lang. If no translation is found or if the translation is the empty string defaultValue is returned.

func (*TranslationsCollection) TranslateFieldSelection

func (tc *TranslationsCollection) TranslateFieldSelection(lang, model, field string, selection types.Selection) types.Selection

TranslateFieldSelection returns the translated version of the given selection in the given lang. When no translation is found for an item, the original string is used.

func (*TranslationsCollection) TranslateResourceItem

func (tc *TranslationsCollection) TranslateResourceItem(lang, resourceID, src string) string

TranslateResourceItem returns the translation for the given src of the given resource in the given lang. If no translation is found or if the translation is the empty string src is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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