mirror of
https://github.com/bitwarden/browser
synced 2026-03-01 02:51:24 +00:00
* Use state provider to store preferred language * migrate preferred language * Use new i18n provider to get LOCAL_ID * Fix preloaded english i18n This is a mock service that forces english translations, it doesn't need the i18n interface that allows changing of locales. * PR improvements * Fixup merge
31 lines
933 B
TypeScript
31 lines
933 B
TypeScript
import * as fs from "fs";
|
|
import * as path from "path";
|
|
|
|
import { I18nService as BaseI18nService } from "@bitwarden/common/platform/services/i18n.service";
|
|
import { GlobalStateProvider } from "@bitwarden/common/platform/state";
|
|
|
|
export class I18nService extends BaseI18nService {
|
|
constructor(
|
|
systemLanguage: string,
|
|
localesDirectory: string,
|
|
globalStateProvider: GlobalStateProvider,
|
|
) {
|
|
super(
|
|
systemLanguage,
|
|
localesDirectory,
|
|
(formattedLocale: string) => {
|
|
const filePath = path.join(
|
|
__dirname,
|
|
this.localesDirectory + "/" + formattedLocale + "/messages.json",
|
|
);
|
|
const localesJson = fs.readFileSync(filePath, "utf8");
|
|
const locales = JSON.parse(localesJson.replace(/^\uFEFF/, "")); // strip the BOM
|
|
return Promise.resolve(locales);
|
|
},
|
|
globalStateProvider,
|
|
);
|
|
|
|
this.supportedTranslationLocales = ["en"];
|
|
}
|
|
}
|