common-header-lib 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +24 -24
  2. package/assets/i18n/ar.json +2 -1
  3. package/assets/i18n/de.json +2 -1
  4. package/assets/i18n/en.json +2 -2
  5. package/assets/i18n/es.json +2 -1
  6. package/assets/i18n/fr.json +2 -1
  7. package/assets/i18n/hi.json +2 -1
  8. package/assets/i18n/ja.json +2 -1
  9. package/assets/i18n/ko.json +2 -1
  10. package/assets/i18n/languages.json +1 -0
  11. package/assets/images/toast-alert.svg +3 -3
  12. package/assets/images/toast-error.svg +3 -3
  13. package/assets/images/toast-info.svg +3 -3
  14. package/assets/images/toast-success.svg +10 -10
  15. package/assets/scss/styles.scss +577 -577
  16. package/esm2020/lib/common-header-lib.component.mjs +1 -1
  17. package/esm2020/lib/common-header-lib.module.mjs +158 -20
  18. package/esm2020/lib/common-header-lib.service.mjs +1 -1
  19. package/esm2020/lib/components/confirm-dialog/confirm-dialog.component.mjs +3 -3
  20. package/esm2020/lib/components/ng-translation/ng-translation.component.mjs +33 -27
  21. package/esm2020/lib/model/data_model.mjs +17 -5
  22. package/esm2020/lib/services/http/http-common.service.mjs +1 -1
  23. package/esm2020/public-api.mjs +1 -1
  24. package/fesm2015/common-header-lib.mjs +208 -52
  25. package/fesm2015/common-header-lib.mjs.map +1 -1
  26. package/fesm2020/common-header-lib.mjs +204 -50
  27. package/fesm2020/common-header-lib.mjs.map +1 -1
  28. package/lib/common-header-lib.module.d.ts +47 -1
  29. package/lib/components/ng-translation/ng-translation.component.d.ts +6 -8
  30. package/lib/model/data_model.d.ts +1 -0
  31. package/package.json +1 -1
  32. package/src/assets/i18n/ar.json +2 -1
  33. package/src/assets/i18n/de.json +2 -1
  34. package/src/assets/i18n/en.json +2 -2
  35. package/src/assets/i18n/es.json +2 -1
  36. package/src/assets/i18n/fr.json +2 -1
  37. package/src/assets/i18n/hi.json +2 -1
  38. package/src/assets/i18n/ja.json +2 -1
  39. package/src/assets/i18n/ko.json +2 -1
  40. package/src/assets/i18n/languages.json +1 -0
  41. package/src/assets/images/toast-alert.svg +3 -3
  42. package/src/assets/images/toast-error.svg +3 -3
  43. package/src/assets/images/toast-info.svg +3 -3
  44. package/src/assets/images/toast-success.svg +10 -10
  45. package/src/assets/scss/styles.scss +577 -577
@@ -3,7 +3,7 @@ import { Injectable, EventEmitter, Component, Input, Output, Pipe, ViewEncapsula
3
3
  import { map, catchError, debounceTime, take, switchMap, takeUntil, finalize } from 'rxjs/operators';
4
4
  import * as i1 from '@angular/common/http';
5
5
  import { HttpParams, HttpClientModule, HttpClient } from '@angular/common/http';
6
- import { throwError, BehaviorSubject, Subject, map as map$1, catchError as catchError$1, of, takeUntil as takeUntil$1, finalize as finalize$1, forkJoin } from 'rxjs';
6
+ import { throwError, BehaviorSubject, Subject, map as map$1, catchError as catchError$1, of, takeUntil as takeUntil$1, finalize as finalize$1, forkJoin, firstValueFrom } from 'rxjs';
7
7
  import * as i9 from 'primeng/api';
8
8
  import { ConfirmationService } from 'primeng/api';
9
9
  import * as i2 from 'primeng/confirmdialog';
@@ -66,14 +66,26 @@ GlobalConstants.PAGEROW = 10;
66
66
  GlobalConstants.CONFIGCONNECTORS = false;
67
67
  GlobalConstants.USERLANGUAGES = [
68
68
  { langKey: 'en', langName: 'English' },
69
- { langKey: 'ar', langName: 'العربية' },
70
- { langKey: 'es', langName: 'Español' },
71
69
  { langKey: 'hi', langName: 'हिन्दी' },
72
- { langKey: 'ja', langName: '日本' },
70
+ { langKey: 'mr', langName: 'मराठी' },
71
+ { langKey: 'ar', langName: 'العربية' },
73
72
  { langKey: 'fr', langName: 'Français' },
73
+ { langKey: 'es', langName: 'Español' },
74
74
  { langKey: 'de', langName: 'Deutsch' },
75
- { langKey: 'ko', langName: '한국인' },
75
+ { langKey: 'ja', langName: '日本語' },
76
+ { langKey: 'ko', langName: '한국어' },
77
+ { langKey: 'zh', langName: '中文' },
78
+ { langKey: 'ru', langName: 'Русский' },
79
+ { langKey: 'pt', langName: 'Português' },
80
+ { langKey: 'it', langName: 'Italiano' },
81
+ { langKey: 'nl', langName: 'Nederlands' },
82
+ { langKey: 'tr', langName: 'Türkçe' },
83
+ { langKey: 'sv', langName: 'Svenska' },
84
+ { langKey: 'pl', langName: 'Polski' },
85
+ { langKey: 'th', langName: 'ไทย' },
86
+ { langKey: 'vi', langName: 'Tiếng Việt' },
76
87
  ];
88
+ GlobalConstants.USERFILTEREDLANGUAGES = [];
77
89
  GlobalConstants.DEFAULTLANG = { langKey: 'en', langName: 'English' };
78
90
  GlobalConstants.DEFAULTLANGKEY = 'en';
79
91
  GlobalConstants.DEFAULT_IMGPATH = 'assets/images/';
@@ -484,10 +496,10 @@ class ConfirmDialogComponent {
484
496
  }
485
497
  }
486
498
  ConfirmDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ConfirmDialogComponent, deps: [{ token: i9.ConfirmationService }], target: i0.ɵɵFactoryTarget.Component });
487
- ConfirmDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: ConfirmDialogComponent, selector: "confirm-dialog", inputs: { header: "header", message: "message" }, outputs: { result: "result" }, providers: [ConfirmationService], ngImport: i0, template: "<div class=\"card flex justify-center gap-2 view-pass-details confirmtion-modal\">\n <p-confirmDialog icon=\"none\" acceptIcon=\"\" rejectIcon=\"\"></p-confirmDialog>\n</div>\n", styles: [""], dependencies: [{ kind: "component", type: i2.ConfirmDialog, selector: "p-confirmDialog", inputs: ["header", "icon", "message", "style", "styleClass", "maskStyleClass", "acceptIcon", "acceptLabel", "acceptAriaLabel", "acceptVisible", "rejectIcon", "rejectLabel", "rejectAriaLabel", "rejectVisible", "acceptButtonStyleClass", "rejectButtonStyleClass", "closeOnEscape", "dismissableMask", "blockScroll", "rtl", "closable", "appendTo", "key", "autoZIndex", "baseZIndex", "transitionOptions", "focusTrap", "defaultFocus", "breakpoints", "visible", "position"], outputs: ["onHide"] }] });
499
+ ConfirmDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: ConfirmDialogComponent, selector: "confirm-dialog", inputs: { header: "header", message: "message" }, outputs: { result: "result" }, providers: [ConfirmationService], ngImport: i0, template: "<div class=\"card flex justify-center gap-2 view-pass-details confirmtion-modal\">\r\n <p-confirmDialog icon=\"none\" acceptIcon=\"\" rejectIcon=\"\"></p-confirmDialog>\r\n</div>\r\n", styles: [""], dependencies: [{ kind: "component", type: i2.ConfirmDialog, selector: "p-confirmDialog", inputs: ["header", "icon", "message", "style", "styleClass", "maskStyleClass", "acceptIcon", "acceptLabel", "acceptAriaLabel", "acceptVisible", "rejectIcon", "rejectLabel", "rejectAriaLabel", "rejectVisible", "acceptButtonStyleClass", "rejectButtonStyleClass", "closeOnEscape", "dismissableMask", "blockScroll", "rtl", "closable", "appendTo", "key", "autoZIndex", "baseZIndex", "transitionOptions", "focusTrap", "defaultFocus", "breakpoints", "visible", "position"], outputs: ["onHide"] }] });
488
500
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ConfirmDialogComponent, decorators: [{
489
501
  type: Component,
490
- args: [{ selector: 'confirm-dialog', providers: [ConfirmationService], template: "<div class=\"card flex justify-center gap-2 view-pass-details confirmtion-modal\">\n <p-confirmDialog icon=\"none\" acceptIcon=\"\" rejectIcon=\"\"></p-confirmDialog>\n</div>\n" }]
502
+ args: [{ selector: 'confirm-dialog', providers: [ConfirmationService], template: "<div class=\"card flex justify-center gap-2 view-pass-details confirmtion-modal\">\r\n <p-confirmDialog icon=\"none\" acceptIcon=\"\" rejectIcon=\"\"></p-confirmDialog>\r\n</div>\r\n" }]
491
503
  }], ctorParameters: function () { return [{ type: i9.ConfirmationService }]; }, propDecorators: { header: [{
492
504
  type: Input,
493
505
  args: ['header']
@@ -2535,54 +2547,60 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2535
2547
  }], ctorParameters: function () { return [{ type: CommonHeaderLibService }, { type: i2$1.FormBuilder }, { type: ToastMsgService }, { type: EncrydecryRSAdataService }, { type: RESTLoginFormService }, { type: ASYNCPasswordcheckService }, { type: i4.TranslateService }, { type: VaptValidationService }, { type: i1$3.DynamicDialogConfig }, { type: HttpCommonService }, { type: HttpGeneralConfigurationService }]; } });
2536
2548
 
2537
2549
  class NgTranslationComponent {
2538
- constructor(_translate, _localstorage, cookieService) {
2550
+ constructor(_translate, _localstorage, msgService) {
2539
2551
  this._translate = _translate;
2540
2552
  this._localstorage = _localstorage;
2541
- this.cookieService = cookieService;
2542
- // @Output('langChange') langChange = new EventEmitter<any>();
2543
- this.languages = GlobalConstants.USERLANGUAGES;
2553
+ this.msgService = msgService;
2554
+ this.languages = [];
2544
2555
  this.selectedLang = {};
2545
2556
  }
2546
2557
  ngOnInit() {
2547
- this.setDefaultLanguage();
2548
- }
2549
- setDefaultLanguage() {
2550
- // 1. Check if user has selected a language before
2551
- const saved = this._localstorage.getData(COOKIECONSTANT.USERLANG);
2552
- if (saved) {
2558
+ this.loadLanguages();
2559
+ }
2560
+ loadLanguages() {
2561
+ /* 1. Load filtered languages */
2562
+ this.languages = GlobalConstants.USERFILTEREDLANGUAGES || [];
2563
+ /* 2. Read saved language */
2564
+ const savedLang = this._localstorage.getData(COOKIECONSTANT.USERLANG);
2565
+ if (savedLang) {
2553
2566
  try {
2554
- this.selectedLang = JSON.parse(saved);
2567
+ const parsed = JSON.parse(savedLang);
2568
+ const validLang = this.languages.find((x) => x.langKey === parsed?.langKey);
2569
+ this.selectedLang = validLang || GlobalConstants.DEFAULTLANG;
2555
2570
  }
2556
- catch (e) {
2557
- // If corrupted JSON, fallback to default
2571
+ catch {
2558
2572
  this.selectedLang = GlobalConstants.DEFAULTLANG;
2559
- this.saveUserLanguage(this.selectedLang);
2560
2573
  }
2561
2574
  }
2562
2575
  else {
2563
- // 2. First time → set default
2564
2576
  this.selectedLang = GlobalConstants.DEFAULTLANG;
2565
- this.saveUserLanguage(this.selectedLang);
2566
2577
  }
2567
- // 3. Apply language
2568
- this._translate.use(this.selectedLang.langKey);
2569
2578
  }
2570
- //* On Language Changes
2579
+ /* Language Change */
2571
2580
  selectLang(event) {
2572
2581
  this.selectedLang = event?.value;
2573
- this._translate.use(this.selectedLang['langKey']);
2574
- this.saveUserLanguage(this.selectedLang);
2582
+ this.useTranslate(this.selectedLang);
2583
+ }
2584
+ useTranslate(selectedLang) {
2585
+ this._translate.use(selectedLang.langKey).subscribe({
2586
+ next: () => {
2587
+ this.saveUserLanguage(selectedLang);
2588
+ },
2589
+ error: () => {
2590
+ this.msgService.error(this._translate.instant('Generic_lib.FailedToLoadLanguageFile'));
2591
+ },
2592
+ });
2575
2593
  }
2576
2594
  saveUserLanguage(lang) {
2577
2595
  this._localstorage.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(lang));
2578
2596
  }
2579
2597
  }
2580
- NgTranslationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgTranslationComponent, deps: [{ token: i4.TranslateService }, { token: StorageService }, { token: i1$1.CookieService }], target: i0.ɵɵFactoryTarget.Component });
2598
+ NgTranslationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgTranslationComponent, deps: [{ token: i4.TranslateService }, { token: StorageService }, { token: ToastMsgService }], target: i0.ɵɵFactoryTarget.Component });
2581
2599
  NgTranslationComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: NgTranslationComponent, selector: "ng-translation", ngImport: i0, template: "<p-dropdown [options]=\"languages\" optionLabel=\"langName\" placeholder='{{ \"Generic_lib.SelectLanguage\" | translate }}'\r\n (onChange)=\"selectLang($event)\" [filter]=\"true\" filterBy=\"langName\"\r\n filterPlaceholder='{{ \"Generic_lib.Search\" | translate }}' [showClear]=\"false\"\r\n [(ngModel)]=\"selectedLang\"></p-dropdown>\r\n", styles: [""], dependencies: [{ kind: "directive", type: i2$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "component", type: i8.Dropdown, selector: "p-dropdown", inputs: ["scrollHeight", "filter", "name", "style", "panelStyle", "styleClass", "panelStyleClass", "readonly", "required", "editable", "appendTo", "tabindex", "placeholder", "filterPlaceholder", "filterLocale", "inputId", "selectId", "dataKey", "filterBy", "autofocus", "resetFilterOnHide", "dropdownIcon", "optionLabel", "optionValue", "optionDisabled", "optionGroupLabel", "optionGroupChildren", "autoDisplayFirst", "group", "showClear", "emptyFilterMessage", "emptyMessage", "lazy", "virtualScroll", "virtualScrollItemSize", "virtualScrollOptions", "overlayOptions", "ariaFilterLabel", "ariaLabel", "ariaLabelledBy", "filterMatchMode", "maxlength", "tooltip", "tooltipPosition", "tooltipPositionStyle", "tooltipStyleClass", "autofocusFilter", "overlayDirection", "disabled", "itemSize", "autoZIndex", "baseZIndex", "showTransitionOptions", "hideTransitionOptions", "options", "filterValue"], outputs: ["onChange", "onFilter", "onFocus", "onBlur", "onClick", "onShow", "onHide", "onClear", "onLazyLoad"] }, { kind: "directive", type: i2$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "pipe", type: i4.TranslatePipe, name: "translate" }] });
2582
2600
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgTranslationComponent, decorators: [{
2583
2601
  type: Component,
2584
- args: [{ selector: 'ng-translation', template: "<p-dropdown [options]=\"languages\" optionLabel=\"langName\" placeholder='{{ \"Generic_lib.SelectLanguage\" | translate }}'\r\n (onChange)=\"selectLang($event)\" [filter]=\"true\" filterBy=\"langName\"\r\n filterPlaceholder='{{ \"Generic_lib.Search\" | translate }}' [showClear]=\"false\"\r\n [(ngModel)]=\"selectedLang\"></p-dropdown>\r\n" }]
2585
- }], ctorParameters: function () { return [{ type: i4.TranslateService }, { type: StorageService }, { type: i1$1.CookieService }]; } });
2602
+ args: [{ selector: 'ng-translation', standalone: false, template: "<p-dropdown [options]=\"languages\" optionLabel=\"langName\" placeholder='{{ \"Generic_lib.SelectLanguage\" | translate }}'\r\n (onChange)=\"selectLang($event)\" [filter]=\"true\" filterBy=\"langName\"\r\n filterPlaceholder='{{ \"Generic_lib.Search\" | translate }}' [showClear]=\"false\"\r\n [(ngModel)]=\"selectedLang\"></p-dropdown>\r\n" }]
2603
+ }], ctorParameters: function () { return [{ type: i4.TranslateService }, { type: StorageService }, { type: ToastMsgService }]; } });
2586
2604
 
2587
2605
  class SliceToTwoPipe {
2588
2606
  transform(textName) {
@@ -3959,7 +3977,7 @@ CommonHeaderLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", v
3959
3977
  {
3960
3978
  provide: APP_INITIALIZER,
3961
3979
  useFactory: initTranslateService,
3962
- deps: [TranslateService, StorageService],
3980
+ deps: [TranslateService, StorageService, HttpClient, ToastMsgService],
3963
3981
  multi: true,
3964
3982
  },
3965
3983
  ], imports: [CommonModule,
@@ -4046,41 +4064,177 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
4046
4064
  {
4047
4065
  provide: APP_INITIALIZER,
4048
4066
  useFactory: initTranslateService,
4049
- deps: [TranslateService, StorageService],
4067
+ deps: [TranslateService, StorageService, HttpClient, ToastMsgService],
4050
4068
  multi: true,
4051
4069
  },
4052
4070
  ],
4053
4071
  }]
4054
4072
  }] });
4055
- function initTranslateService(translate, localStorageService) {
4056
- return () => {
4057
- const supportedLangs = GlobalConstants.USERLANGUAGES;
4058
- const defaultLang = GlobalConstants.DEFAULTLANG;
4059
- let selectedLang = defaultLang;
4060
- /* 1. Read from localStorage */
4073
+ // Single source of truth for the i18n asset path. Used by every translation
4074
+ // HTTP call and by the TranslateHttpLoader factory below.
4075
+ const I18N_BASE_PATH = 'assets/common-header-lib/i18n/';
4076
+ const LANGUAGES_CONFIG_URL = `${I18N_BASE_PATH}languages.json`;
4077
+ /**
4078
+ * Loads a language JSON file, applies it to TranslateService, and persists
4079
+ * the selected language to local storage. Returns true on success, false on
4080
+ * any failure (network error, missing file, etc.) — callers decide whether to
4081
+ * fall through to the next fallback.
4082
+ *
4083
+ * Centralizes the load → setTranslation → setDefaultLang → use → saveData
4084
+ * sequence so each fallback step in initTranslateService stays a single call.
4085
+ */
4086
+ async function loadAndApplyLanguage(lang, http, translate, storage) {
4087
+ try {
4088
+ const translations = await firstValueFrom(http.get(`${I18N_BASE_PATH}${lang.langKey}.json`));
4089
+ translate.setTranslation(lang.langKey, translations);
4090
+ translate.setDefaultLang(lang.langKey);
4091
+ await firstValueFrom(translate.use(lang.langKey));
4092
+ storage.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(lang));
4093
+ return true;
4094
+ }
4095
+ catch {
4096
+ return false;
4097
+ }
4098
+ }
4099
+ /**
4100
+ * Initializes ngx-translate language configuration during application startup.
4101
+ *
4102
+ * Flow:
4103
+ * 1. Load and validate supported languages from:
4104
+ * assets/common-header-lib/i18n/languages.json
4105
+ *
4106
+ * 2. Build USERFILTEREDLANGUAGES using the exact order defined in languages.json:
4107
+ * - removes duplicate langKeys
4108
+ * - ignores unsupported language codes safely
4109
+ *
4110
+ * 3. Read USERLANG from localStorage:
4111
+ * COOKIECONSTANT.USERLANG
4112
+ *
4113
+ * 4. If USERLANG:
4114
+ * - exists in supported languages
4115
+ * - and translation JSON loads successfully
4116
+ * → initialize application using USERLANG
4117
+ *
4118
+ * 5. If USERLANG is invalid or translation loading fails:
4119
+ * → fallback to first language from USERFILTEREDLANGUAGES
4120
+ * (preserving languages.json order)
4121
+ *
4122
+ * 6. If first fallback language also fails:
4123
+ * → fallback to GlobalConstants.DEFAULTLANG
4124
+ *
4125
+ * 7. If DEFAULTLANG translation also fails:
4126
+ * → initialize empty translations safely
4127
+ * → prevent application bootstrap crash
4128
+ *
4129
+ * Example:
4130
+ * languages.json = ["it", "ja", "ko"]
4131
+ * localStorage USERLANG = { langKey: "vi" }
4132
+ *
4133
+ * Result:
4134
+ * - "vi" ignored because unsupported
4135
+ * - tries "it.json"
4136
+ * - if "it.json" fails → loads DEFAULTLANG ("en")
4137
+ *
4138
+ * Notes:
4139
+ * - languages.json controls supported language order and priority
4140
+ * - translation files are validated before translate.use(...)
4141
+ * - invalid localStorage data is ignored safely
4142
+ * - application startup is protected against translation failures
4143
+ */
4144
+ function initTranslateService(translate, localStorageService, http, msgService) {
4145
+ return async () => {
4146
+ // ---------------------------------------------------------------------
4147
+ // Step 1: Load and validate languages.json (the supported-language list)
4148
+ // ---------------------------------------------------------------------
4149
+ try {
4150
+ const codes = await firstValueFrom(http.get(LANGUAGES_CONFIG_URL));
4151
+ // Reject anything that is not a non-empty array of non-empty strings.
4152
+ if (!codes ||
4153
+ !Array.isArray(codes) ||
4154
+ codes.length === 0 ||
4155
+ !codes.every((code) => typeof code === 'string' && code.trim().length > 0)) {
4156
+ GlobalConstants.USERFILTEREDLANGUAGES = [GlobalConstants.DEFAULTLANG];
4157
+ msgService.error('Invalid or empty languages configuration.', 'Error');
4158
+ }
4159
+ else {
4160
+ // Build filtered list in the exact order defined by languages.json.
4161
+ // Dedupe by langKey and silently drop unsupported codes.
4162
+ const seenKeys = new Set();
4163
+ const ordered = [];
4164
+ for (const raw of codes) {
4165
+ const key = raw.trim();
4166
+ if (seenKeys.has(key))
4167
+ continue;
4168
+ const match = GlobalConstants.USERLANGUAGES.find((lang) => lang.langKey === key);
4169
+ if (match) {
4170
+ seenKeys.add(key);
4171
+ ordered.push(match);
4172
+ }
4173
+ }
4174
+ // If none of the codes matched supported languages, fall back to default.
4175
+ GlobalConstants.USERFILTEREDLANGUAGES =
4176
+ ordered.length > 0 ? ordered : [GlobalConstants.DEFAULTLANG];
4177
+ }
4178
+ }
4179
+ catch {
4180
+ // languages.json failed to load — fall back to default supported list.
4181
+ GlobalConstants.USERFILTEREDLANGUAGES = [GlobalConstants.DEFAULTLANG];
4182
+ msgService.error('Failed to load languages configuration.', 'Error');
4183
+ }
4184
+ // ---------------------------------------------------------------------
4185
+ // Step 2: Read USERLANG from storage and validate against supported list
4186
+ // ---------------------------------------------------------------------
4061
4187
  const saved = localStorageService.getData(COOKIECONSTANT.USERLANG);
4188
+ let userLang = null;
4062
4189
  if (saved) {
4063
4190
  try {
4064
4191
  const parsed = JSON.parse(saved);
4065
- const isValid = supportedLangs.some((lang) => lang.langKey === parsed?.langKey);
4066
- if (isValid) {
4067
- selectedLang = parsed;
4192
+ // Only accept saved language if it is still in the supported list.
4193
+ if (GlobalConstants.USERFILTEREDLANGUAGES.some((lang) => lang.langKey === parsed?.langKey)) {
4194
+ userLang = parsed;
4068
4195
  }
4069
4196
  }
4070
4197
  catch {
4071
- // corrupted JSON → fallback to default
4072
- selectedLang = defaultLang;
4198
+ // Saved data is corrupt JSON — ignore and fall through to defaults.
4073
4199
  }
4074
4200
  }
4075
- /* 2. Persist corrected value */
4076
- localStorageService.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(selectedLang));
4077
- /* 3. Apply language */
4078
- translate.setDefaultLang(selectedLang.langKey);
4079
- return translate.use(selectedLang.langKey).subscribe();
4201
+ // ---------------------------------------------------------------------
4202
+ // Step 3: Attempt to apply USERLANG (highest priority)
4203
+ // ---------------------------------------------------------------------
4204
+ if (userLang) {
4205
+ const ok = await loadAndApplyLanguage(userLang, http, translate, localStorageService);
4206
+ if (ok)
4207
+ return; // Success — bootstrap complete.
4208
+ msgService.error(`Failed to load language file for ${userLang.langName}.`, 'Error');
4209
+ }
4210
+ // ---------------------------------------------------------------------
4211
+ // Step 4: Fallback 1 — first language from languages.json order
4212
+ // ---------------------------------------------------------------------
4213
+ const firstLang = GlobalConstants.USERFILTEREDLANGUAGES[0];
4214
+ if (firstLang) {
4215
+ const ok = await loadAndApplyLanguage(firstLang, http, translate, localStorageService);
4216
+ if (ok)
4217
+ return; // Success — bootstrap complete.
4218
+ msgService.error(`Failed to load language file for ${firstLang.langName}.`, 'Error');
4219
+ }
4220
+ // ---------------------------------------------------------------------
4221
+ // Step 5: Final fallback — DEFAULTLANG
4222
+ // ---------------------------------------------------------------------
4223
+ const defaultOk = await loadAndApplyLanguage(GlobalConstants.DEFAULTLANG, http, translate, localStorageService);
4224
+ if (defaultOk)
4225
+ return;
4226
+ // ---------------------------------------------------------------------
4227
+ // Step 6: Critical failure — initialize empty translations so the
4228
+ // application can still bootstrap without crashing.
4229
+ // ---------------------------------------------------------------------
4230
+ msgService.error('Critical: Failed to load default language file. Initializing with empty translations.', 'Error');
4231
+ translate.setDefaultLang(GlobalConstants.DEFAULTLANG.langKey);
4232
+ translate.setTranslation(GlobalConstants.DEFAULTLANG.langKey, {});
4233
+ localStorageService.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(GlobalConstants.DEFAULTLANG));
4080
4234
  };
4081
4235
  }
4082
4236
  function createLibTranslateLoader(http) {
4083
- return new TranslateHttpLoader(http, 'assets/common-header-lib/i18n/', '.json');
4237
+ return new TranslateHttpLoader(http, I18N_BASE_PATH, '.json');
4084
4238
  }
4085
4239
 
4086
4240
  /*