mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
* Require init in i18n service. this is needed to load translations and set translation locale * No longer need to cast i18n * Expose user preferred locale in i18nService This is for correctly displaying `default` when no locale has been set in preferences components. The `locale$` observable should always resolve to the currently locale currently being translated to.
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { Observable } from "rxjs";
|
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
|
|
export class I18nMockService implements I18nService {
|
|
userSetLocale$: Observable<string | undefined>;
|
|
locale$: Observable<string>;
|
|
supportedTranslationLocales: string[];
|
|
translationLocale: string;
|
|
collator: Intl.Collator;
|
|
localeNames: Map<string, string>;
|
|
|
|
constructor(private lookupTable: Record<string, string | ((...args: string[]) => string)>) {}
|
|
|
|
t(id: string, p1?: string, p2?: string, p3?: string) {
|
|
let value = this.lookupTable[id];
|
|
if (typeof value == "string") {
|
|
if (value !== "") {
|
|
if (p1 != null) {
|
|
value = value.split("__$1__").join(p1.toString());
|
|
}
|
|
if (p2 != null) {
|
|
value = value.split("__$2__").join(p2.toString());
|
|
}
|
|
if (p3 != null) {
|
|
value = value.split("__$3__").join(p3.toString());
|
|
}
|
|
}
|
|
|
|
return value;
|
|
}
|
|
return value(p1, p2, p3);
|
|
}
|
|
|
|
translate(id: string, p1?: string, p2?: string, p3?: string) {
|
|
return this.t(id, p1, p2, p3);
|
|
}
|
|
|
|
async setLocale(locale: string): Promise<void> {
|
|
throw new Error("Method not implemented.");
|
|
}
|
|
|
|
init(): Promise<void> {
|
|
throw new Error("Method not implemented.");
|
|
}
|
|
}
|