2022-06-14 17:10:53 +02:00
|
|
|
import { I18nService as BaseI18nService } from "@bitwarden/common/services/i18n.service";
|
2018-04-11 21:16:35 +02:00
|
|
|
|
|
|
|
export default class I18nService extends BaseI18nService {
|
2021-12-21 15:43:35 +01:00
|
|
|
constructor(systemLanguage: string) {
|
|
|
|
super(systemLanguage, null, async (formattedLocale: string) => {
|
|
|
|
// Deprecated
|
|
|
|
const file = await fetch(this.localesDirectory + formattedLocale + "/messages.json");
|
|
|
|
return await file.json();
|
|
|
|
});
|
2018-04-11 21:16:35 +02:00
|
|
|
|
2021-12-21 15:43:35 +01:00
|
|
|
// Please leave 'en' where it is, as it's our fallback language in case no translation can be found
|
|
|
|
this.supportedTranslationLocales = [
|
|
|
|
"en",
|
|
|
|
"az",
|
|
|
|
"be",
|
|
|
|
"bg",
|
|
|
|
"bn",
|
2022-02-25 22:13:00 +01:00
|
|
|
"bs",
|
2021-12-21 15:43:35 +01:00
|
|
|
"ca",
|
|
|
|
"cs",
|
|
|
|
"da",
|
|
|
|
"de",
|
|
|
|
"el",
|
|
|
|
"en-GB",
|
|
|
|
"en-IN",
|
|
|
|
"es",
|
|
|
|
"et",
|
|
|
|
"fa",
|
|
|
|
"fi",
|
2022-02-25 22:13:00 +01:00
|
|
|
"fil",
|
2021-12-21 15:43:35 +01:00
|
|
|
"fr",
|
|
|
|
"he",
|
2022-02-25 22:13:00 +01:00
|
|
|
"hi",
|
2021-12-21 15:43:35 +01:00
|
|
|
"hr",
|
|
|
|
"hu",
|
|
|
|
"id",
|
|
|
|
"it",
|
|
|
|
"ja",
|
2022-02-25 22:13:00 +01:00
|
|
|
"ka",
|
|
|
|
"km",
|
2021-12-21 15:43:35 +01:00
|
|
|
"kn",
|
|
|
|
"ko",
|
2022-02-25 22:13:00 +01:00
|
|
|
"lt",
|
2021-12-21 15:43:35 +01:00
|
|
|
"lv",
|
|
|
|
"ml",
|
|
|
|
"nb",
|
|
|
|
"nl",
|
2022-02-25 22:13:00 +01:00
|
|
|
"nn",
|
2021-12-21 15:43:35 +01:00
|
|
|
"pl",
|
|
|
|
"pt-BR",
|
|
|
|
"pt-PT",
|
|
|
|
"ro",
|
|
|
|
"ru",
|
2022-02-25 22:13:00 +01:00
|
|
|
"si",
|
2021-12-21 15:43:35 +01:00
|
|
|
"sk",
|
2022-02-25 22:13:00 +01:00
|
|
|
"sl",
|
2021-12-21 15:43:35 +01:00
|
|
|
"sr",
|
|
|
|
"sv",
|
|
|
|
"th",
|
|
|
|
"tr",
|
|
|
|
"uk",
|
|
|
|
"vi",
|
|
|
|
"zh-CN",
|
|
|
|
"zh-TW",
|
|
|
|
];
|
|
|
|
}
|
2018-01-12 04:13:57 +01:00
|
|
|
|
2021-12-21 15:43:35 +01:00
|
|
|
t(id: string, p1?: string, p2?: string, p3?: string): string {
|
|
|
|
return this.translate(id, p1, p2, p3);
|
|
|
|
}
|
2018-01-12 04:13:57 +01:00
|
|
|
|
2021-12-21 15:43:35 +01:00
|
|
|
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);
|
|
|
|
}
|
2018-01-13 03:51:07 +01:00
|
|
|
|
2021-12-21 15:43:35 +01:00
|
|
|
if (placeholders.length) {
|
|
|
|
return chrome.i18n.getMessage(id, placeholders);
|
|
|
|
} else {
|
|
|
|
return chrome.i18n.getMessage(id);
|
|
|
|
}
|
2018-01-13 03:51:07 +01:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
|
|
|
return super.translate(id, p1, p2, p3);
|
|
|
|
}
|
2018-01-13 03:51:07 +01:00
|
|
|
}
|