1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-29 14:43:31 +00:00

new i18n properties

This commit is contained in:
Kyle Spearrin
2018-01-26 22:39:45 -05:00
parent 8a7311e441
commit f8aba3cc17
2 changed files with 17 additions and 14 deletions

View File

@@ -3,38 +3,41 @@ import * as path from 'path';
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
// First locale is the default (English)
const SupportedLocales = [
const SupportedTranslationLocales = [
'en', 'es',
];
export class I18nService implements I18nServiceAbstraction {
defaultMessages: any = {};
localeMessages: any = {};
language: string;
locale: string;
translationLocale: string;
collator: Intl.Collator;
inited: boolean;
constructor(private systemLanguage: string, private localesDirectory: string) {
}
async init(language?: string) {
async init(locale?: string) {
if (this.inited) {
throw new Error('i18n already initialized.');
}
this.inited = true;
this.language = language != null ? language : this.systemLanguage;
this.locale = this.translationLocale = locale != null ? locale : this.systemLanguage;
this.collator = new Intl.Collator(this.locale);
if (SupportedLocales.indexOf(this.language) === -1) {
this.language = this.language.slice(0, 2);
if (SupportedTranslationLocales.indexOf(this.translationLocale) === -1) {
this.translationLocale = this.translationLocale.slice(0, 2);
if (SupportedLocales.indexOf(this.language) === -1) {
this.language = SupportedLocales[0];
if (SupportedTranslationLocales.indexOf(this.translationLocale) === -1) {
this.translationLocale = SupportedTranslationLocales[0];
}
}
await this.loadMessages(this.language, this.localeMessages);
if (this.language !== SupportedLocales[0]) {
await this.loadMessages(SupportedLocales[0], this.defaultMessages);
await this.loadMessages(this.translationLocale, this.localeMessages);
if (this.translationLocale !== SupportedTranslationLocales[0]) {
await this.loadMessages(SupportedTranslationLocales[0], this.defaultMessages);
}
}