Documentation ¶
Overview ¶
Package i18n defines internationalization and localization.
Index ¶
- Constants
- func LocalesFS() fs.FS
- func TranslatorLanguage(l gotext.Translator) string
- type LocaleMap
- func (l *LocaleMap) Canonicalize(id string, matcher language.Matcher) (result string, retErr error)
- func (l *LocaleMap) Lookup(ids ...string) gotext.Translator
- func (l *LocaleMap) LookupDynamic(realmID uint, realmDefaultLocale string, ids ...string) gotext.Translator
- func (l *LocaleMap) SetDynamicTranslations(incoming []*database.DynamicTranslation)
- type Option
- type Source
Constants ¶
const ( DefaultSource = iota RedirectSource )
Variables ¶
This section is empty.
Functions ¶
func TranslatorLanguage ¶ added in v0.26.0
func TranslatorLanguage(l gotext.Translator) string
Types ¶
type LocaleMap ¶
type LocaleMap struct {
// contains filtered or unexported fields
}
LocaleMap is a map of locale names to their data structure.
func Load ¶
Load parses and loads the localization files from disk. It builds the locale matcher based on the currently available data (organized by folder).
Due to the heavy I/O, callers should cache the resulting value and only call Load when data needs to be refreshed.
func (*LocaleMap) Canonicalize ¶
Canonicalize converts the given ID to the expected name.
func (*LocaleMap) Lookup ¶
func (l *LocaleMap) Lookup(ids ...string) gotext.Translator
Lookup finds the best locale for the given ids. If none exists, the default locale is used.
If reloading is enabled, the locales are reloaded before lookup. If reloading fails, it panics. For this reason, you should not enable reloading in production.
func (*LocaleMap) LookupDynamic ¶ added in v0.30.0
func (l *LocaleMap) LookupDynamic(realmID uint, realmDefaultLocale string, ids ...string) gotext.Translator
LookupDynamic finds the best locale for the given ids.
func (*LocaleMap) SetDynamicTranslations ¶ added in v0.30.0
func (l *LocaleMap) SetDynamicTranslations(incoming []*database.DynamicTranslation)
SetDynamicTranslations creates realm specific locals with translations based on what's in the database.
type Option ¶
Option is an option to creating a locale map.
func WithDefaultSource ¶ added in v1.1.0
func WithDefaultSource() Option
WithDefaultSource loads the default translations for the main Web UI (server).
func WithRedirectSource ¶ added in v1.1.0
func WithRedirectSource() Option
WithRedirectSource loads the translations for the redirect server.
func WithReloading ¶
WithReloading enables hot reloading for the map.