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 Currency
- type LangDirection
- type Locale
- func (l *Locale) Check() error
- func (l *Locale) FormatDate(date dates.Date) string
- func (l *Locale) FormatDateTime(datetime dates.DateTime) string
- func (l *Locale) FormatFloat(number float64, digits nbutils.Digits) string
- func (l *Locale) FormatMonetary(value float64, curr Currency) string
- func (l *Locale) FormatTime(datetime dates.DateTime) string
- type NumberGrouping
- 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 Currency ¶
type Currency interface { // Symbol returns the currency symbol when printing amounts Symbol() string // Position returns 'before' or 'after' depending on where the symbol must be printed Position() string // DecimalPlaces for this currency DecimalPlaces() int // Round returns the given value rounded according to this currency Round(float64) float64 }
A Currency with symbol, position and decimals
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"` DateFormatGo string `json:"date_format_go"` Direction LangDirection `json:"lang_direction"` ThousandsSep string `json:"thousands_sep"` TimeFormat string `json:"time_format"` TimeFormatGo string `json:"time_format_go"` DecimalPoint string `json:"decimal_point"` Grouping NumberGrouping `json:"grouping"` }
Locale defines the parameters of a language locale
func GetLocale ¶
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) FormatDate ¶
FormatDate returns the given date formatted according to this Locale
func (*Locale) FormatDateTime ¶
FormatDateTime returns the given datetime formatted according to this Locale
func (*Locale) FormatFloat ¶
FormatFloat formats the given number according to this Locale, with the given digits
func (*Locale) FormatMonetary ¶
FormatMonetary formats the given value according to this Locale and given currency
type NumberGrouping ¶
type NumberGrouping []int
NumberGrouping represents grouping values of a number as follows:
- it splits a number into groups of N, N being a value in the slice
- the values define groups from right to left
- all values should be positive
- 0 at the end means repetition of previous int
- if the last value is not a 0, the grouping will end e.g. : 3 -> 123456,789 3,0 -> 123,456,789 3,2 -> 1234,56,789 3,2,0 -> 12,34,56,789
func (NumberGrouping) MarshalJSON ¶
func (nb NumberGrouping) MarshalJSON() ([]byte, error)
MarshalJSON function for the NumberGrouping type that should marshal as string.
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.