From f8aba3cc171da09126ee2c6a100979d2ef3f37b7 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 26 Jan 2018 22:39:45 -0500 Subject: [PATCH] new i18n properties --- src/app/services/services.module.ts | 6 +++--- src/services/i18n.service.ts | 25 ++++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index c11c9229a4..3a60bb46aa 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -75,10 +75,10 @@ const environmentService = new EnvironmentService(apiService, storageService); const userService = new UserService(tokenService, storageService); const settingsService = new SettingsService(userService, storageService); const cipherService = new CipherService(cryptoService, userService, settingsService, - apiService, storageService); + apiService, storageService, i18nService); const folderService = new FolderService(cryptoService, userService, - () => i18nService.t('noneFolder'), apiService, storageService); -const collectionService = new CollectionService(cryptoService, userService, storageService); + () => i18nService.t('noneFolder'), apiService, storageService, i18nService); +const collectionService = new CollectionService(cryptoService, userService, storageService, i18nService); const lockService = new LockService(cipherService, folderService, collectionService, cryptoService, platformUtilsService, storageService, () => { /* set icon */ }, () => { /* refresh badge and menu */ }); diff --git a/src/services/i18n.service.ts b/src/services/i18n.service.ts index 97fcd2521d..5b9d3dad71 100644 --- a/src/services/i18n.service.ts +++ b/src/services/i18n.service.ts @@ -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); } }