|
|
@@ -5,6 +5,7 @@ import { BrowserModule } from '@angular/platform-browser';
|
|
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
|
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
|
|
|
|
|
+import { getAppConfig } from './app.config';
|
|
|
import { getDefaultLanguage } from './common/utilities/get-default-language';
|
|
|
import { AppShellComponent } from './components/app-shell/app-shell.component';
|
|
|
import { BreadcrumbComponent } from './components/breadcrumb/breadcrumb.component';
|
|
|
@@ -13,13 +14,13 @@ import { JobListComponent } from './components/job-list/job-list.component';
|
|
|
import { MainNavComponent } from './components/main-nav/main-nav.component';
|
|
|
import { NotificationComponent } from './components/notification/notification.component';
|
|
|
import { OverlayHostComponent } from './components/overlay-host/overlay-host.component';
|
|
|
-import { UiLanguageSwitcherComponent } from './components/ui-language-switcher/ui-language-switcher.component';
|
|
|
+import { UiLanguageSwitcherDialogComponent } from './components/ui-language-switcher-dialog/ui-language-switcher-dialog.component';
|
|
|
import { UserMenuComponent } from './components/user-menu/user-menu.component';
|
|
|
import { DataModule } from './data/data.module';
|
|
|
-import { DataService } from './data/providers/data.service';
|
|
|
import { CustomHttpTranslationLoader } from './providers/i18n/custom-http-loader';
|
|
|
import { InjectableTranslateMessageFormatCompiler } from './providers/i18n/custom-message-format-compiler';
|
|
|
import { I18nService } from './providers/i18n/i18n.service';
|
|
|
+import { LocalStorageService } from './providers/local-storage/local-storage.service';
|
|
|
import { SharedModule } from './shared/shared.module';
|
|
|
|
|
|
@NgModule({
|
|
|
@@ -45,15 +46,33 @@ import { SharedModule } from './shared/shared.module';
|
|
|
BreadcrumbComponent,
|
|
|
OverlayHostComponent,
|
|
|
NotificationComponent,
|
|
|
- UiLanguageSwitcherComponent,
|
|
|
+ UiLanguageSwitcherDialogComponent,
|
|
|
JobListComponent,
|
|
|
ChannelSwitcherComponent,
|
|
|
],
|
|
|
})
|
|
|
export class CoreModule {
|
|
|
- constructor(private dataService: DataService, private i18nService: I18nService) {
|
|
|
- this.dataService.client.setUiLanguage(getDefaultLanguage());
|
|
|
- this.i18nService.setDefaultLanguage(getDefaultLanguage());
|
|
|
+ constructor(private i18nService: I18nService, private localStorageService: LocalStorageService) {
|
|
|
+ this.initUiLanguages();
|
|
|
+ }
|
|
|
+
|
|
|
+ private initUiLanguages() {
|
|
|
+ const defaultLanguage = getDefaultLanguage();
|
|
|
+ const lastLanguage = this.localStorageService.get('uiLanguageCode');
|
|
|
+ const availableLanguages = getAppConfig().availableLanguages;
|
|
|
+
|
|
|
+ if (!availableLanguages.includes(defaultLanguage)) {
|
|
|
+ throw new Error(
|
|
|
+ `The defaultLanguage "${defaultLanguage}" must be one of the availableLanguages [${availableLanguages
|
|
|
+ .map(l => `"${l}"`)
|
|
|
+ .join(', ')}]`,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ const uiLanguage = availableLanguages.includes(lastLanguage) ? lastLanguage : defaultLanguage;
|
|
|
+ this.localStorageService.set('uiLanguageCode', uiLanguage);
|
|
|
+ this.i18nService.setLanguage(uiLanguage);
|
|
|
+ this.i18nService.setDefaultLanguage(defaultLanguage);
|
|
|
+ this.i18nService.setAvailableLanguages(availableLanguages || [defaultLanguage]);
|
|
|
}
|
|
|
}
|
|
|
|