Documentation ¶
Index ¶
- Variables
- func BootStrap()
- func GetAllCustomTranslations() map[string]map[string]map[string]string
- func GetAllLanguageList() []string
- func LoadPOFile(fileName string)
- func OverrideLocale(loc *Locale) error
- func RegisterLocale(loc *Locale) error
- func TranslateCode(lang, context, src string) string
- func TranslateCustom(lang, id, moduleName string) string
- func TranslateFieldDescription(lang, model, field, defaultValue string) string
- func TranslateFieldHelp(lang, model, field, defaultValue string) string
- func TranslateFieldSelection(lang, model, field string, selection types.Selection) types.Selection
- func TranslateResourceItem(lang, resourceID, src string) string
- type LangDirection
- type Locale
- type Translation
- type TranslationsCollection
- func (tc *TranslationsCollection) LoadPOFile(fileName string)
- func (tc *TranslationsCollection) TranslateCode(lang, context, src string) string
- func (tc *TranslationsCollection) TranslateCustom(lang, id, moduleName string) string
- func (tc *TranslationsCollection) TranslateFieldDescription(lang, model, field, defaultValue string) string
- func (tc *TranslationsCollection) TranslateFieldHelp(lang, model, field, defaultValue string) string
- func (tc *TranslationsCollection) TranslateFieldSelection(lang, model, field string, selection types.Selection) types.Selection
- func (tc *TranslationsCollection) TranslateResourceItem(lang, resourceID, src string) string
Constants ¶
This section is empty.
Variables ¶
var ( // Langs is the list of all loaded languages in the application Langs []string )
Functions ¶
func GetAllCustomTranslations ¶
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 ¶
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 TranslateCode ¶
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 ¶
TranslateCustom returns the custom translation for the given id
func TranslateFieldDescription ¶
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 ¶
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 ¶
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 ¶
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
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.