mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-24 11:55:50 +01:00
new i18n properties
This commit is contained in:
parent
8a7311e441
commit
f8aba3cc17
@ -75,10 +75,10 @@ const environmentService = new EnvironmentService(apiService, storageService);
|
|||||||
const userService = new UserService(tokenService, storageService);
|
const userService = new UserService(tokenService, storageService);
|
||||||
const settingsService = new SettingsService(userService, storageService);
|
const settingsService = new SettingsService(userService, storageService);
|
||||||
const cipherService = new CipherService(cryptoService, userService, settingsService,
|
const cipherService = new CipherService(cryptoService, userService, settingsService,
|
||||||
apiService, storageService);
|
apiService, storageService, i18nService);
|
||||||
const folderService = new FolderService(cryptoService, userService,
|
const folderService = new FolderService(cryptoService, userService,
|
||||||
() => i18nService.t('noneFolder'), apiService, storageService);
|
() => i18nService.t('noneFolder'), apiService, storageService, i18nService);
|
||||||
const collectionService = new CollectionService(cryptoService, userService, storageService);
|
const collectionService = new CollectionService(cryptoService, userService, storageService, i18nService);
|
||||||
const lockService = new LockService(cipherService, folderService, collectionService,
|
const lockService = new LockService(cipherService, folderService, collectionService,
|
||||||
cryptoService, platformUtilsService, storageService,
|
cryptoService, platformUtilsService, storageService,
|
||||||
() => { /* set icon */ }, () => { /* refresh badge and menu */ });
|
() => { /* set icon */ }, () => { /* refresh badge and menu */ });
|
||||||
|
@ -3,38 +3,41 @@ import * as path from 'path';
|
|||||||
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
|
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
|
||||||
|
|
||||||
// First locale is the default (English)
|
// First locale is the default (English)
|
||||||
const SupportedLocales = [
|
const SupportedTranslationLocales = [
|
||||||
'en', 'es',
|
'en', 'es',
|
||||||
];
|
];
|
||||||
|
|
||||||
export class I18nService implements I18nServiceAbstraction {
|
export class I18nService implements I18nServiceAbstraction {
|
||||||
defaultMessages: any = {};
|
defaultMessages: any = {};
|
||||||
localeMessages: any = {};
|
localeMessages: any = {};
|
||||||
language: string;
|
locale: string;
|
||||||
|
translationLocale: string;
|
||||||
|
collator: Intl.Collator;
|
||||||
inited: boolean;
|
inited: boolean;
|
||||||
|
|
||||||
constructor(private systemLanguage: string, private localesDirectory: string) {
|
constructor(private systemLanguage: string, private localesDirectory: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(language?: string) {
|
async init(locale?: string) {
|
||||||
if (this.inited) {
|
if (this.inited) {
|
||||||
throw new Error('i18n already initialized.');
|
throw new Error('i18n already initialized.');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inited = true;
|
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) {
|
if (SupportedTranslationLocales.indexOf(this.translationLocale) === -1) {
|
||||||
this.language = this.language.slice(0, 2);
|
this.translationLocale = this.translationLocale.slice(0, 2);
|
||||||
|
|
||||||
if (SupportedLocales.indexOf(this.language) === -1) {
|
if (SupportedTranslationLocales.indexOf(this.translationLocale) === -1) {
|
||||||
this.language = SupportedLocales[0];
|
this.translationLocale = SupportedTranslationLocales[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.loadMessages(this.language, this.localeMessages);
|
await this.loadMessages(this.translationLocale, this.localeMessages);
|
||||||
if (this.language !== SupportedLocales[0]) {
|
if (this.translationLocale !== SupportedTranslationLocales[0]) {
|
||||||
await this.loadMessages(SupportedLocales[0], this.defaultMessages);
|
await this.loadMessages(SupportedTranslationLocales[0], this.defaultMessages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user