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.
- package/README.md +24 -24
- package/assets/i18n/ar.json +1 -2
- package/assets/i18n/de.json +1 -2
- package/assets/i18n/en.json +2 -2
- package/assets/i18n/es.json +1 -2
- package/assets/i18n/fr.json +1 -2
- package/assets/i18n/hi.json +1 -2
- package/assets/i18n/ja.json +1 -2
- package/assets/i18n/ko.json +1 -2
- package/assets/images/toast-alert.svg +3 -3
- package/assets/images/toast-error.svg +3 -3
- package/assets/images/toast-info.svg +3 -3
- package/assets/images/toast-success.svg +10 -10
- package/assets/scss/styles.scss +577 -577
- package/esm2020/lib/common-header-lib.component.mjs +7 -1
- package/esm2020/lib/common-header-lib.module.mjs +20 -158
- package/esm2020/lib/common-header-lib.service.mjs +1 -1
- package/esm2020/lib/components/confirm-dialog/confirm-dialog.component.mjs +3 -3
- package/esm2020/lib/components/ng-translation/ng-translation.component.mjs +27 -33
- package/esm2020/lib/model/data_model.mjs +5 -17
- package/esm2020/lib/services/http/http-common.service.mjs +1 -1
- package/esm2020/public-api.mjs +1 -1
- package/fesm2015/common-header-lib.mjs +58 -208
- package/fesm2015/common-header-lib.mjs.map +1 -1
- package/fesm2020/common-header-lib.mjs +56 -204
- package/fesm2020/common-header-lib.mjs.map +1 -1
- package/lib/common-header-lib.module.d.ts +1 -47
- package/lib/components/ng-translation/ng-translation.component.d.ts +8 -6
- package/lib/model/data_model.d.ts +0 -1
- package/package.json +1 -1
- package/src/assets/i18n/ar.json +1 -2
- package/src/assets/i18n/de.json +1 -2
- package/src/assets/i18n/en.json +2 -2
- package/src/assets/i18n/es.json +1 -2
- package/src/assets/i18n/fr.json +1 -2
- package/src/assets/i18n/hi.json +1 -2
- package/src/assets/i18n/ja.json +1 -2
- package/src/assets/i18n/ko.json +1 -2
- package/src/assets/images/toast-alert.svg +3 -3
- package/src/assets/images/toast-error.svg +3 -3
- package/src/assets/images/toast-info.svg +3 -3
- package/src/assets/images/toast-success.svg +10 -10
- package/src/assets/scss/styles.scss +577 -577
|
@@ -3,7 +3,7 @@ import { Injectable, EventEmitter, Component, Output, Pipe, Input, 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
|
|
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 { __awaiter } from 'tslib';
|
|
8
8
|
import * as i10$1 from 'primeng/overlaypanel';
|
|
9
9
|
import { OverlayPanel, OverlayPanelModule } from 'primeng/overlaypanel';
|
|
@@ -67,26 +67,14 @@ GlobalConstants.PAGEROW = 10;
|
|
|
67
67
|
GlobalConstants.CONFIGCONNECTORS = false;
|
|
68
68
|
GlobalConstants.USERLANGUAGES = [
|
|
69
69
|
{ langKey: 'en', langName: 'English' },
|
|
70
|
-
{ langKey: 'hi', langName: 'हिन्दी' },
|
|
71
|
-
{ langKey: 'mr', langName: 'मराठी' },
|
|
72
70
|
{ langKey: 'ar', langName: 'العربية' },
|
|
73
|
-
{ langKey: 'fr', langName: 'Français' },
|
|
74
71
|
{ langKey: 'es', langName: 'Español' },
|
|
72
|
+
{ langKey: 'hi', langName: 'हिन्दी' },
|
|
73
|
+
{ langKey: 'ja', langName: '日本' },
|
|
74
|
+
{ langKey: 'fr', langName: 'Français' },
|
|
75
75
|
{ langKey: 'de', langName: 'Deutsch' },
|
|
76
|
-
{ langKey: '
|
|
77
|
-
{ langKey: 'ko', langName: '한국어' },
|
|
78
|
-
{ langKey: 'zh', langName: '中文' },
|
|
79
|
-
{ langKey: 'ru', langName: 'Русский' },
|
|
80
|
-
{ langKey: 'pt', langName: 'Português' },
|
|
81
|
-
{ langKey: 'it', langName: 'Italiano' },
|
|
82
|
-
{ langKey: 'nl', langName: 'Nederlands' },
|
|
83
|
-
{ langKey: 'tr', langName: 'Türkçe' },
|
|
84
|
-
{ langKey: 'sv', langName: 'Svenska' },
|
|
85
|
-
{ langKey: 'pl', langName: 'Polski' },
|
|
86
|
-
{ langKey: 'th', langName: 'ไทย' },
|
|
87
|
-
{ langKey: 'vi', langName: 'Tiếng Việt' },
|
|
76
|
+
{ langKey: 'ko', langName: '한국인' },
|
|
88
77
|
];
|
|
89
|
-
GlobalConstants.USERFILTEREDLANGUAGES = [];
|
|
90
78
|
GlobalConstants.DEFAULTLANG = { langKey: 'en', langName: 'English' };
|
|
91
79
|
GlobalConstants.DEFAULTLANGKEY = 'en';
|
|
92
80
|
GlobalConstants.DEFAULT_IMGPATH = 'assets/images/';
|
|
@@ -2516,60 +2504,54 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
|
|
|
2516
2504
|
}], ctorParameters: function () { return [{ type: CommonHeaderLibService }, { type: i2.FormBuilder }, { type: ToastMsgService }, { type: EncrydecryRSAdataService }, { type: RESTLoginFormService }, { type: ASYNCPasswordcheckService }, { type: i4.TranslateService }, { type: VaptValidationService }, { type: i1$3.DynamicDialogConfig }, { type: HttpCommonService }, { type: HttpGeneralConfigurationService }]; } });
|
|
2517
2505
|
|
|
2518
2506
|
class NgTranslationComponent {
|
|
2519
|
-
constructor(_translate, _localstorage,
|
|
2507
|
+
constructor(_translate, _localstorage, cookieService) {
|
|
2520
2508
|
this._translate = _translate;
|
|
2521
2509
|
this._localstorage = _localstorage;
|
|
2522
|
-
this.
|
|
2523
|
-
|
|
2510
|
+
this.cookieService = cookieService;
|
|
2511
|
+
// @Output('langChange') langChange = new EventEmitter<any>();
|
|
2512
|
+
this.languages = GlobalConstants.USERLANGUAGES;
|
|
2524
2513
|
this.selectedLang = {};
|
|
2525
2514
|
}
|
|
2526
2515
|
ngOnInit() {
|
|
2527
|
-
this.
|
|
2528
|
-
}
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
const savedLang = this._localstorage.getData(COOKIECONSTANT.USERLANG);
|
|
2534
|
-
if (savedLang) {
|
|
2516
|
+
this.setDefaultLanguage();
|
|
2517
|
+
}
|
|
2518
|
+
setDefaultLanguage() {
|
|
2519
|
+
// 1. Check if user has selected a language before
|
|
2520
|
+
const saved = this._localstorage.getData(COOKIECONSTANT.USERLANG);
|
|
2521
|
+
if (saved) {
|
|
2535
2522
|
try {
|
|
2536
|
-
|
|
2537
|
-
const validLang = this.languages.find((x) => x.langKey === (parsed === null || parsed === void 0 ? void 0 : parsed.langKey));
|
|
2538
|
-
this.selectedLang = validLang || GlobalConstants.DEFAULTLANG;
|
|
2523
|
+
this.selectedLang = JSON.parse(saved);
|
|
2539
2524
|
}
|
|
2540
|
-
catch (
|
|
2525
|
+
catch (e) {
|
|
2526
|
+
// If corrupted JSON, fallback to default
|
|
2541
2527
|
this.selectedLang = GlobalConstants.DEFAULTLANG;
|
|
2528
|
+
this.saveUserLanguage(this.selectedLang);
|
|
2542
2529
|
}
|
|
2543
2530
|
}
|
|
2544
2531
|
else {
|
|
2532
|
+
// 2. First time → set default
|
|
2545
2533
|
this.selectedLang = GlobalConstants.DEFAULTLANG;
|
|
2534
|
+
this.saveUserLanguage(this.selectedLang);
|
|
2546
2535
|
}
|
|
2536
|
+
// 3. Apply language
|
|
2537
|
+
this._translate.use(this.selectedLang.langKey);
|
|
2547
2538
|
}
|
|
2548
|
-
|
|
2539
|
+
//* On Language Changes
|
|
2549
2540
|
selectLang(event) {
|
|
2550
2541
|
this.selectedLang = event === null || event === void 0 ? void 0 : event.value;
|
|
2551
|
-
this.
|
|
2552
|
-
|
|
2553
|
-
useTranslate(selectedLang) {
|
|
2554
|
-
this._translate.use(selectedLang.langKey).subscribe({
|
|
2555
|
-
next: () => {
|
|
2556
|
-
this.saveUserLanguage(selectedLang);
|
|
2557
|
-
},
|
|
2558
|
-
error: () => {
|
|
2559
|
-
this.msgService.error(this._translate.instant('Generic_lib.FailedToLoadLanguageFile'));
|
|
2560
|
-
},
|
|
2561
|
-
});
|
|
2542
|
+
this._translate.use(this.selectedLang['langKey']);
|
|
2543
|
+
this.saveUserLanguage(this.selectedLang);
|
|
2562
2544
|
}
|
|
2563
2545
|
saveUserLanguage(lang) {
|
|
2564
2546
|
this._localstorage.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(lang));
|
|
2565
2547
|
}
|
|
2566
2548
|
}
|
|
2567
|
-
NgTranslationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgTranslationComponent, deps: [{ token: i4.TranslateService }, { token: StorageService }, { token:
|
|
2549
|
+
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 });
|
|
2568
2550
|
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.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.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "pipe", type: i4.TranslatePipe, name: "translate" }] });
|
|
2569
2551
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NgTranslationComponent, decorators: [{
|
|
2570
2552
|
type: Component,
|
|
2571
|
-
args: [{ selector: 'ng-translation',
|
|
2572
|
-
}], ctorParameters: function () { return [{ type: i4.TranslateService }, { type: StorageService }, { type:
|
|
2553
|
+
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" }]
|
|
2554
|
+
}], ctorParameters: function () { return [{ type: i4.TranslateService }, { type: StorageService }, { type: i1$1.CookieService }]; } });
|
|
2573
2555
|
|
|
2574
2556
|
class SliceToTwoPipe {
|
|
2575
2557
|
transform(textName) {
|
|
@@ -3339,10 +3321,10 @@ class ConfirmDialogComponent {
|
|
|
3339
3321
|
}
|
|
3340
3322
|
}
|
|
3341
3323
|
ConfirmDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ConfirmDialogComponent, deps: [{ token: i9.ConfirmationService }], target: i0.ɵɵFactoryTarget.Component });
|
|
3342
|
-
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\">\
|
|
3324
|
+
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$1.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"] }] });
|
|
3343
3325
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ConfirmDialogComponent, decorators: [{
|
|
3344
3326
|
type: Component,
|
|
3345
|
-
args: [{ selector: 'confirm-dialog', providers: [ConfirmationService], template: "<div class=\"card flex justify-center gap-2 view-pass-details confirmtion-modal\">\
|
|
3327
|
+
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" }]
|
|
3346
3328
|
}], ctorParameters: function () { return [{ type: i9.ConfirmationService }]; }, propDecorators: { header: [{
|
|
3347
3329
|
type: Input,
|
|
3348
3330
|
args: ['header']
|
|
@@ -3439,8 +3421,11 @@ class CommonHeaderLibComponent {
|
|
|
3439
3421
|
this.setWebAPIURL();
|
|
3440
3422
|
}
|
|
3441
3423
|
ngOnChanges(changes) {
|
|
3424
|
+
console.log('changes:', changes);
|
|
3442
3425
|
if (changes['EnableLOB']) {
|
|
3426
|
+
console.log('changes[EnableLOB]:', changes['EnableLOB']);
|
|
3443
3427
|
if (changes['EnableLOB'].currentValue === true) {
|
|
3428
|
+
console.log('EnableLOB changed to true as currentVaule is true');
|
|
3444
3429
|
this.getListofLOB();
|
|
3445
3430
|
}
|
|
3446
3431
|
}
|
|
@@ -3739,8 +3724,10 @@ class CommonHeaderLibComponent {
|
|
|
3739
3724
|
//* get Lob AI call and initial LOB emitter
|
|
3740
3725
|
getListofLOB() {
|
|
3741
3726
|
this.showLobLoader = true;
|
|
3727
|
+
console.log('Before calling Lobs API');
|
|
3742
3728
|
this.httpCommonService.getLOBList().subscribe((res) => {
|
|
3743
3729
|
var _a, _b, _c;
|
|
3730
|
+
console.log('API Lob Data:', res);
|
|
3744
3731
|
this.showLobLoader = false;
|
|
3745
3732
|
this.userLOBList = res.result;
|
|
3746
3733
|
//* As per parent input, here we add All LOB option in DDL
|
|
@@ -3766,6 +3753,7 @@ class CommonHeaderLibComponent {
|
|
|
3766
3753
|
this.tempSelectedLOBId = (_c = this.userLOBList[0]) === null || _c === void 0 ? void 0 : _c.lobId;
|
|
3767
3754
|
localStorage.setItem('XOB', JSON.stringify(initialLobSelected));
|
|
3768
3755
|
}
|
|
3756
|
+
console.log('Lob Emitted:', initialLobSelected);
|
|
3769
3757
|
this.lobSelected.emit(initialLobSelected);
|
|
3770
3758
|
this.cdRef.detectChanges();
|
|
3771
3759
|
});
|
|
@@ -3996,7 +3984,7 @@ CommonHeaderLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", v
|
|
|
3996
3984
|
{
|
|
3997
3985
|
provide: APP_INITIALIZER,
|
|
3998
3986
|
useFactory: initTranslateService,
|
|
3999
|
-
deps: [TranslateService, StorageService
|
|
3987
|
+
deps: [TranslateService, StorageService],
|
|
4000
3988
|
multi: true,
|
|
4001
3989
|
},
|
|
4002
3990
|
], imports: [CommonModule,
|
|
@@ -4083,179 +4071,41 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
|
|
|
4083
4071
|
{
|
|
4084
4072
|
provide: APP_INITIALIZER,
|
|
4085
4073
|
useFactory: initTranslateService,
|
|
4086
|
-
deps: [TranslateService, StorageService
|
|
4074
|
+
deps: [TranslateService, StorageService],
|
|
4087
4075
|
multi: true,
|
|
4088
4076
|
},
|
|
4089
4077
|
],
|
|
4090
4078
|
}]
|
|
4091
4079
|
}] });
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
const
|
|
4095
|
-
const
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
* the selected language to local storage. Returns true on success, false on
|
|
4099
|
-
* any failure (network error, missing file, etc.) — callers decide whether to
|
|
4100
|
-
* fall through to the next fallback.
|
|
4101
|
-
*
|
|
4102
|
-
* Centralizes the load → setTranslation → setDefaultLang → use → saveData
|
|
4103
|
-
* sequence so each fallback step in initTranslateService stays a single call.
|
|
4104
|
-
*/
|
|
4105
|
-
function loadAndApplyLanguage(lang, http, translate, storage) {
|
|
4106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4107
|
-
try {
|
|
4108
|
-
const translations = yield firstValueFrom(http.get(`${I18N_BASE_PATH}${lang.langKey}.json`));
|
|
4109
|
-
translate.setTranslation(lang.langKey, translations);
|
|
4110
|
-
translate.setDefaultLang(lang.langKey);
|
|
4111
|
-
yield firstValueFrom(translate.use(lang.langKey));
|
|
4112
|
-
storage.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(lang));
|
|
4113
|
-
return true;
|
|
4114
|
-
}
|
|
4115
|
-
catch (_a) {
|
|
4116
|
-
return false;
|
|
4117
|
-
}
|
|
4118
|
-
});
|
|
4119
|
-
}
|
|
4120
|
-
/**
|
|
4121
|
-
* Initializes ngx-translate language configuration during application startup.
|
|
4122
|
-
*
|
|
4123
|
-
* Flow:
|
|
4124
|
-
* 1. Load and validate supported languages from:
|
|
4125
|
-
* assets/common-header-lib/i18n/languages.json
|
|
4126
|
-
*
|
|
4127
|
-
* 2. Build USERFILTEREDLANGUAGES using the exact order defined in languages.json:
|
|
4128
|
-
* - removes duplicate langKeys
|
|
4129
|
-
* - ignores unsupported language codes safely
|
|
4130
|
-
*
|
|
4131
|
-
* 3. Read USERLANG from localStorage:
|
|
4132
|
-
* COOKIECONSTANT.USERLANG
|
|
4133
|
-
*
|
|
4134
|
-
* 4. If USERLANG:
|
|
4135
|
-
* - exists in supported languages
|
|
4136
|
-
* - and translation JSON loads successfully
|
|
4137
|
-
* → initialize application using USERLANG
|
|
4138
|
-
*
|
|
4139
|
-
* 5. If USERLANG is invalid or translation loading fails:
|
|
4140
|
-
* → fallback to first language from USERFILTEREDLANGUAGES
|
|
4141
|
-
* (preserving languages.json order)
|
|
4142
|
-
*
|
|
4143
|
-
* 6. If first fallback language also fails:
|
|
4144
|
-
* → fallback to GlobalConstants.DEFAULTLANG
|
|
4145
|
-
*
|
|
4146
|
-
* 7. If DEFAULTLANG translation also fails:
|
|
4147
|
-
* → initialize empty translations safely
|
|
4148
|
-
* → prevent application bootstrap crash
|
|
4149
|
-
*
|
|
4150
|
-
* Example:
|
|
4151
|
-
* languages.json = ["it", "ja", "ko"]
|
|
4152
|
-
* localStorage USERLANG = { langKey: "vi" }
|
|
4153
|
-
*
|
|
4154
|
-
* Result:
|
|
4155
|
-
* - "vi" ignored because unsupported
|
|
4156
|
-
* - tries "it.json"
|
|
4157
|
-
* - if "it.json" fails → loads DEFAULTLANG ("en")
|
|
4158
|
-
*
|
|
4159
|
-
* Notes:
|
|
4160
|
-
* - languages.json controls supported language order and priority
|
|
4161
|
-
* - translation files are validated before translate.use(...)
|
|
4162
|
-
* - invalid localStorage data is ignored safely
|
|
4163
|
-
* - application startup is protected against translation failures
|
|
4164
|
-
*/
|
|
4165
|
-
function initTranslateService(translate, localStorageService, http, msgService) {
|
|
4166
|
-
return () => __awaiter(this, void 0, void 0, function* () {
|
|
4167
|
-
// ---------------------------------------------------------------------
|
|
4168
|
-
// Step 1: Load and validate languages.json (the supported-language list)
|
|
4169
|
-
// ---------------------------------------------------------------------
|
|
4170
|
-
try {
|
|
4171
|
-
const codes = yield firstValueFrom(http.get(LANGUAGES_CONFIG_URL));
|
|
4172
|
-
// Reject anything that is not a non-empty array of non-empty strings.
|
|
4173
|
-
if (!codes ||
|
|
4174
|
-
!Array.isArray(codes) ||
|
|
4175
|
-
codes.length === 0 ||
|
|
4176
|
-
!codes.every((code) => typeof code === 'string' && code.trim().length > 0)) {
|
|
4177
|
-
GlobalConstants.USERFILTEREDLANGUAGES = [GlobalConstants.DEFAULTLANG];
|
|
4178
|
-
msgService.error('Invalid or empty languages configuration.', 'Error');
|
|
4179
|
-
}
|
|
4180
|
-
else {
|
|
4181
|
-
// Build filtered list in the exact order defined by languages.json.
|
|
4182
|
-
// Dedupe by langKey and silently drop unsupported codes.
|
|
4183
|
-
const seenKeys = new Set();
|
|
4184
|
-
const ordered = [];
|
|
4185
|
-
for (const raw of codes) {
|
|
4186
|
-
const key = raw.trim();
|
|
4187
|
-
if (seenKeys.has(key))
|
|
4188
|
-
continue;
|
|
4189
|
-
const match = GlobalConstants.USERLANGUAGES.find((lang) => lang.langKey === key);
|
|
4190
|
-
if (match) {
|
|
4191
|
-
seenKeys.add(key);
|
|
4192
|
-
ordered.push(match);
|
|
4193
|
-
}
|
|
4194
|
-
}
|
|
4195
|
-
// If none of the codes matched supported languages, fall back to default.
|
|
4196
|
-
GlobalConstants.USERFILTEREDLANGUAGES =
|
|
4197
|
-
ordered.length > 0 ? ordered : [GlobalConstants.DEFAULTLANG];
|
|
4198
|
-
}
|
|
4199
|
-
}
|
|
4200
|
-
catch (_a) {
|
|
4201
|
-
// languages.json failed to load — fall back to default supported list.
|
|
4202
|
-
GlobalConstants.USERFILTEREDLANGUAGES = [GlobalConstants.DEFAULTLANG];
|
|
4203
|
-
msgService.error('Failed to load languages configuration.', 'Error');
|
|
4204
|
-
}
|
|
4205
|
-
// ---------------------------------------------------------------------
|
|
4206
|
-
// Step 2: Read USERLANG from storage and validate against supported list
|
|
4207
|
-
// ---------------------------------------------------------------------
|
|
4080
|
+
function initTranslateService(translate, localStorageService) {
|
|
4081
|
+
return () => {
|
|
4082
|
+
const supportedLangs = GlobalConstants.USERLANGUAGES;
|
|
4083
|
+
const defaultLang = GlobalConstants.DEFAULTLANG;
|
|
4084
|
+
let selectedLang = defaultLang;
|
|
4085
|
+
/* 1. Read from localStorage */
|
|
4208
4086
|
const saved = localStorageService.getData(COOKIECONSTANT.USERLANG);
|
|
4209
|
-
let userLang = null;
|
|
4210
4087
|
if (saved) {
|
|
4211
4088
|
try {
|
|
4212
4089
|
const parsed = JSON.parse(saved);
|
|
4213
|
-
|
|
4214
|
-
if (
|
|
4215
|
-
|
|
4090
|
+
const isValid = supportedLangs.some((lang) => lang.langKey === (parsed === null || parsed === void 0 ? void 0 : parsed.langKey));
|
|
4091
|
+
if (isValid) {
|
|
4092
|
+
selectedLang = parsed;
|
|
4216
4093
|
}
|
|
4217
4094
|
}
|
|
4218
|
-
catch (
|
|
4219
|
-
//
|
|
4095
|
+
catch (_a) {
|
|
4096
|
+
// corrupted JSON → fallback to default
|
|
4097
|
+
selectedLang = defaultLang;
|
|
4220
4098
|
}
|
|
4221
4099
|
}
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
return; // Success — bootstrap complete.
|
|
4229
|
-
msgService.error(`Failed to load language file for ${userLang.langName}.`, 'Error');
|
|
4230
|
-
}
|
|
4231
|
-
// ---------------------------------------------------------------------
|
|
4232
|
-
// Step 4: Fallback 1 — first language from languages.json order
|
|
4233
|
-
// ---------------------------------------------------------------------
|
|
4234
|
-
const firstLang = GlobalConstants.USERFILTEREDLANGUAGES[0];
|
|
4235
|
-
if (firstLang) {
|
|
4236
|
-
const ok = yield loadAndApplyLanguage(firstLang, http, translate, localStorageService);
|
|
4237
|
-
if (ok)
|
|
4238
|
-
return; // Success — bootstrap complete.
|
|
4239
|
-
msgService.error(`Failed to load language file for ${firstLang.langName}.`, 'Error');
|
|
4240
|
-
}
|
|
4241
|
-
// ---------------------------------------------------------------------
|
|
4242
|
-
// Step 5: Final fallback — DEFAULTLANG
|
|
4243
|
-
// ---------------------------------------------------------------------
|
|
4244
|
-
const defaultOk = yield loadAndApplyLanguage(GlobalConstants.DEFAULTLANG, http, translate, localStorageService);
|
|
4245
|
-
if (defaultOk)
|
|
4246
|
-
return;
|
|
4247
|
-
// ---------------------------------------------------------------------
|
|
4248
|
-
// Step 6: Critical failure — initialize empty translations so the
|
|
4249
|
-
// application can still bootstrap without crashing.
|
|
4250
|
-
// ---------------------------------------------------------------------
|
|
4251
|
-
msgService.error('Critical: Failed to load default language file. Initializing with empty translations.', 'Error');
|
|
4252
|
-
translate.setDefaultLang(GlobalConstants.DEFAULTLANG.langKey);
|
|
4253
|
-
translate.setTranslation(GlobalConstants.DEFAULTLANG.langKey, {});
|
|
4254
|
-
localStorageService.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(GlobalConstants.DEFAULTLANG));
|
|
4255
|
-
});
|
|
4100
|
+
/* 2. Persist corrected value */
|
|
4101
|
+
localStorageService.saveData(COOKIECONSTANT.USERLANG, JSON.stringify(selectedLang));
|
|
4102
|
+
/* 3. Apply language */
|
|
4103
|
+
translate.setDefaultLang(selectedLang.langKey);
|
|
4104
|
+
return translate.use(selectedLang.langKey).subscribe();
|
|
4105
|
+
};
|
|
4256
4106
|
}
|
|
4257
4107
|
function createLibTranslateLoader(http) {
|
|
4258
|
-
return new TranslateHttpLoader(http,
|
|
4108
|
+
return new TranslateHttpLoader(http, 'assets/common-header-lib/i18n/', '.json');
|
|
4259
4109
|
}
|
|
4260
4110
|
|
|
4261
4111
|
/*
|