1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-27 04:03:00 +02:00
bitwarden-browser/apps/browser/src/platform/services/i18n.service.ts
Matt Gibson f4150ffda6
[PM-6511] New i18n for angular (#8122)
* 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
2024-03-11 13:59:19 -04:00

103 lines
2.0 KiB
TypeScript

import { I18nService as BaseI18nService } from "@bitwarden/common/platform/services/i18n.service";
import { GlobalStateProvider } from "@bitwarden/common/platform/state";
export default class I18nService extends BaseI18nService {
constructor(systemLanguage: string, globalStateProvider: GlobalStateProvider) {
super(
systemLanguage,
null,
async (formattedLocale: string) => {
// Deprecated
const file = await fetch(this.localesDirectory + formattedLocale + "/messages.json");
return await file.json();
},
globalStateProvider,
);
// Please leave 'en' where it is, as it's our fallback language in case no translation can be found
this.supportedTranslationLocales = [
"en",
"ar",
"az",
"be",
"bg",
"bn",
"bs",
"ca",
"cs",
"da",
"de",
"el",
"en-GB",
"en-IN",
"es",
"et",
"eu",
"fa",
"fi",
"fil",
"fr",
"he",
"hi",
"hr",
"hu",
"id",
"it",
"ja",
"ka",
"km",
"kn",
"ko",
"lt",
"lv",
"ml",
"nb",
"nl",
"nn",
"pl",
"pt-BR",
"pt-PT",
"ro",
"ru",
"si",
"sk",
"sl",
"sr",
"sv",
"th",
"tr",
"uk",
"vi",
"zh-CN",
"zh-TW",
];
}
t(id: string, p1?: string, p2?: string, p3?: string): string {
return this.translate(id, p1, p2, p3);
}
translate(id: string, p1?: string, p2?: string, p3?: string): string {
if (this.localesDirectory == null) {
const placeholders: string[] = [];
if (p1 != null) {
placeholders.push(p1);
}
if (p2 != null) {
placeholders.push(p2);
}
if (p3 != null) {
placeholders.push(p3);
}
if (placeholders.length) {
return chrome.i18n.getMessage(id, placeholders);
} else {
return chrome.i18n.getMessage(id);
}
}
return super.translate(id, p1, p2, p3);
}
}