2023-06-06 22:34:53 +02:00
|
|
|
import { TranslationService as BaseTranslationService } from "@bitwarden/common/platform/services/translation.service";
|
2023-02-04 15:23:42 +01:00
|
|
|
|
|
|
|
import { SupportedTranslationLocales } from "../translation-constants";
|
|
|
|
|
|
|
|
export class TranslationService extends BaseTranslationService {
|
|
|
|
private _translationLocale: string;
|
|
|
|
|
|
|
|
constructor(systemLanguage: string, localesDirectory: string) {
|
|
|
|
super(systemLanguage || "en-US", localesDirectory, async (formattedLocale: string) => {
|
|
|
|
const filePath =
|
|
|
|
this.localesDirectory +
|
|
|
|
"/" +
|
|
|
|
formattedLocale +
|
|
|
|
"/messages.json?cache=" +
|
|
|
|
process.env.CACHE_TAG;
|
|
|
|
const localesResult = await fetch(filePath);
|
|
|
|
const locales = await localesResult.json();
|
|
|
|
return locales;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.supportedTranslationLocales = SupportedTranslationLocales;
|
|
|
|
}
|
|
|
|
|
|
|
|
get translationLocale(): string {
|
|
|
|
return this._translationLocale;
|
|
|
|
}
|
|
|
|
|
|
|
|
set translationLocale(locale: string) {
|
|
|
|
this._translationLocale = locale;
|
|
|
|
}
|
|
|
|
}
|