UNPKG

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