/** @packageDocumentation * @module Localization */ import { Callback, TranslationOptions } from "i18next"; import { I18NextXhrBackend } from "i18next-xhr-backend"; /** @public */ export interface I18NOptions { urlTemplate?: I18NextXhrBackend.LoadPathOption; } /** Supplies Internationalization services. * @note Internally, this class uses the [i18next](https://www.i18next.com/) package. * @public */ export declare class I18N { private _i18next; private readonly _namespaceRegistry; /** Constructor for I18N. * @param nameSpaces either the name of the default namespace, an array of namespaces, or undefined. If an array, the first entry is the default. * @param options object with I18NOptions (optional) * @param renderFunction optional i18next.Callback function */ constructor(nameSpaces?: string | string[], options?: I18NOptions, renderFunction?: Callback); /** Replace all instances of `%{key}` within a string with the translations of those keys. * For example: * ``` ts * "MyKeys": { * "Key1": "First value", * "Key2": "Second value" * } * ``` * * ``` ts * i18.translateKeys("string with %{MyKeys.Key1} followed by %{MyKeys.Key2}!"") // returns "string with First Value followed by Second Value!" * ``` * @param line The input line, potentially containing %{keys}. * @returns The line with all %{keys} translated * @public */ translateKeys(line: string): string; /** Return the translated value of a key. * @param key - the key that matches a property in the JSON localization file. * @note The key includes the namespace, which identifies the particular localization file that contains the property, * followed by a colon, followed by the property in the JSON file. * For example: * ``` ts * const dataString: string = IModelApp.i18n.translate("iModelJs:BackgroundMap.BingDataAttribution"); * ``` * assigns to dataString the string with property BackgroundMap.BingDataAttribution from the iModelJs.json localization file. * @returns The string corresponding to the first key that resolves. * @throws Error if no keys resolve to a string. * @public */ translate(key: string | string[], options?: TranslationOptions): string; /** Similar to 'translate()' but the namespace is a separate param and the key does not include the namespace. * @param namespace - the namespace that identifies the particular localization file that contains the property. * @param key - the key that matches a property in the JSON localization file. * @returns The string corresponding to the first key that resolves. * @throws Error if no keys resolve to a string. * @internal */ translateWithNamespace(namespace: string, key: string | string[], options?: TranslationOptions): string; /** Gets the English translation. * @param namespace - the namespace that identifies the particular localization file that contains the property. * @param key - the key that matches a property in the JSON localization file. * @returns The string corresponding to the first key that resolves. * @throws Error if no keys resolve to a string. * @internal */ getEnglishTranslation(namespace: string, key: string | string[], options?: TranslationOptions): string; /** @internal */ loadNamespace(name: string, i18nCallback: any): void; /** Get an already registered Namespace. * @param name - the name of the namespace * @public */ getNamespace(name: string): I18NNamespace | undefined; /** @internal */ languageList(): string[]; /** Register a new Namespace and return it. If the namespace is already registered, it will be returned. * @param name - the name of the namespace, which is the base name of the JSON file that contains the localization properties. * @note - The registerNamespace method starts fetching the appropriate version of the JSON localization file from the server, * based on the current locale. To make sure that fetch is complete before performing translations from this namespace, await * fulfillment of the readPromise Promise property of the returned I18NNamespace. * @see [Localization in iModel.js]($docs/learning/frontend/Localization.md) * @public */ registerNamespace(name: string): I18NNamespace; /** Waits for the Promises for all the registered namespaces to be fulfilled. * @internal */ waitForAllRead(): Promise; /** @internal */ unregisterNamespace(name: string): void; } /** The class that represents a registered I18N Namespace * @note The readFinished member is a Promise that is resolved when the JSON file for the namespace has been retrieved from the server, or rejected if an error occurs. * @public */ export declare class I18NNamespace { name: string; readFinished: Promise; constructor(name: string, readFinished: Promise); } //# sourceMappingURL=Localization.d.ts.map