Lion Logo Lion Fundamentals Guides Components Blog Toggle darkmode

Localize: API Table

class: LocalizeManager

Fields

NamePrivacyTypeDefaultDescriptionInherited From
formatDateOptionspublicobject{ /** @type {Map<string, DatePostProcessor>} */ postProcessors: new Map(), }The localize system uses (normalized) Intl for formatting dates. It's possible to customize this output per locale
formatNumberOptionspublicobject{ returnIfNaN: '', /** @type {Map<string, NumberPostProcessor>} */ postProcessors: new Map(), }The localize system uses (normalized) Intl for formatting numbers. It's possible to customize this output per locale
loadingCompletepublic
localepublic
_autoLoadOnLocaleChangeprotectedboolean!!autoLoadOnLocaleChange
_fallbackLocaleprotectedfallbackLocale
_langAttrSetByTranslationToolprotected
_showKeyAsFallbackprotectedshowKeyAsFallback
_supportExternalTranslationToolsprotected

Methods

NamePrivacyDescriptionParametersReturnInherited From
addDatapubliclocale: string, namespace: string, data: object
loadNamespacepublicnamespaceObj: NamespaceObject, { locale = this.locale }, options: @param {string} [options.locale] * Promise<Object|void>
loadNamespacespublicnamespaces: NamespaceObject[], { locale }, options: @param {string} [options.locale] * Promise<Object>
msgpublickeys: string | string[], vars: Object<string,?>, opts: @param {string} [opts.locale] * string
resetpublic
setDatePostProcessorForLocalepublic{ locale, postProcessor }, options: {locale:string, postProcessor:DatePostProcessor}
setNumberPostProcessorForLocalepublic{ locale, postProcessor }, options: {locale:string, postProcessor:NumberPostProcessor}
setupNamespaceLoaderpublicpattern: RegExp|string, loader: function
teardownpublic
_cacheNamespaceLoaderPromiseprotectedlocale: string, namespace: string, promise: Promise<Object|void>
_getCachedNamespaceLoaderPromiseprotectedlocale: string, namespace: string
_getLangFromLocaleprotectedlocale: stringstring
_getMessageForKeyprotectedkey: string | undefined, locale: stringstring
_getMessageForKeysprotectedkeys: string | string[], locale: stringstring | undefined
_getNamespaceLoaderprotectednamespaceObj: NamespaceObject, isDynamicImport: boolean, namespace: string
_getNamespaceLoaderPromiseprotectedloader: function, locale: string, namespace: string, fallbackLocale: stringPromise<any>
_isNamespaceInCacheprotectedlocale: string, namespace: string
_loadAllMissingprotectednewLocale: string, oldLocale: string
_loadNamespaceDataprotectedlocale: string, namespaceObj: NamespaceObject, isDynamicImport: boolean, namespace: stringPromise<Object|void>
_lookupNamespaceLoaderprotectednamespace: stringfunction|null
_onLocaleChangedprotectednewLocale: string, oldLocale: stringundefined
_setHtmlLangAttributeprotectedlocale: string
_setupHtmlLangAttributeObserverprotected
_setupTranslationToolSupportprotectedThis value allows for support for Google Translate (or other 3rd parties taking control of the html[lang] attribute). Have the following scenario in mind: 1. locale is initialized by developer via html[data-localize-lang="en-US"] and html[lang="en-US"]. When localize is loaded (note that this also can be after step 2 below), it will sync its initial state from html[data-localize-lang] 2. Google Translate kicks in for the French language. It will set html[lang="fr"]. This new language is not one known by us, so we most likely don't have translations for this file. Therefore, we do NOT sync this value to LocalizeManager. The manager should still ask for known resources (in this case for locale 'en-US') 3. locale is changed (think of a language dropdown) It's a bit of a weird case, because we would not expect an end user to do this. If he/she does, make sure that we do not go against Google Translate, so we maintain accessibility (by not altering html[lang]). We detect this by reading #localeSetByTranslationTool: when its value is null, we consider Google translate 'not active'. When Google Translate is turned off by the user (html[lang=auto]), `localize.locale` will be synced to html[lang] again Keep in mind that all of the above also works with other tools than Google Translate, but this is the most widely used tool and therefore used as an example.
_teardownHtmlLangAttributeObserverprotected

Events

NameTypeDescriptionInherited From
__localeChangingCustomEvent
localeChangedCustomEvent