UNPKG

6.9 kBTypeScriptView Raw
1import { EventEmitter, InjectionToken } from "@angular/core";
2import { Observable } from "rxjs";
3import { MissingTranslationHandler } from "./missing-translation-handler";
4import { TranslateCompiler } from "./translate.compiler";
5import { TranslateLoader } from "./translate.loader";
6import { TranslateParser } from "./translate.parser";
7import { TranslateStore } from "./translate.store";
8export declare const USE_STORE: InjectionToken<string>;
9export declare const USE_DEFAULT_LANG: InjectionToken<string>;
10export declare const DEFAULT_LANGUAGE: InjectionToken<string>;
11export declare const USE_EXTEND: InjectionToken<string>;
12export interface TranslationChangeEvent {
13 translations: any;
14 lang: string;
15}
16export interface LangChangeEvent {
17 lang: string;
18 translations: any;
19}
20export interface DefaultLangChangeEvent {
21 lang: string;
22 translations: any;
23}
24export declare class TranslateService {
25 store: TranslateStore;
26 currentLoader: TranslateLoader;
27 compiler: TranslateCompiler;
28 parser: TranslateParser;
29 missingTranslationHandler: MissingTranslationHandler;
30 private useDefaultLang;
31 private isolate;
32 private extend;
33 private loadingTranslations;
34 private pending;
35 private _onTranslationChange;
36 private _onLangChange;
37 private _onDefaultLangChange;
38 private _defaultLang;
39 private _currentLang;
40 private _langs;
41 private _translations;
42 private _translationRequests;
43 /**
44 * An EventEmitter to listen to translation change events
45 * onTranslationChange.subscribe((params: TranslationChangeEvent) => {
46 * // do something
47 * });
48 */
49 get onTranslationChange(): EventEmitter<TranslationChangeEvent>;
50 /**
51 * An EventEmitter to listen to lang change events
52 * onLangChange.subscribe((params: LangChangeEvent) => {
53 * // do something
54 * });
55 */
56 get onLangChange(): EventEmitter<LangChangeEvent>;
57 /**
58 * An EventEmitter to listen to default lang change events
59 * onDefaultLangChange.subscribe((params: DefaultLangChangeEvent) => {
60 * // do something
61 * });
62 */
63 get onDefaultLangChange(): EventEmitter<DefaultLangChangeEvent>;
64 /**
65 * The default lang to fallback when translations are missing on the current lang
66 */
67 get defaultLang(): string;
68 set defaultLang(defaultLang: string);
69 /**
70 * The lang currently used
71 */
72 get currentLang(): string;
73 set currentLang(currentLang: string);
74 /**
75 * an array of langs
76 */
77 get langs(): string[];
78 set langs(langs: string[]);
79 /**
80 * a list of translations per lang
81 */
82 get translations(): any;
83 set translations(translations: any);
84 /**
85 *
86 * @param store an instance of the store (that is supposed to be unique)
87 * @param currentLoader An instance of the loader currently used
88 * @param compiler An instance of the compiler currently used
89 * @param parser An instance of the parser currently used
90 * @param missingTranslationHandler A handler for missing translations.
91 * @param useDefaultLang whether we should use default language translation when current language translation is missing.
92 * @param isolate whether this service should use the store or not
93 * @param extend To make a child module extend (and use) translations from parent modules.
94 * @param defaultLanguage Set the default language using configuration
95 */
96 constructor(store: TranslateStore, currentLoader: TranslateLoader, compiler: TranslateCompiler, parser: TranslateParser, missingTranslationHandler: MissingTranslationHandler, useDefaultLang: boolean, isolate: boolean, extend: boolean, defaultLanguage: string);
97 /**
98 * Sets the default language to use as a fallback
99 */
100 setDefaultLang(lang: string): void;
101 /**
102 * Gets the default language used
103 */
104 getDefaultLang(): string;
105 /**
106 * Changes the lang currently used
107 */
108 use(lang: string): Observable<any>;
109 /**
110 * Retrieves the given translations
111 */
112 private retrieveTranslations;
113 /**
114 * Gets an object of translations for a given language with the current loader
115 * and passes it through the compiler
116 */
117 getTranslation(lang: string): Observable<any>;
118 /**
119 * Manually sets an object of translations for a given language
120 * after passing it through the compiler
121 */
122 setTranslation(lang: string, translations: Object, shouldMerge?: boolean): void;
123 /**
124 * Returns an array of currently available langs
125 */
126 getLangs(): Array<string>;
127 /**
128 * Add available langs
129 */
130 addLangs(langs: Array<string>): void;
131 /**
132 * Update the list of available langs
133 */
134 private updateLangs;
135 /**
136 * Returns the parsed result of the translations
137 */
138 getParsedResult(translations: any, key: any, interpolateParams?: Object): any;
139 /**
140 * Gets the translated value of a key (or an array of keys)
141 * @returns the translated key, or an object of translated keys
142 */
143 get(key: string | Array<string>, interpolateParams?: Object): Observable<string | any>;
144 /**
145 * Returns a stream of translated values of a key (or an array of keys) which updates
146 * whenever the translation changes.
147 * @returns A stream of the translated key, or an object of translated keys
148 */
149 getStreamOnTranslationChange(key: string | Array<string>, interpolateParams?: Object): Observable<string | any>;
150 /**
151 * Returns a stream of translated values of a key (or an array of keys) which updates
152 * whenever the language changes.
153 * @returns A stream of the translated key, or an object of translated keys
154 */
155 stream(key: string | Array<string>, interpolateParams?: Object): Observable<string | any>;
156 /**
157 * Returns a translation instantly from the internal state of loaded translation.
158 * All rules regarding the current language, the preferred language of even fallback languages will be used except any promise handling.
159 */
160 instant(key: string | Array<string>, interpolateParams?: Object): string | any;
161 /**
162 * Sets the translated value of a key, after compiling it
163 */
164 set(key: string, value: string, lang?: string): void;
165 /**
166 * Changes the current lang
167 */
168 private changeLang;
169 /**
170 * Changes the default lang
171 */
172 private changeDefaultLang;
173 /**
174 * Allows to reload the lang file from the file
175 */
176 reloadLang(lang: string): Observable<any>;
177 /**
178 * Deletes inner translation
179 */
180 resetLang(lang: string): void;
181 /**
182 * Returns the language code name from the browser, e.g. "de"
183 */
184 getBrowserLang(): string;
185 /**
186 * Returns the culture language code name from the browser, e.g. "de-DE"
187 */
188 getBrowserCultureLang(): string;
189}