2021-06-07 19:25:37 +02:00
|
|
|
import { I18nService as BaseI18nService } from 'jslib-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) {
|
2021-02-03 20:36:05 +01:00
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
this.supportedTranslationLocales = [
|
2021-05-13 19:54:56 +02:00
|
|
|
'en', 'be', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en-GB', 'en-IN', 'es', 'et', 'fa', 'fi', 'fr', 'he', 'hr', 'hu',
|
2021-05-14 15:59:24 +02:00
|
|
|
'id', 'it', 'ja', 'ko', 'lv', 'ml', 'nb', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sk', 'sr', 'sv', 'th', 'tr', 'uk',
|
2020-11-18 22:54:29 +01:00
|
|
|
'vi', 'zh-CN', 'zh-TW',
|
2018-04-11 21:16:35 +02:00
|
|
|
];
|
2017-12-06 19:51:49 +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-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
|
|
|
}
|
|
|
|
}
|