/** * `LocalizeManager` manages your translations (includes loading) */ export class LocalizeManager extends EventTarget { constructor({ allowOverridesForExistingNamespaces, autoLoadOnLocaleChange, showKeyAsFallback, fallbackLocale, }?: { allowOverridesForExistingNamespaces?: boolean | undefined; autoLoadOnLocaleChange?: boolean | undefined; showKeyAsFallback?: boolean | undefined; fallbackLocale?: string | undefined; }); /** * The localize system uses (normalized) Intl for formatting numbers. * It's possible to customize this output per locale */ formatNumberOptions: { returnIfNaN: string; /** @type {Map} */ postProcessors: Map; }; /** * The localize system uses (normalized) Intl for formatting dates. * It's possible to customize this output per locale */ formatDateOptions: { /** @type {Map} */ postProcessors: Map; }; /** * @type {Object>} * @private */ private __storage; /** * @type {Map} * @private */ private __namespacePatternsMap; /** * @type {Object} * @private */ private __namespaceLoadersCache; /** * @type {Object>>} * @private */ private __namespaceLoaderPromisesCache; /** * @param {string} newLocale */ set locale(arg: string); /** * @returns {string} */ get locale(): string; /** * @readonly * @returns {Promise} */ readonly get loadingComplete(): Promise; /** @private */ private __allowOverridesForExistingNamespaces; /** @protected */ protected _autoLoadOnLocaleChange: boolean; /** @protected */ protected _showKeyAsFallback: boolean; /** @protected */ protected _fallbackLocale: string; /** * @param {string} locale * @param {string} namespace * @param {object} data * @throws {Error} Namespace can be added only once, for a given locale unless allowOverridesForExistingNamespaces * is set to `true` */ addData(locale: string, namespace: string, data: object): void; /** * @param {RegExp|string} pattern * @param {function} loader */ setupNamespaceLoader(pattern: RegExp | string, loader: Function): void; /** * @param {NamespaceObject[]} namespaces * @param {Object} options * @param {string} [options.locale] * @returns {Promise} */ loadNamespaces(namespaces: NamespaceObject[], { locale }?: { locale?: string | undefined; }): Promise; /** * @param {NamespaceObject} namespaceObj * @param {Object} options * @param {string} [options.locale] * @returns {Promise} */ loadNamespace(namespaceObj: NamespaceObject, { locale }?: { locale?: string | undefined; }): Promise; /** * @param {string | string[]} keys * @param {Object} [vars] * @param {Object} [opts] * @param {string} [opts.locale] * @returns {string} */ msg(keys: string | string[], vars?: { [x: string]: any; } | undefined, opts?: { locale?: string | undefined; } | undefined): string; teardown(): void; reset(): void; /** * @param {{locale:string, postProcessor:DatePostProcessor}} options */ setDatePostProcessorForLocale({ locale, postProcessor }: { locale: string; postProcessor: DatePostProcessor; }): void; /** * @param {{locale:string, postProcessor:NumberPostProcessor}} options */ setNumberPostProcessorForLocale({ locale, postProcessor }: { locale: string; postProcessor: NumberPostProcessor; }): void; /** * This 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. * @protected */ protected _setupTranslationToolSupport(): void; /** * @param {string} locale * @protected */ protected _setHtmlLangAttribute(locale: string): void; /** @protected */ protected _setupHtmlLangAttributeObserver(): void; _htmlLangAttributeObserver: MutationObserver | undefined; /** @protected */ protected _teardownHtmlLangAttributeObserver(): void; /** * @param {string} locale * @param {string} namespace * @protected */ protected _isNamespaceInCache(locale: string, namespace: string): boolean; /** * @param {string} locale * @param {string} namespace * @protected */ protected _getCachedNamespaceLoaderPromise(locale: string, namespace: string): Promise | null; /** * @param {string} locale * @param {NamespaceObject} namespaceObj * @param {boolean} isDynamicImport * @param {string} namespace * @returns {Promise} * @protected */ protected _loadNamespaceData(locale: string, namespaceObj: NamespaceObject, isDynamicImport: boolean, namespace: string): Promise; /** * @param {NamespaceObject} namespaceObj * @param {boolean} isDynamicImport * @param {string} namespace * @throws {Error} Namespace shall setup properly. Check loader! * @protected */ protected _getNamespaceLoader(namespaceObj: NamespaceObject, isDynamicImport: boolean, namespace: string): Function; /** * @param {function} loader * @param {string} locale * @param {string} namespace * @param {string} [fallbackLocale] * @returns {Promise} * @throws {Error} Data for namespace and (locale or fallback locale) could not be loaded. * @protected */ protected _getNamespaceLoaderPromise(loader: Function, locale: string, namespace: string, fallbackLocale?: string | undefined): Promise; /** * @param {string} locale * @param {string} namespace * @param {Promise} promise * @protected */ protected _cacheNamespaceLoaderPromise(locale: string, namespace: string, promise: Promise): void; /** * @param {string} namespace * @returns {function|null} * @protected */ protected _lookupNamespaceLoader(namespace: string): Function | null; /** * @param {string} locale * @returns {string} * @protected */ protected _getLangFromLocale(locale: string): string; /** * @param {string} newLocale * @param {string} oldLocale * @returns {undefined} * @protected */ protected _onLocaleChanged(newLocale: string, oldLocale: string): undefined; /** * @param {string} newLocale * @param {string} oldLocale * @protected */ protected _loadAllMissing(newLocale: string, oldLocale: string): void; /** * @param {string | string[]} keys * @param {string} locale * @returns {string | undefined} * @protected */ protected _getMessageForKeys(keys: string | string[], locale: string): string | undefined; /** * @param {string | undefined} key * @param {string} locale * @returns {string} * @throws {Error} `key`is missing namespace. The format for `key` is "namespace:name" * @protected * */ protected _getMessageForKey(key: string | undefined, locale: string): string; /** * @deprecated * @protected */ protected set _supportExternalTranslationTools(arg: boolean); /** * @deprecated * @protected */ protected get _supportExternalTranslationTools(): boolean; /** * @deprecated * @protected */ protected set _langAttrSetByTranslationTool(arg: string); /** * @deprecated * @protected */ protected get _langAttrSetByTranslationTool(): string; #private; } export type NumberPostProcessor = import('../types/LocalizeMixinTypes.js').NumberPostProcessor; export type DatePostProcessor = import('../types/LocalizeMixinTypes.js').DatePostProcessor; export type NamespaceObject = import('../types/LocalizeMixinTypes.js').NamespaceObject; //# sourceMappingURL=LocalizeManager.d.ts.map