1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-07 09:31:31 +01:00
bitwarden-browser/src/services/i18n.service.ts
2018-07-25 11:18:57 -04:00

44 lines
1.5 KiB
TypeScript

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 = [
'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',
'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);
}
}