Lion Logo Lion Fundamentals Guides Components Blog Toggle darkmode

Localize: API Table

class: LocalizeManager

Fields

NamePrivacyTypeDefaultDescriptionInherited From
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
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
localepublic
loadingCompletepublic
_supportExternalTranslationToolsprotected
_langAttrSetByTranslationToolprotected
_autoLoadOnLocaleChangeprotectedboolean!!autoLoadOnLocaleChange
_showKeyAsFallbackprotectedshowKeyAsFallback
_fallbackLocaleprotectedfallbackLocale

Methods

NamePrivacyDescriptionParametersReturnInherited From
addDatapubliclocale: string, namespace: string, data: object
setupNamespaceLoaderpublicpattern: RegExp|string, loader: function
loadNamespacespublicnamespaces: NamespaceObject[], { locale }, options: @param {string} [options.locale] * Promise<Object>
loadNamespacepublicnamespaceObj: NamespaceObject, { locale = this.locale }, options: @param {string} [options.locale] * Promise<Object|void>
msgpublickeys: string | string[], vars: Object<string,?>, opts: @param {string} [opts.locale] * string
teardownpublic
resetpublic
setDatePostProcessorForLocalepublic{ locale, postProcessor }, options: {locale:string, postProcessor:DatePostProcessor}
setNumberPostProcessorForLocalepublic{ locale, postProcessor }, options: {locale:string, postProcessor:NumberPostProcessor}
_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.
_setHtmlLangAttributeprotectedlocale: string
_setupHtmlLangAttributeObserverprotected
_teardownHtmlLangAttributeObserverprotected
_isNamespaceInCacheprotectedlocale: string, namespace: string
_getCachedNamespaceLoaderPromiseprotectedlocale: string, namespace: string
_loadNamespaceDataprotectedlocale: string, namespaceObj: NamespaceObject, isDynamicImport: boolean, namespace: stringPromise<Object|void>
_getNamespaceLoaderprotectednamespaceObj: NamespaceObject, isDynamicImport: boolean, namespace: string
_getNamespaceLoaderPromiseprotectedloader: function, locale: string, namespace: string, fallbackLocale: stringPromise<any>
_cacheNamespaceLoaderPromiseprotectedlocale: string, namespace: string, promise: Promise<Object|void>
_lookupNamespaceLoaderprotectednamespace: stringfunction|null
_getLangFromLocaleprotectedlocale: stringstring
_onLocaleChangedprotectednewLocale: string, oldLocale: stringundefined
_loadAllMissingprotectednewLocale: string, oldLocale: string
_getMessageForKeysprotectedkeys: string | string[], locale: stringstring | undefined
_getMessageForKeyprotectedkey: string | undefined, locale: stringstring

Events

NameTypeDescriptionInherited From
__localeChangingCustomEvent
localeChangedCustomEvent