|
| 1 | +import { InterpolateFunction } from "./translate.parser"; |
| 2 | +import { Observable } from "rxjs"; |
| 3 | + |
| 4 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 5 | +export type InterpolationParameters = Record<string, any>; |
| 6 | +export type StrictTranslation = string | StrictTranslation[] | TranslationObject | undefined | null; |
| 7 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 8 | +export type Translation = StrictTranslation | any; |
| 9 | + |
| 10 | +export interface TranslationObject { |
| 11 | + [key: string]: StrictTranslation; |
| 12 | +} |
| 13 | + |
| 14 | +export type InterpolatableTranslation = |
| 15 | + | string |
| 16 | + | InterpolatableTranslation[] |
| 17 | + | InterpolateFunction |
| 18 | + | InterpolatableTranslationObject |
| 19 | + | undefined |
| 20 | + | null; |
| 21 | + |
| 22 | +export interface InterpolatableTranslationObject { |
| 23 | + [key: string]: InterpolatableTranslation; |
| 24 | +} |
| 25 | + |
| 26 | +export type Language = string; |
| 27 | + |
| 28 | +export interface TranslationChangeEvent { |
| 29 | + translations: InterpolatableTranslationObject; |
| 30 | + lang: string; |
| 31 | +} |
| 32 | + |
| 33 | +export interface LangChangeEvent { |
| 34 | + lang: string; |
| 35 | + translations: InterpolatableTranslationObject; |
| 36 | +} |
| 37 | + |
| 38 | +export interface FallbackLangChangeEvent { |
| 39 | + lang: string; |
| 40 | + translations: InterpolatableTranslationObject; |
| 41 | +} |
| 42 | + |
| 43 | +/** @deprecated use `FallbackLangChangeEvent` */ |
| 44 | +export type DefaultLangChangeEvent = FallbackLangChangeEvent; |
| 45 | + |
| 46 | +export abstract class ITranslateService { |
| 47 | + public abstract readonly onTranslationChange: Observable<TranslationChangeEvent>; |
| 48 | + public abstract readonly onLangChange: Observable<LangChangeEvent>; |
| 49 | + public abstract readonly onFallbackLangChange: Observable<FallbackLangChangeEvent>; |
| 50 | + |
| 51 | + public abstract use(lang: Language): Observable<InterpolatableTranslationObject>; |
| 52 | + |
| 53 | + public abstract setFallbackLang(lang: Language): Observable<InterpolatableTranslationObject>; |
| 54 | + public abstract getFallbackLang(): Language | null; |
| 55 | + |
| 56 | + public abstract addLangs(languages: Language[]): void; |
| 57 | + public abstract getLangs(): readonly Language[]; |
| 58 | + public abstract reloadLang(lang: Language): Observable<InterpolatableTranslationObject>; |
| 59 | + public abstract resetLang(lang: Language): void; |
| 60 | + |
| 61 | + public abstract instant( |
| 62 | + key: string | string[], |
| 63 | + interpolateParams?: InterpolationParameters, |
| 64 | + ): Translation; |
| 65 | + |
| 66 | + public abstract stream( |
| 67 | + key: string | string[], |
| 68 | + interpolateParams?: InterpolationParameters, |
| 69 | + ): Observable<Translation>; |
| 70 | + |
| 71 | + public abstract getStreamOnTranslationChange( |
| 72 | + key: string | string[], |
| 73 | + interpolateParams?: InterpolationParameters, |
| 74 | + ): Observable<Translation>; |
| 75 | + |
| 76 | + public abstract set( |
| 77 | + key: string, |
| 78 | + translation: string | TranslationObject, |
| 79 | + lang?: Language, |
| 80 | + ): void; |
| 81 | + |
| 82 | + public abstract get( |
| 83 | + key: string | string[], |
| 84 | + interpolateParams?: InterpolationParameters, |
| 85 | + ): Observable<Translation>; |
| 86 | + |
| 87 | + public abstract setTranslation( |
| 88 | + lang: Language, |
| 89 | + translations: TranslationObject, |
| 90 | + shouldMerge?: boolean, |
| 91 | + ): void; |
| 92 | + |
| 93 | + public abstract getParsedResult( |
| 94 | + key: string | string[], |
| 95 | + interpolateParams?: InterpolationParameters, |
| 96 | + ): StrictTranslation | Observable<StrictTranslation>; |
| 97 | + |
| 98 | + public abstract getBrowserLang(): Language | undefined; |
| 99 | + |
| 100 | + public abstract getBrowserCultureLang(): Language | undefined; |
| 101 | + |
| 102 | + /** |
| 103 | + * Returns the current language |
| 104 | + * @deprecated use `getCurrentLang()` |
| 105 | + */ |
| 106 | + public abstract readonly currentLang: Language; |
| 107 | + |
| 108 | + /** |
| 109 | + * Returns a list of known languages - either loaded |
| 110 | + * or set by using `addLangs()` |
| 111 | + * @deprecated use `getLangs()` |
| 112 | + */ |
| 113 | + public abstract readonly langs: readonly Language[]; |
| 114 | + |
| 115 | + /** |
| 116 | + * Sets the fallback language |
| 117 | + * @param lang The language to set |
| 118 | + * @deprecated use `setFallbackLang(lang)` |
| 119 | + */ |
| 120 | + public abstract setDefaultLang(lang: Language): Observable<InterpolatableTranslationObject>; |
| 121 | + |
| 122 | + /** |
| 123 | + * Gets the fallback language |
| 124 | + * @deprecated use `getFallbackLang()` |
| 125 | + */ |
| 126 | + public abstract getDefaultLang(): Language | null; |
| 127 | + |
| 128 | + /** |
| 129 | + * Returns the fallback language |
| 130 | + * @deprectated use `getFallbackLang()` |
| 131 | + */ |
| 132 | + public abstract readonly defaultLang: Language | null; |
| 133 | + |
| 134 | + /** |
| 135 | + * @deprectated use `getFallbackLang()` |
| 136 | + */ |
| 137 | + public abstract readonly onDefaultLangChange: Observable<DefaultLangChangeEvent>; |
| 138 | +} |
0 commit comments