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

53 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-04-11 21:16:35 +02:00
import { I18nService as BaseI18nService } from 'jslib/services/i18n.service';
2019-08-14 22:54:40 +02:00
import { BrowserApi } from '../browser/browserApi';
import { SafariApp } from '../browser/safariApp';
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, BrowserApi.isSafariApi ? 'safari' : null, async (formattedLocale: string) => {
if (BrowserApi.isSafariApi) {
2019-08-15 19:22:26 +02:00
await SafariApp.sendMessageToApp('getLocaleStrings', formattedLocale);
return (window as any).bitwardenLocaleStrings;
2019-08-14 22:54:40 +02:00
} else {
// Deprecated
const file = await fetch(this.localesDirectory + formattedLocale + '/messages.json');
return await file.json();
}
2018-04-11 21:16:35 +02:00
});
this.supportedTranslationLocales = [
2020-09-15 19:38:40 +02:00
'en', 'be', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'en-GB', 'es', 'et', 'fa', 'fi', 'fr', 'he', 'hr', 'hu',
'id', 'it', 'ja', 'ko', 'nb', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sk', 'sv', 'th', 'tr', 'uk', 'vi',
2018-04-11 21:16:35 +02:00
'zh-CN', 'zh-TW',
];
}
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-12 04:13:57 +01:00
}
2018-04-11 20:52:49 +02:00
if (placeholders.length) {
return chrome.i18n.getMessage(id, placeholders);
} else {
return chrome.i18n.getMessage(id);
}
}
2018-01-13 03:51:07 +01:00
2018-04-11 21:16:35 +02:00
return super.translate(id, p1, p2, p3);
2018-01-13 03:51:07 +01:00
}
}