mirror of
https://github.com/bitwarden/browser.git
synced 2025-03-19 14:49:13 +01:00
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { I18nService as BaseI18nService } from 'jslib/services/i18n.service';
|
|
|
|
import { BrowserApi } from '../browser/browserApi';
|
|
import { SafariApp } from '../browser/safariApp';
|
|
|
|
export default class I18nService extends BaseI18nService {
|
|
constructor(systemLanguage: string) {
|
|
super(systemLanguage, BrowserApi.isSafariApi ? 'safari' : null, async (formattedLocale: string) => {
|
|
if (BrowserApi.isSafariApi) {
|
|
await SafariApp.sendMessageToApp('getLocaleStrings', formattedLocale);
|
|
return (window as any).bitwardenLocaleStrings;
|
|
} else {
|
|
// Deprecated
|
|
const file = await fetch(this.localesDirectory + formattedLocale + '/messages.json');
|
|
return await file.json();
|
|
}
|
|
});
|
|
|
|
this.supportedTranslationLocales = [
|
|
'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', 'sr', '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);
|
|
}
|
|
}
|