common-header-lib 0.0.17 → 0.5.15

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 (43) hide show
  1. package/README.md +24 -24
  2. package/assets/i18n/ar.json +1 -2
  3. package/assets/i18n/de.json +1 -2
  4. package/assets/i18n/en.json +2 -2
  5. package/assets/i18n/es.json +1 -2
  6. package/assets/i18n/fr.json +1 -2
  7. package/assets/i18n/hi.json +1 -2
  8. package/assets/i18n/ja.json +1 -2
  9. package/assets/i18n/ko.json +1 -2
  10. package/assets/images/toast-alert.svg +3 -3
  11. package/assets/images/toast-error.svg +3 -3
  12. package/assets/images/toast-info.svg +3 -3
  13. package/assets/images/toast-success.svg +10 -10
  14. package/assets/scss/styles.scss +577 -577
  15. package/esm2020/lib/common-header-lib.component.mjs +7 -1
  16. package/esm2020/lib/common-header-lib.module.mjs +20 -158
  17. package/esm2020/lib/common-header-lib.service.mjs +1 -1
  18. package/esm2020/lib/components/confirm-dialog/confirm-dialog.component.mjs +3 -3
  19. package/esm2020/lib/components/ng-translation/ng-translation.component.mjs +27 -33
  20. package/esm2020/lib/model/data_model.mjs +5 -17
  21. package/esm2020/lib/services/http/http-common.service.mjs +1 -1
  22. package/esm2020/public-api.mjs +1 -1
  23. package/fesm2015/common-header-lib.mjs +58 -208
  24. package/fesm2015/common-header-lib.mjs.map +1 -1
  25. package/fesm2020/common-header-lib.mjs +56 -204
  26. package/fesm2020/common-header-lib.mjs.map +1 -1
  27. package/lib/common-header-lib.module.d.ts +1 -47
  28. package/lib/components/ng-translation/ng-translation.component.d.ts +8 -6
  29. package/lib/model/data_model.d.ts +0 -1
  30. package/package.json +1 -1
  31. package/src/assets/i18n/ar.json +1 -2
  32. package/src/assets/i18n/de.json +1 -2
  33. package/src/assets/i18n/en.json +2 -2
  34. package/src/assets/i18n/es.json +1 -2
  35. package/src/assets/i18n/fr.json +1 -2
  36. package/src/assets/i18n/hi.json +1 -2
  37. package/src/assets/i18n/ja.json +1 -2
  38. package/src/assets/i18n/ko.json +1 -2
  39. package/src/assets/images/toast-alert.svg +3 -3
  40. package/src/assets/images/toast-error.svg +3 -3
  41. package/src/assets/images/toast-info.svg +3 -3
  42. package/src/assets/images/toast-success.svg +10 -10
  43. 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, firstValueFrom } 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 } 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,26 +66,14 @@ GlobalConstants.PAGEROW = 10;
66
66
  GlobalConstants.CONFIGCONNECTORS = false;
67
67
  GlobalConstants.USERLANGUAGES = [
68
68
  { langKey: 'en', langName: 'English' },
69
- { langKey: 'hi', langName: 'हिन्दी' },
70
- { langKey: 'mr', langName: 'मराठी' },
71
69
  { langKey: 'ar', langName: 'العربية' },
72
- { langKey: 'fr', langName: 'Français' },
73
70
  { langKey: 'es', langName: 'Español' },
71
+ { langKey: 'hi', langName: 'हिन्दी' },
72
+ { langKey: 'ja', langName: '日本' },
73
+ { langKey: 'fr', langName: 'Français' },
74
74
  { langKey: 'de', langName: 'Deutsch' },
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' },
75
+ { langKey: 'ko', langName: '한국인' },
87
76
  ];
88
- GlobalConstants.USERFILTEREDLANGUAGES = [];
89
77
  GlobalConstants.DEFAULTLANG = { langKey: 'en', langName: 'English' };
90
78
  GlobalConstants.DEFAULTLANGKEY = 'en';
91
79
  GlobalConstants.DEFAULT_IMGPATH = 'assets/images/';
@@ -496,10 +484,10 @@ class ConfirmDialogComponent {
496
484
  }
497
485
  }
498
486
  ConfirmDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ConfirmDialogComponent, deps: [{ token: i9.ConfirmationService }], target: i0.ɵɵFactoryTarget.Component });
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"] }] });
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"] }] });
500
488
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ConfirmDialogComponent, decorators: [{
501
489
  type: Component,
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" }]
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" }]
503
491
  }], ctorParameters: function () { return [{ type: i9.ConfirmationService }]; }, propDecorators: { header: [{
504
492
  type: Input,
505
493
  args: ['header']
@@ -2547,60 +2535,54 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2547
2535
  }], 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 }]; } });
2548
2536
 
2549
2537
  class NgTranslationComponent {
2550
- constructor(_translate, _localstorage, msgService) {
2538
+ constructor(_translate, _localstorage, cookieService) {
2551
2539
  this._translate = _translate;
2552
2540
  this._localstorage = _localstorage;
2553
- this.msgService = msgService;
2554
- this.languages = [];
2541
+ this.cookieService = cookieService;
2542
+ // @Output('langChange') langChange = new EventEmitter<any>();
2543
+ this.languages = GlobalConstants.USERLANGUAGES;
2555
2544
  this.selectedLang = {};
2556
2545
  }
2557
2546
  ngOnInit() {
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) {
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) {
2566
2553
  try {
2567
- const parsed = JSON.parse(savedLang);
2568
- const validLang = this.languages.find((x) => x.langKey === parsed?.langKey);
2569
- this.selectedLang = validLang || GlobalConstants.DEFAULTLANG;
2554
+ this.selectedLang = JSON.parse(saved);
2570
2555
  }
2571
- catch {
2556
+ catch (e) {
2557
+ // If corrupted JSON, fallback to default
2572
2558
  this.selectedLang = GlobalConstants.DEFAULTLANG;
2559
+ this.saveUserLanguage(this.selectedLang);
2573
2560
  }
2574
2561
  }
2575
2562
  else {
2563
+ // 2. First time → set default
2576
2564
  this.selectedLang = GlobalConstants.DEFAULTLANG;
2565
+ this.saveUserLanguage(this.selectedLang);
2577
2566
  }
2567
+ // 3. Apply language
2568
+ this._translate.use(this.selectedLang.langKey);
2578
2569
  }
2579
- /* Language Change */
2570
+ //* On Language Changes
2580
2571
  selectLang(event) {
2581
2572
  this.selectedLang = event?.value;
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
- });
2573
+ this._translate.use(this.selectedLang['langKey']);
2574
+ this.saveUserLanguage(this.selectedLang);
2593
2575
  }
2594
2576
  saveUserLanguage(lang) {
2595
2577
  this._localstorage.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(lang));
2596
2578
  }
2597
2579
  }
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 });
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 });
2599
2581
  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" }] });
2600
2582
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgTranslationComponent, decorators: [{
2601
2583
  type: Component,
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 }]; } });
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 }]; } });
2604
2586
 
2605
2587
  class SliceToTwoPipe {
2606
2588
  transform(textName) {
@@ -3425,8 +3407,11 @@ class CommonHeaderLibComponent {
3425
3407
  this.setWebAPIURL();
3426
3408
  }
3427
3409
  ngOnChanges(changes) {
3410
+ console.log('changes:', changes);
3428
3411
  if (changes['EnableLOB']) {
3412
+ console.log('changes[EnableLOB]:', changes['EnableLOB']);
3429
3413
  if (changes['EnableLOB'].currentValue === true) {
3414
+ console.log('EnableLOB changed to true as currentVaule is true');
3430
3415
  this.getListofLOB();
3431
3416
  }
3432
3417
  }
@@ -3721,7 +3706,9 @@ class CommonHeaderLibComponent {
3721
3706
  //* get Lob AI call and initial LOB emitter
3722
3707
  getListofLOB() {
3723
3708
  this.showLobLoader = true;
3709
+ console.log('Before calling Lobs API');
3724
3710
  this.httpCommonService.getLOBList().subscribe((res) => {
3711
+ console.log('API Lob Data:', res);
3725
3712
  this.showLobLoader = false;
3726
3713
  this.userLOBList = res.result;
3727
3714
  //* As per parent input, here we add All LOB option in DDL
@@ -3747,6 +3734,7 @@ class CommonHeaderLibComponent {
3747
3734
  this.tempSelectedLOBId = this.userLOBList[0]?.lobId;
3748
3735
  localStorage.setItem('XOB', JSON.stringify(initialLobSelected));
3749
3736
  }
3737
+ console.log('Lob Emitted:', initialLobSelected);
3750
3738
  this.lobSelected.emit(initialLobSelected);
3751
3739
  this.cdRef.detectChanges();
3752
3740
  });
@@ -3977,7 +3965,7 @@ CommonHeaderLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", v
3977
3965
  {
3978
3966
  provide: APP_INITIALIZER,
3979
3967
  useFactory: initTranslateService,
3980
- deps: [TranslateService, StorageService, HttpClient, ToastMsgService],
3968
+ deps: [TranslateService, StorageService],
3981
3969
  multi: true,
3982
3970
  },
3983
3971
  ], imports: [CommonModule,
@@ -4064,177 +4052,41 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
4064
4052
  {
4065
4053
  provide: APP_INITIALIZER,
4066
4054
  useFactory: initTranslateService,
4067
- deps: [TranslateService, StorageService, HttpClient, ToastMsgService],
4055
+ deps: [TranslateService, StorageService],
4068
4056
  multi: true,
4069
4057
  },
4070
4058
  ],
4071
4059
  }]
4072
4060
  }] });
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
+ function initTranslateService(translate, localStorageService) {
4062
+ return () => {
4063
+ const supportedLangs = GlobalConstants.USERLANGUAGES;
4064
+ const defaultLang = GlobalConstants.DEFAULTLANG;
4065
+ let selectedLang = defaultLang;
4066
+ /* 1. Read from localStorage */
4187
4067
  const saved = localStorageService.getData(COOKIECONSTANT.USERLANG);
4188
- let userLang = null;
4189
4068
  if (saved) {
4190
4069
  try {
4191
4070
  const parsed = JSON.parse(saved);
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;
4071
+ const isValid = supportedLangs.some((lang) => lang.langKey === parsed?.langKey);
4072
+ if (isValid) {
4073
+ selectedLang = parsed;
4195
4074
  }
4196
4075
  }
4197
4076
  catch {
4198
- // Saved data is corrupt JSON — ignore and fall through to defaults.
4077
+ // corrupted JSON → fallback to default
4078
+ selectedLang = defaultLang;
4199
4079
  }
4200
4080
  }
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));
4081
+ /* 2. Persist corrected value */
4082
+ localStorageService.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(selectedLang));
4083
+ /* 3. Apply language */
4084
+ translate.setDefaultLang(selectedLang.langKey);
4085
+ return translate.use(selectedLang.langKey).subscribe();
4234
4086
  };
4235
4087
  }
4236
4088
  function createLibTranslateLoader(http) {
4237
- return new TranslateHttpLoader(http, I18N_BASE_PATH, '.json');
4089
+ return new TranslateHttpLoader(http, 'assets/common-header-lib/i18n/', '.json');
4238
4090
  }
4239
4091
 
4240
4092
  /*