1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

[EC-772] Add i18n key typechecking in web (#4023)

This commit is contained in:
Thomas Rittson
2022-12-21 14:27:00 +10:00
committed by GitHub
parent b331f5b329
commit 5a1940f3f4
50 changed files with 176 additions and 109 deletions

View File

@@ -1,8 +1,8 @@
import { Observable, ReplaySubject } from "rxjs";
import { I18nService as I18nServiceAbstraction } from "../abstractions/i18n.service";
import { I18nService } from "../abstractions/i18n.service";
export class I18nService implements I18nServiceAbstraction {
export class I18nServiceImplementation<TKey = string> implements I18nService<TKey> {
private _locale = new ReplaySubject<string>(1);
locale$: Observable<string> = this._locale.asObservable();
// First locale is the default (English)
@@ -118,11 +118,11 @@ export class I18nService implements I18nServiceAbstraction {
}
}
t(id: string, p1?: string, p2?: string, p3?: string): string {
t(id: TKey, p1?: string, p2?: string, p3?: string): string {
return this.translate(id, p1, p2, p3);
}
translate(id: string, p1?: string | number, p2?: string | number, p3?: string | number): string {
translate(id: TKey, p1?: string | number, p2?: string | number, p3?: string | number): string {
let result: string;
// eslint-disable-next-line
if (this.localeMessages.hasOwnProperty(id) && this.localeMessages[id]) {