1 | import { ITranslationConfig, Key, LangChangedEvent, LanguageIdentifier, Translation, Translations, Values, ValuesCallback } from "./model";
|
2 | /**
|
3 | * Default configuration object.
|
4 | */
|
5 | export declare const defaultTranslateConfig: ITranslationConfig;
|
6 | /**
|
7 | * Registers a translation config.
|
8 | * @param config
|
9 | */
|
10 | export declare function registerTranslateConfig(config: Partial<ITranslationConfig>): ITranslationConfig;
|
11 | /**
|
12 | * Loads translations using either the values from the cache or the provided translations loader.
|
13 | * @param lang
|
14 | * @param config
|
15 | */
|
16 | export declare function loadTranslations(lang: LanguageIdentifier, config?: ITranslationConfig): Promise<Translations>;
|
17 | /**
|
18 | * Dispatches a language changed event.
|
19 | * @param detail
|
20 | */
|
21 | export declare function dispatchLangChanged(detail: LangChangedEvent): void;
|
22 | /**
|
23 | * Updates the configuration object with a new language and translations and then dispatches than the language has changed.
|
24 | * @param config
|
25 | * @param newLang
|
26 | * @param newTranslations
|
27 | */
|
28 | export declare function updateConfig(config: ITranslationConfig, newLang: LanguageIdentifier, newTranslations: Translations): void;
|
29 | /**
|
30 | * Listens for changes in the language.
|
31 | * Returns a method for unsubscribing from the event.
|
32 | * @param callback
|
33 | * @param options
|
34 | */
|
35 | export declare function listenForLangChanged(callback: (e: LangChangedEvent) => void, options?: EventListenerOptions): (() => void);
|
36 | /**
|
37 | * Sets a new current language and dispatches a global language changed event.
|
38 | * @param lang
|
39 | * @param config
|
40 | */
|
41 | export declare function use(lang: LanguageIdentifier, config?: ITranslationConfig): Promise<void>;
|
42 | /**
|
43 | * Interpolates the values into the string.
|
44 | * @param text
|
45 | * @param values
|
46 | */
|
47 | export declare function interpolate(text: string, values: Values | ValuesCallback): string;
|
48 | /**
|
49 | * Returns a translation based on a chain of keys using the dot notation.
|
50 | * @param key
|
51 | * @param config
|
52 | */
|
53 | export declare function getTranslation(key: Key, config?: ITranslationConfig): string;
|
54 | /**
|
55 | * Translates a key and interpolates if values are defined.
|
56 | * Uses the current strings and string cache to fetch the string.
|
57 | * @param key (eg. "common.get_started")
|
58 | * @param values (eg. { count: 42 })
|
59 | * @param config
|
60 | */
|
61 | export declare function get(key: Key, values?: Values | ValuesCallback | null, config?: ITranslationConfig): Translation;
|
62 | /**
|
63 | * Extracts either the value from the function or return the value that was passed in.
|
64 | * @param obj
|
65 | */
|
66 | export declare function extract<T>(obj: T | (() => T)): T;
|