mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
i18n2service
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
|||||||
CryptoService as CryptoServiceAbstraction,
|
CryptoService as CryptoServiceAbstraction,
|
||||||
EnvironmentService as EnvironmentServiceAbstraction,
|
EnvironmentService as EnvironmentServiceAbstraction,
|
||||||
FolderService as FolderServiceAbstraction,
|
FolderService as FolderServiceAbstraction,
|
||||||
|
I18nService as I18nServiceAbstraction,
|
||||||
LockService as LockServiceAbstraction,
|
LockService as LockServiceAbstraction,
|
||||||
MessagingService as MessagingServiceAbstraction,
|
MessagingService as MessagingServiceAbstraction,
|
||||||
PasswordGenerationService as PasswordGenerationServiceAbstraction,
|
PasswordGenerationService as PasswordGenerationServiceAbstraction,
|
||||||
@@ -58,6 +59,7 @@ import BrowserMessagingService from '../services/browserMessaging.service';
|
|||||||
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
|
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
|
||||||
import BrowserStorageService from '../services/browserStorage.service';
|
import BrowserStorageService from '../services/browserStorage.service';
|
||||||
import i18nService from '../services/i18n.service';
|
import i18nService from '../services/i18n.service';
|
||||||
|
import I18n2Service from '../services/i18n2.service';
|
||||||
|
|
||||||
import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service';
|
import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service';
|
||||||
|
|
||||||
@@ -66,6 +68,7 @@ export default class MainBackground {
|
|||||||
storageService: StorageServiceAbstraction;
|
storageService: StorageServiceAbstraction;
|
||||||
secureStorageService: StorageServiceAbstraction;
|
secureStorageService: StorageServiceAbstraction;
|
||||||
i18nService: any;
|
i18nService: any;
|
||||||
|
i18n2Service: I18nServiceAbstraction;
|
||||||
platformUtilsService: PlatformUtilsServiceAbstraction;
|
platformUtilsService: PlatformUtilsServiceAbstraction;
|
||||||
utilsService: UtilsServiceAbstraction;
|
utilsService: UtilsServiceAbstraction;
|
||||||
constantsService: ConstantsService;
|
constantsService: ConstantsService;
|
||||||
@@ -115,6 +118,7 @@ export default class MainBackground {
|
|||||||
this.storageService = new BrowserStorageService(this.platformUtilsService, false);
|
this.storageService = new BrowserStorageService(this.platformUtilsService, false);
|
||||||
this.secureStorageService = new BrowserStorageService(this.platformUtilsService, true);
|
this.secureStorageService = new BrowserStorageService(this.platformUtilsService, true);
|
||||||
this.i18nService = i18nService(this.platformUtilsService);
|
this.i18nService = i18nService(this.platformUtilsService);
|
||||||
|
this.i18n2Service = new I18n2Service(window.navigator.language, i18nService);
|
||||||
this.constantsService = new ConstantsService(this.i18nService, delayi18nLoad);
|
this.constantsService = new ConstantsService(this.i18nService, delayi18nLoad);
|
||||||
this.cryptoService = new CryptoService(this.storageService, this.secureStorageService);
|
this.cryptoService = new CryptoService(this.storageService, this.secureStorageService);
|
||||||
this.tokenService = new TokenService(this.storageService);
|
this.tokenService = new TokenService(this.storageService);
|
||||||
@@ -125,10 +129,11 @@ export default class MainBackground {
|
|||||||
this.userService = new UserService(this.tokenService, this.storageService);
|
this.userService = new UserService(this.tokenService, this.storageService);
|
||||||
this.settingsService = new SettingsService(this.userService, this.storageService);
|
this.settingsService = new SettingsService(this.userService, this.storageService);
|
||||||
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
|
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
|
||||||
this.apiService, this.storageService);
|
this.apiService, this.storageService, this.i18n2Service);
|
||||||
this.folderService = new FolderService(this.cryptoService, this.userService,
|
this.folderService = new FolderService(this.cryptoService, this.userService,
|
||||||
() => this.i18nService.noneFolder, this.apiService, this.storageService);
|
() => this.i18nService.noneFolder, this.apiService, this.storageService, this.i18n2Service);
|
||||||
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService);
|
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
|
||||||
|
this.i18n2Service);
|
||||||
this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService,
|
this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService,
|
||||||
this.cryptoService, this.platformUtilsService, this.storageService,
|
this.cryptoService, this.platformUtilsService, this.storageService,
|
||||||
() => this.setIcon(), () => this.refreshBadgeAndMenu());
|
() => this.setIcon(), () => this.refreshBadgeAndMenu());
|
||||||
|
|||||||
29
src/services/i18n2.service.ts
Normal file
29
src/services/i18n2.service.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
|
||||||
|
|
||||||
|
export default class I18n2Service implements I18nServiceAbstraction {
|
||||||
|
locale: string;
|
||||||
|
translationLocale: string;
|
||||||
|
collator: Intl.Collator;
|
||||||
|
inited: boolean;
|
||||||
|
|
||||||
|
constructor(private systemLanguage: string, private i18nService: any) {
|
||||||
|
}
|
||||||
|
|
||||||
|
async init(locale?: string) {
|
||||||
|
if (this.inited) {
|
||||||
|
throw new Error('i18n already initialized.');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.inited = true;
|
||||||
|
this.locale = this.translationLocale = locale != null ? locale : this.systemLanguage;
|
||||||
|
this.collator = new Intl.Collator(this.locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
t(id: string): string {
|
||||||
|
return this.translate(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
translate(id: string): string {
|
||||||
|
return this.i18nService[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user