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

44 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-04-11 21:16:35 +02:00
import { I18nService as BaseI18nService } from 'jslib/services/i18n.service';
export default class I18nService extends BaseI18nService {
constructor(systemLanguage: string, localesDirectory: string) {
super(systemLanguage, localesDirectory, async (formattedLocale: string) => {
const file = await fetch(localesDirectory + formattedLocale + '/messages.json');
return await file.json();
});
this.supportedTranslationLocales = [
2018-07-25 17:18:57 +02:00
'en', 'bg', 'cs', 'da', 'de', 'es', 'et', 'fa', 'fi', 'fr', '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
}
}