import { InjectionToken } from '@angular/core'; import { PromiseState } from 'mobx-utils'; import { LfRouter } from './router.service'; import { LfStorage } from './storage.service'; import * as i0 from "@angular/core"; /** * Options used for fetching a translation. */ export interface GetTranslationOptions { /** * Whether functions in translations should be resolved (by calling them with * a storage instance with the path relative to the translation's path). * Defaults to `true`. */ callFunctionWithContext?: boolean; /** * Whether to cache the translation as a state property of the path in * question. `callFunctionWithContext` is assumed `true` if this setting is * set. This setting makes it possible to use asynchronous functions as * translations. The first time the translation is fetched, a state property * is created in the storage: as such, a MobX `action` is performed, meaning * that fetching translations with this setting set to `true` should not be * done from within a MobX computed value. */ useState?: boolean; } /** * Map of i18n languages to their map of paths. */ export interface I18nLanguages { [lang: string]: I18nPaths; } /** * Map of paths to their map of translations. */ export interface I18nPaths { [path: string]: Record; } /** * Injection token used to specify the initial i18n object. */ export declare const LF_APP_I18N: InjectionToken; /** * Injection token used to specify the name of the URL query parameter with * which to manage the i18n service's current language. If none is provided, * then the i18n service won't control the current language via query parameter. */ export declare const LF_I18N_LANGUAGE_QUERY_PARAM: InjectionToken; /** * Separator used in between translation record properties to form a unique key. * E.g. if the translation record has something like: `{a: {b: 'string'}}` then * we can use `'a.b'` to access the respective translation. */ export declare const I18N_KEY_SEPARATOR = "."; /** * Translations can be specified by "path"; however, the `'*'` pseudo-path works * as a "catch-all" when no path should be associated or if the translation * should be available to all paths. */ export declare const I18N_CATCH_ALL_PATH = "*"; /** * Prefix used in state properties to hold i18n strings. */ export declare const I18N_STATE_PROPERTY_PREFIX = "i18n"; /** * Service used to deal with the internationalisation of applications. * Translations may be added dynamically and be associated with paths if * desired. */ export declare class LfI18n { private lfStorage; private lfRouter; private lfLanguageQueryParam; private _defaultLanguage; /** * Used only when `lfLanguageQueryParam` is `null`. */ private _currentLanguage?; private translations; /** * Map generic paths found in translations to a RegExp that matches them * against given paths. E.g. the generic path `/a/?` should match against * `/a/b` or `a/c`. */ private genericPaths; constructor(lfStorage: LfStorage, translations: I18nLanguages | null, lfRouter: LfRouter | null, lfLanguageQueryParam: string | null); /** * Static method used to merge translation objects. Merges all translations * into the first one. * @param translations Translations to merge into the first object. A minimum * of one object is required. * @returns Merged translations. */ static mergeTranslations(...translations: Array>): Record; private static _mergeTranslations; /** * Available languages. */ get languages(): string[]; /** * Default language from which to fetch translations when one wasn't found in * the current language. */ get defaultLanguage(): string; set defaultLanguage(lang: string); /** * Language being currently used for translations. */ get currentLanguage(): string; set currentLanguage(lang: string); /** * Sets the current language, possibly asynchronously when using a query * parameter to keep track of the current language. * @param lang Language to set as current language. `undefined` means that the * i18n service will use the default language. * @returns Promise that resolves to `true`/`false` when the navigation * succeeds/fails or is rejected when an error happens (when using a query * parameter to keep track of the current language, otherwise this method * returns `undefined`). */ setCurrentLanguage(lang?: string): void | Promise; /** * Gets a given translation from the "catch-all" path (tries the current * language, if no translation was found for the current language, tries the * default language). * @param key Key of the translation to fetch. * @param options Options for fetching the translation. * @returns Translation for provided key (typically a string, but can * theoretically be anything). */ get(key: string, { callFunctionWithContext, useState, }?: GetTranslationOptions): any; /** * Gets a given translation for a given path (tries the provided path with the * current language, if no translation was found then tries the "catch-all" * path for the current language; if a translation still hasn't been found the * process is repeated for the default language). * @param path Path from which to fetch translation. * @param key Key of the translation to fetch. * @param options Options for fetching the translation. * @returns Translation for provided key (typically a string or a function, * but can theoretically be anything). */ getFromPath(path: string, key: string, { callFunctionWithContext, useState, }?: GetTranslationOptions): any; /** * Status of a translation when it is an asynchronous context function and * `useState` was used to fetch it, or `'fulfilled'` in all other cases. * @param path Path from which to fetch the translation status. * @param key Key of the translation from which to fetch the status. * @returns The status of the translation when possible, `'fulfilled'` in all * other cases. */ translationStatus(path: string, key: string): PromiseState; /** * Adds translations to the application. Translations may be added for * multiple languages at once or for a single language. * @param translations Translations to add to the application. If `lang` is * defined then its translations should be an object mapping paths to * translation keys: * ```typescript * { * '*': { * randomKey: 'Some translation' * }, * '/some/path': { * anotherKey: 'Another translation' * } * } * ``` * Otherwise (if `lang` is not defined), the object should map languages to * objects similar to the example: * ```typescript * { * 'en-US': { * '*': { * randomKey: 'Some translation' * }, * '/some/path': { * anotherKey: 'Another translation' * } * }, * 'pt-PT': { * '*': { * randomKey: 'Alguma tradução' * } * } * } * ``` * @param lang Language of the translation object if the object only contains * translations for a single language. */ addTranslations(translations: Record, lang?: string): void; private addGenericPaths; private getFromState; private getFromTranslations; private statePropName; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; }