bitwarden-estensione-browser/apps/browser/src/services/i18n.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
1.8 KiB
TypeScript
Raw Normal View History

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 {
2019-08-14 22:54:40 +02: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
});
// Please leave 'en' where it is, as it's our fallback language in case no translation can be found
2018-04-11 21:16:35 +02:00
this.supportedTranslationLocales = [
"en",
"az",
"be",
"bg",
"bn",
"bs",
"ca",
"cs",
"da",
"de",
"el",
"en-GB",
"en-IN",
"es",
"et",
"fa",
"fi",
"fil",
"fr",
"he",
"hi",
"hr",
"hu",
2021-07-06 12:39:39 +02:00
"id",
"it",
"ja",
"ka",
"km",
2021-07-06 12:39:39 +02:00
"kn",
"ko",
"lt",
2021-07-06 12:39:39 +02:00
"lv",
"ml",
"nb",
"nl",
"nn",
2021-07-06 12:39:39 +02:00
"pl",
"pt-BR",
"pt-PT",
"ro",
"ru",
"si",
2021-07-06 12:39:39 +02:00
"sk",
"sl",
2021-07-06 12:39:39 +02:00
"sr",
"sv",
"th",
"tr",
"uk",
"vi",
"zh-CN",
"zh-TW",
2018-04-11 21:16:35 +02:00
];
2018-04-11 20:52:49 +02:00
}
2018-01-12 04:13:57 +01:00
2018-04-11 20:52:49 +02: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
}
2018-04-11 20:52:49 +02: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
2018-04-11 20:52:49 +02:00
if (placeholders.length) {
2018-04-11 21:16:35 +02:00
return chrome.i18n.getMessage(id, placeholders);
2021-12-21 15:43:35 +01:00
} else {
2018-04-11 20:52:49 +02:00
return chrome.i18n.getMessage(id);
2021-12-21 15:43:35 +01:00
}
2018-01-13 03:51:07 +01:00
}
2021-12-21 15:43:35 +01:00
2018-04-11 20:52:49 +02:00
return super.translate(id, p1, p2, p3);
2021-12-21 15:43:35 +01:00
}
2018-01-13 03:51:07 +01:00
}