1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00
Files
browser/libs/components/src/utils/i18n-mock.service.ts
Matt Gibson 25f89e2a1c [PM-6769] [SM-1158] Fix Translation pipe issues on main (#8319)
* 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.
2024-03-13 11:35:46 -04:00

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.");
}
}