@sixbell-telco/sdk 1.6.0 → 2.1.0
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/CHANGELOG.md +260 -711
- package/README.md +337 -278
- package/_index.css +3 -3
- package/components/accordion/accordion-item/accordion-item.component.d.ts +3 -4
- package/components/audio-player/audio-timeline/audio-timeline.component.d.ts +29 -2
- package/components/audio-player/services/audio.service.d.ts +14 -14
- package/components/audio-player/src/audio-player.component.d.ts +7 -3
- package/components/audio-player/volume-control/volume-control.component.d.ts +28 -1
- package/components/button/src/button.component.d.ts +46 -1
- package/components/countdown/src/countdown.component.d.ts +1 -1
- package/components/data-table/data-table-empty-actions/data-table-empty-actions.component.d.ts +5 -0
- package/components/data-table/public-api.d.ts +1 -0
- package/components/data-table/src/data-table.component.d.ts +11 -3
- package/components/dialog/src/dialog.component.d.ts +51 -5
- package/components/dropdown/dropdown-content/dropdown-content.component.d.ts +2 -1
- package/components/dropdown/dropdown-item/dropdown-item.component.d.ts +37 -1
- package/components/dropdown/dropdown-item-checkbox/dropdown-item-checkbox.component.d.ts +33 -1
- package/components/dropdown/dropdown-item-radio/dropdown-item-radio.component.d.ts +33 -1
- package/components/dropdown/dropdown-trigger/dropdown-trigger.component.d.ts +53 -2
- package/components/dropdown/src/dropdown.component.d.ts +2 -2
- package/components/dropdown-menu/bar/dropdown-menu-bar-content/dropdown-menu-bar-content.component.d.ts +2 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-item/dropdown-menu-bar-item.component.d.ts +33 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-checkbox/dropdown-menu-bar-item-checkbox.component.d.ts +33 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-radio/dropdown-menu-bar-item-radio.component.d.ts +33 -1
- package/components/dropdown-menu/src/directives/dropdown-menu.directive.d.ts +1 -3
- package/components/dropdown-menu/src/dropdown-menu-content/dropdown-menu-content.component.d.ts +4 -4
- package/components/dropdown-menu/src/dropdown-menu-item/dropdown-menu-item.component.d.ts +33 -1
- package/components/dropdown-menu/src/dropdown-menu-sub-content/dropdown-menu-sub-content.component.d.ts +2 -1
- package/components/dual-list/src/dual-list.component.d.ts +4 -2
- package/components/file-upload/file-dropzone/file-dropzone.component.d.ts +53 -8
- package/components/file-upload/file-uploader/file-uploader.component.d.ts +40 -9
- package/components/forms/checkbox/src/checkbox.component.d.ts +46 -2
- package/components/forms/combobox/src/combobox.component.d.ts +40 -5
- package/components/forms/date-picker/src/date-picker.component.d.ts +11 -1
- package/components/forms/form-group/README.md +114 -0
- package/components/forms/form-group/index.d.ts +5 -0
- package/components/forms/form-group/public-api.d.ts +1 -0
- package/components/forms/form-group/src/form-group.component.d.ts +150 -0
- package/components/forms/form-item/README.md +17 -0
- package/components/forms/form-item/index.d.ts +5 -0
- package/components/forms/form-item/public-api.d.ts +1 -0
- package/components/forms/form-item/src/form-item.component.d.ts +5 -0
- package/components/forms/input/src/input.component.d.ts +45 -2
- package/components/forms/radio/src/radio.component.d.ts +46 -2
- package/components/forms/range/src/range.component.d.ts +38 -1
- package/components/forms/select/src/select.component.d.ts +40 -5
- package/components/forms/switch/src/switch.component.d.ts +46 -2
- package/components/forms/textarea/src/textarea.component.d.ts +62 -12
- package/components/forms/toggle/src/toggle.component.d.ts +46 -1
- package/components/link/src/link.component.d.ts +0 -3
- package/components/overlay/overlay-content/overlay-content.component.d.ts +2 -1
- package/components/overlay/overlay-trigger/overlay-trigger.component.d.ts +37 -5
- package/components/overlay/src/overlay.component.d.ts +4 -5
- package/components/paginator/components/pagination-item/pagination-item.component.d.ts +37 -1
- package/components/tab/directives/tab-content/tab-content.directive.d.ts +5 -6
- package/components/tab/directives/tab-header/tab-header.directive.d.ts +2 -2
- package/components/table/public-api.d.ts +1 -0
- package/components/table/src/table.component.d.ts +36 -4
- package/components/table/table-empty-actions/table-empty-actions.component.d.ts +5 -0
- package/components/table/table-header-checkbox/table-header-checkbox.component.d.ts +5 -11
- package/components/table/table-row-checkbox/table-row-checkbox.component.d.ts +5 -11
- package/components/toast/toast-message/toast-message.component.d.ts +42 -1
- package/components/tooltip/src/tooltip.component.d.ts +10 -1
- package/components/wizard/services/wizard.service.d.ts +5 -5
- package/components/wizard/wizard-marker/wizard-marker.component.d.ts +2 -3
- package/directives/auto-focus/public-api.d.ts +1 -1
- package/directives/auto-focus/src/{autofocus.directive.d.ts → auto-focus.directive.d.ts} +9 -15
- package/directives/click-outside/src/click-outside.directive.d.ts +1 -3
- package/directives/only-numbers/public-api.d.ts +6 -1
- package/directives/only-numbers/src/only-numbers.directive.d.ts +36 -0
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs +6 -9
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs +133 -51
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-button.mjs +78 -4
- package/fesm2022/sixbell-telco-sdk-components-button.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-countdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs +53 -27
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs +82 -12
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs +166 -13
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs +68 -24
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +283 -16
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs +12 -9
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs +151 -10
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs +69 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs +96 -19
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs +15 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-form-group.mjs +159 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-group.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs +20 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs +62 -6
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs +69 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs +57 -4
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs +91 -20
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs +80 -6
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs +131 -13
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs +69 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-link.mjs +2 -7
- package/fesm2022/sixbell-telco-sdk-components-link.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs +94 -42
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs +71 -10
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs +5 -9
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-table.mjs +131 -47
- package/fesm2022/sixbell-telco-sdk-components-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-toast.mjs +69 -4
- package/fesm2022/sixbell-telco-sdk-components-toast.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs +15 -3
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs +29 -49
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-click-outside.mjs +7 -10
- package/fesm2022/sixbell-telco-sdk-directives-click-outside.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs +48 -17
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-pipes-to-bytes-extesion.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-pipes-to-bytes-extesion.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-runtime-config.mjs +339 -0
- package/fesm2022/sixbell-telco-sdk-utils-runtime-config.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-utils-sync.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-sync.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs +1062 -730
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs +350 -267
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs.map +1 -1
- package/package.json +55 -46
- package/utils/runtime-config/README.md +235 -0
- package/utils/{resource-loader → runtime-config}/index.d.ts +1 -1
- package/utils/runtime-config/public-api.d.ts +5 -0
- package/utils/runtime-config/src/http-client.d.ts +11 -0
- package/utils/runtime-config/src/runtime-config-loader.d.ts +23 -0
- package/utils/runtime-config/src/runtime-config-store.d.ts +11 -0
- package/utils/runtime-config/src/runtime-update-adapter.d.ts +15 -0
- package/utils/runtime-config/src/types.d.ts +66 -0
- package/utils/theme/README.md +324 -986
- package/utils/theme/public-api.d.ts +4 -4
- package/utils/theme/src/constants.d.ts +6 -12
- package/utils/theme/src/models/theme.d.ts +46 -173
- package/utils/theme/src/providers/theme.provider.d.ts +0 -10
- package/utils/theme/src/providers/theme.provider.types.d.ts +16 -15
- package/utils/theme/src/theme-assets/theme-assets.service.d.ts +16 -12
- package/utils/theme/src/theme-dom/theme-dom.service.d.ts +10 -3
- package/utils/theme/src/theme.service.d.ts +24 -27
- package/utils/theme/src/utils/utils.d.ts +2 -10
- package/utils/translation/README.md +170 -1390
- package/utils/translation/public-api.d.ts +3 -3
- package/utils/translation/src/constants.d.ts +7 -9
- package/utils/translation/src/models/translation.d.ts +9 -10
- package/utils/translation/src/providers/translation.provider.d.ts +17 -28
- package/utils/translation/src/providers/translation.provider.types.d.ts +13 -6
- package/utils/translation/src/translation-dom/translation-dom.service.d.ts +2 -3
- package/utils/translation/src/translation.service.d.ts +37 -9
- package/directives/only-numbers/src/just-numbers.directive.d.ts +0 -9
- package/fesm2022/sixbell-telco-sdk-utils-resource-loader.mjs +0 -1222
- package/fesm2022/sixbell-telco-sdk-utils-resource-loader.mjs.map +0 -1
- package/utils/resource-loader/README.md +0 -460
- package/utils/resource-loader/public-api.d.ts +0 -1
- package/utils/resource-loader/src/cache/index.d.ts +0 -2
- package/utils/resource-loader/src/cache/layers/factory.d.ts +0 -38
- package/utils/resource-loader/src/cache/layers/index.d.ts +0 -3
- package/utils/resource-loader/src/cache/layers/indexed-db-cache.d.ts +0 -118
- package/utils/resource-loader/src/cache/layers/local-storage-cache.d.ts +0 -86
- package/utils/resource-loader/src/cache/layers/memory-cache.d.ts +0 -76
- package/utils/resource-loader/src/cache/types.d.ts +0 -107
- package/utils/resource-loader/src/config/index.d.ts +0 -1
- package/utils/resource-loader/src/config/load-config.d.ts +0 -32
- package/utils/resource-loader/src/constants.d.ts +0 -38
- package/utils/resource-loader/src/http/index.d.ts +0 -1
- package/utils/resource-loader/src/http/retryable-client.d.ts +0 -43
- package/utils/resource-loader/src/index.d.ts +0 -1
- package/utils/resource-loader/src/resource-loader.d.ts +0 -67
- package/utils/resource-loader/src/types.d.ts +0 -152
- package/utils/resource-loader/src/utils/cache-validator.d.ts +0 -72
- package/utils/resource-loader/src/utils/helpers.d.ts +0 -15
- package/utils/resource-loader/src/utils/index.d.ts +0 -2
- package/utils/theme/src/providers/constants.d.ts +0 -7
- package/utils/translation/src/providers/constants.d.ts +0 -11
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { TranslateService, provideTranslateService, MissingTranslationHandler, TranslateLoader } from '@ngx-translate/core';
|
|
2
|
+
import { inject, RendererFactory2, Injectable, DestroyRef, signal, computed, Injector, runInInjectionContext, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
|
|
3
|
+
import { TranslateService, provideTranslateService, provideMissingTranslationHandler, provideTranslateLoader } from '@ngx-translate/core';
|
|
5
4
|
export * from '@ngx-translate/core';
|
|
6
5
|
import { LoggerService } from '@sixbell-telco/sdk/utils/logger';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { RuntimeHttpClient, RuntimeConfigStore, RuntimeConfigLoader, RuntimeUpdateAdapter } from '@sixbell-telco/sdk/utils/runtime-config';
|
|
7
|
+
import { firstValueFrom, from } from 'rxjs';
|
|
9
8
|
import { DOCUMENT } from '@angular/common';
|
|
10
|
-
import { Router, NavigationEnd } from '@angular/router';
|
|
11
9
|
export * from '@ngx-translate/http-loader';
|
|
12
10
|
export * from 'ngx-translate-multi-http-loader';
|
|
13
11
|
|
|
@@ -44,35 +42,31 @@ const DEFAULT_TRANSLATION_PATHS = ['/assets/i18n/'];
|
|
|
44
42
|
* HTML attribute name for setting the active language on document element
|
|
45
43
|
*/
|
|
46
44
|
const LANGUAGE_ATTRIBUTE_NAME = 'lang';
|
|
47
|
-
/**
|
|
48
|
-
* Injection token for translation configuration
|
|
49
|
-
* Used to provide static translation configuration at bootstrap
|
|
50
|
-
*/
|
|
51
|
-
const TRANSLATION_CONFIG_TOKEN = new InjectionToken('Translation Configuration');
|
|
52
45
|
/**
|
|
53
46
|
* Translation-specific IndexedDB database name for resource caching
|
|
54
47
|
*/
|
|
55
48
|
const TRANSLATION_INDEXED_DB_NAME = 'sixbell-translation';
|
|
49
|
+
/**
|
|
50
|
+
* Schema version for runtime translation configuration payloads.
|
|
51
|
+
* Bump this when the JSON structure changes in a breaking way.
|
|
52
|
+
*/
|
|
53
|
+
const TRANSLATION_SCHEMA_VERSION = '2';
|
|
56
54
|
const DEFAULT_LANGUAGES = [
|
|
57
55
|
{ code: 'en', name: 'English' },
|
|
58
56
|
{ code: 'es', name: 'Español' },
|
|
59
57
|
{ code: 'pt', name: 'Português' },
|
|
60
58
|
];
|
|
61
59
|
const DEFAULT_LANGUAGE_CODE = 'en';
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
retryDelayMs: 400,
|
|
73
|
-
timeoutMs: 6000,
|
|
74
|
-
seedCacheWithFallback: true,
|
|
75
|
-
logErrors: true,
|
|
60
|
+
const FALLBACK_RUNTIME_TRANSLATION_CONFIG = {
|
|
61
|
+
meta: {
|
|
62
|
+
version: 'fallback',
|
|
63
|
+
updatedAt: new Date().toISOString(),
|
|
64
|
+
hash: 'fallback-hash',
|
|
65
|
+
schemaVersion: TRANSLATION_SCHEMA_VERSION,
|
|
66
|
+
},
|
|
67
|
+
additionalLanguages: [],
|
|
68
|
+
defaultLang: DEFAULT_LANGUAGE_CODE,
|
|
69
|
+
translationPaths: [...DEFAULT_TRANSLATION_PATHS],
|
|
76
70
|
};
|
|
77
71
|
|
|
78
72
|
/**
|
|
@@ -84,12 +78,10 @@ const TRANSLATION_RESOURCE_LOADER_DEFAULTS = {
|
|
|
84
78
|
* Decouples DOM operations from business logic
|
|
85
79
|
*/
|
|
86
80
|
class TranslationDomService {
|
|
87
|
-
rendererFactory;
|
|
88
|
-
document;
|
|
89
81
|
renderer;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
rendererFactory = inject(RendererFactory2);
|
|
83
|
+
document = inject(DOCUMENT);
|
|
84
|
+
constructor() {
|
|
93
85
|
this.renderer = this.rendererFactory.createRenderer(null, null);
|
|
94
86
|
}
|
|
95
87
|
/**
|
|
@@ -118,16 +110,13 @@ class TranslationDomService {
|
|
|
118
110
|
}
|
|
119
111
|
return htmlElement.getAttribute(LANGUAGE_ATTRIBUTE_NAME) || '';
|
|
120
112
|
}
|
|
121
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationDomService, deps: [
|
|
113
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationDomService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
122
114
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationDomService, providedIn: 'root' });
|
|
123
115
|
}
|
|
124
116
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationDomService, decorators: [{
|
|
125
117
|
type: Injectable,
|
|
126
118
|
args: [{ providedIn: 'root' }]
|
|
127
|
-
}], ctorParameters: () => [
|
|
128
|
-
type: Inject,
|
|
129
|
-
args: [DOCUMENT]
|
|
130
|
-
}] }] });
|
|
119
|
+
}], ctorParameters: () => [] });
|
|
131
120
|
|
|
132
121
|
/**
|
|
133
122
|
* Translation Storage Service
|
|
@@ -237,7 +226,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
|
|
|
237
226
|
/**
|
|
238
227
|
* Translation Service
|
|
239
228
|
* Main service for handling language selection, translation loading, and management
|
|
240
|
-
* Mirrors ThemeService - config via DI token +
|
|
229
|
+
* Mirrors ThemeService - config via DI token + multi-path loading
|
|
241
230
|
*/
|
|
242
231
|
function createLanguage(config) {
|
|
243
232
|
return {
|
|
@@ -254,34 +243,39 @@ class PlaceholderMissingTranslationHandler {
|
|
|
254
243
|
}
|
|
255
244
|
}
|
|
256
245
|
class TranslationService {
|
|
257
|
-
translationConfig;
|
|
258
246
|
translate = inject(TranslateService);
|
|
259
247
|
storageService = inject(TranslationStorageService);
|
|
260
248
|
domService = inject(TranslationDomService);
|
|
261
249
|
logger = inject(LoggerService);
|
|
250
|
+
destroyRef = inject(DestroyRef);
|
|
262
251
|
initialized = false;
|
|
263
252
|
currentTranslationPaths = [...DEFAULT_TRANSLATION_PATHS];
|
|
264
|
-
|
|
253
|
+
translationHttpClient = null;
|
|
265
254
|
hasAppliedInitialLanguage = false;
|
|
255
|
+
isUsingFallbackConfig = false;
|
|
256
|
+
prefetchLanguages = true;
|
|
257
|
+
isApplyingRuntimeConfig = false;
|
|
258
|
+
runtimeHash = null;
|
|
259
|
+
runtimeLoader;
|
|
260
|
+
runtimeMeta;
|
|
261
|
+
pendingUpdatedLanguages = new Set();
|
|
262
|
+
bootstrapValidated = false;
|
|
263
|
+
translationTick = signal(0);
|
|
264
|
+
updateAvailable = signal(false);
|
|
265
|
+
lastRefreshFailed = signal(false);
|
|
266
266
|
config = {
|
|
267
267
|
availableLanguages: [...DEFAULT_LANGUAGES],
|
|
268
268
|
defaultLanguage: DEFAULT_LANGUAGE_CODE,
|
|
269
269
|
};
|
|
270
270
|
currentLanguage = signal(DEFAULT_LANGUAGE_CODE);
|
|
271
|
-
onLanguageChange$ = this.translate.onLangChange
|
|
271
|
+
onLanguageChange$ = this.translate.onLangChange;
|
|
272
272
|
onLanguageChange = signal(0);
|
|
273
273
|
ready = signal(false);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (translationConfig) {
|
|
277
|
-
this.configure(translationConfig);
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
this.initializeFromStorage();
|
|
281
|
-
}
|
|
274
|
+
changes = computed(() => this.translationTick());
|
|
275
|
+
constructor() {
|
|
282
276
|
this.currentLanguage.set(this.getCurrentLanguage());
|
|
283
277
|
}
|
|
284
|
-
configure(config
|
|
278
|
+
configure(config) {
|
|
285
279
|
this.logger.debug('configure - starting', {
|
|
286
280
|
component: 'TranslationService',
|
|
287
281
|
action: 'configure',
|
|
@@ -306,7 +300,17 @@ class TranslationService {
|
|
|
306
300
|
action: 'configure',
|
|
307
301
|
newPaths,
|
|
308
302
|
});
|
|
309
|
-
this.
|
|
303
|
+
const targetLang = this.getCurrentLanguage();
|
|
304
|
+
const preloadPromises = this.currentTranslationPaths.map((path) => {
|
|
305
|
+
const normalized = path.endsWith('/') ? path : `${path}/`;
|
|
306
|
+
const url = `${normalized}${targetLang}.json`;
|
|
307
|
+
return this.fetchTranslation(url)
|
|
308
|
+
.then(() => undefined)
|
|
309
|
+
.catch(() => undefined);
|
|
310
|
+
});
|
|
311
|
+
Promise.all(preloadPromises).then(() => {
|
|
312
|
+
this.translate.reloadLang(targetLang);
|
|
313
|
+
});
|
|
310
314
|
}
|
|
311
315
|
this.config = {
|
|
312
316
|
availableLanguages,
|
|
@@ -328,11 +332,14 @@ class TranslationService {
|
|
|
328
332
|
finalDefaultLang: this.config.defaultLanguage,
|
|
329
333
|
availableLangCodes: availableCodes,
|
|
330
334
|
});
|
|
335
|
+
this.resolveStoredLanguage();
|
|
331
336
|
if (this.initialized) {
|
|
332
337
|
// This is a runtime config update (not initial construction)
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
|
|
338
|
+
// Keep current language resolved from storage unless we're doing a fresh init
|
|
339
|
+
if (!this.isApplyingRuntimeConfig) {
|
|
340
|
+
this.currentLanguage.set(this.config.defaultLanguage);
|
|
341
|
+
this.initializeFromStorage();
|
|
342
|
+
}
|
|
336
343
|
// Mark that we've applied the initial language so init() can apply it on next call
|
|
337
344
|
this.hasAppliedInitialLanguage = true;
|
|
338
345
|
}
|
|
@@ -344,35 +351,133 @@ class TranslationService {
|
|
|
344
351
|
// will be deferred until setRuntimeConfig() is called.
|
|
345
352
|
}
|
|
346
353
|
}
|
|
354
|
+
resolveStoredLanguage() {
|
|
355
|
+
const availableCodes = this.config.availableLanguages.map((lang) => lang.code);
|
|
356
|
+
const savedLanguage = this.storageService.getSavedLanguage();
|
|
357
|
+
if (savedLanguage && availableCodes.includes(savedLanguage)) {
|
|
358
|
+
this.currentLanguage.set(savedLanguage);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (savedLanguage && !this.isUsingFallbackConfig) {
|
|
362
|
+
this.storageService.clear();
|
|
363
|
+
}
|
|
364
|
+
this.currentLanguage.set(this.config.defaultLanguage);
|
|
365
|
+
}
|
|
347
366
|
async setRuntimeConfig(config) {
|
|
367
|
+
this.ready.set(false);
|
|
348
368
|
this.logger.debug('setRuntimeConfig - starting', {
|
|
349
369
|
component: 'TranslationService',
|
|
350
370
|
action: 'setRuntimeConfig',
|
|
351
371
|
configPath: config.translationPaths,
|
|
352
372
|
});
|
|
353
373
|
// Update configuration (this will update currentLanguage signal and restore from storage)
|
|
374
|
+
this.isApplyingRuntimeConfig = true;
|
|
354
375
|
this.configure(config);
|
|
355
376
|
// Apply language now that runtime config has loaded
|
|
356
377
|
// This saves to storage with the correct default from config file
|
|
378
|
+
const targetLang = this.currentLanguage();
|
|
379
|
+
await firstValueFrom(this.translate.reloadLang(targetLang));
|
|
357
380
|
this.applyLanguage();
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
currentLanguage: currentLang,
|
|
365
|
-
});
|
|
366
|
-
this.translate.reloadLang(currentLang);
|
|
367
|
-
await this.waitForTranslations();
|
|
381
|
+
await this.loadSelectedLanguage();
|
|
382
|
+
if (this.prefetchLanguages) {
|
|
383
|
+
this.prefetchRemainingLanguages();
|
|
384
|
+
}
|
|
385
|
+
this.isApplyingRuntimeConfig = false;
|
|
386
|
+
this.translationTick.update((value) => value + 1);
|
|
368
387
|
this.logger.debug('setRuntimeConfig - complete', {
|
|
369
388
|
component: 'TranslationService',
|
|
370
389
|
action: 'setRuntimeConfig',
|
|
371
390
|
currentLanguage: this.getCurrentLanguage(),
|
|
372
391
|
});
|
|
373
392
|
}
|
|
393
|
+
enablePrefetch(enable) {
|
|
394
|
+
this.prefetchLanguages = enable;
|
|
395
|
+
}
|
|
396
|
+
async loadSelectedLanguage() {
|
|
397
|
+
const targetLang = this.currentLanguage();
|
|
398
|
+
await this.loadLanguageResources(targetLang);
|
|
399
|
+
}
|
|
400
|
+
prefetchRemainingLanguages() {
|
|
401
|
+
const currentLang = this.currentLanguage();
|
|
402
|
+
const remaining = this.getAvailableLanguagesConfig()
|
|
403
|
+
.map((lang) => lang.code)
|
|
404
|
+
.filter((code) => code !== currentLang);
|
|
405
|
+
for (const lang of remaining) {
|
|
406
|
+
this.loadLanguageResources(lang).catch(() => undefined);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async loadLanguageResources(lang) {
|
|
410
|
+
const loadPromises = this.currentTranslationPaths.map((path) => {
|
|
411
|
+
const normalized = path.endsWith('/') ? path : `${path}/`;
|
|
412
|
+
const url = `${normalized}${lang}.json`;
|
|
413
|
+
return this.fetchTranslation(url);
|
|
414
|
+
});
|
|
415
|
+
await Promise.allSettled(loadPromises);
|
|
416
|
+
}
|
|
417
|
+
queueUpdatedLanguage(lang) {
|
|
418
|
+
if (!lang) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
this.pendingUpdatedLanguages.add(lang);
|
|
422
|
+
}
|
|
423
|
+
async reloadLanguages(languages) {
|
|
424
|
+
const unique = Array.from(new Set(languages)).filter(Boolean);
|
|
425
|
+
if (!unique.length) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const available = new Set(this.getAvailableLanguageCodes());
|
|
429
|
+
await Promise.all(unique.filter((lang) => available.has(lang)).map((lang) => firstValueFrom(this.translate.reloadLang(lang)).catch(() => undefined)));
|
|
430
|
+
}
|
|
431
|
+
async refreshInactiveLanguages() {
|
|
432
|
+
const current = this.currentLanguage();
|
|
433
|
+
const nonActive = this.getAvailableLanguageCodes().filter((lang) => lang !== current);
|
|
434
|
+
await this.reloadLanguages(nonActive);
|
|
435
|
+
}
|
|
436
|
+
async validateBootstrapCache() {
|
|
437
|
+
if (this.bootstrapValidated) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
this.bootstrapValidated = true;
|
|
441
|
+
const runtimeLoader = this.runtimeLoader;
|
|
442
|
+
if (!runtimeLoader || !this.runtimeHash || this.isUsingFallbackConfig) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (this.runtimeMeta?.schemaVersion && this.runtimeMeta.schemaVersion !== TRANSLATION_SCHEMA_VERSION) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
const check = await runtimeLoader.checkForUpdates(this.runtimeHash);
|
|
450
|
+
if (!check.updated) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const result = await runtimeLoader.refresh();
|
|
454
|
+
this.isUsingFallbackConfig = result.source === 'fallback';
|
|
455
|
+
this.runtimeHash = result.hash;
|
|
456
|
+
this.runtimeMeta = result.meta;
|
|
457
|
+
this.updateAvailable.set(false);
|
|
458
|
+
await this.setRuntimeConfig(result.data);
|
|
459
|
+
this.ready.set(true);
|
|
460
|
+
const current = this.currentLanguage();
|
|
461
|
+
await this.reloadLanguages([current]);
|
|
462
|
+
void this.refreshInactiveLanguages();
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
this.logger.warn('Translation bootstrap validation failed', {
|
|
466
|
+
component: 'TranslationService',
|
|
467
|
+
action: 'validateBootstrapCache',
|
|
468
|
+
error: error instanceof Error ? error.message : String(error),
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
374
472
|
initializeFromStorage() {
|
|
375
473
|
try {
|
|
474
|
+
if (this.isApplyingRuntimeConfig) {
|
|
475
|
+
this.logger.debug('Skipping storage restore during runtime config apply', {
|
|
476
|
+
component: 'TranslationService',
|
|
477
|
+
action: 'initializeFromStorage',
|
|
478
|
+
});
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
376
481
|
const saved = this.storageService.getSavedLanguage();
|
|
377
482
|
const availableCodes = this.config.availableLanguages.map((l) => l.code);
|
|
378
483
|
if (saved && availableCodes.includes(saved)) {
|
|
@@ -394,6 +499,7 @@ class TranslationService {
|
|
|
394
499
|
}
|
|
395
500
|
applyLanguage() {
|
|
396
501
|
const targetLang = this.currentLanguage();
|
|
502
|
+
this.translate.setFallbackLang(this.config.defaultLanguage);
|
|
397
503
|
this.translate.use(targetLang);
|
|
398
504
|
this.domService.setDocumentLanguage(targetLang);
|
|
399
505
|
// Always save to storage - keeps state consistent from the start
|
|
@@ -429,7 +535,7 @@ class TranslationService {
|
|
|
429
535
|
return saved && availableCodes.includes(saved) ? saved : this.config.defaultLanguage;
|
|
430
536
|
}
|
|
431
537
|
getAvailableLanguages() {
|
|
432
|
-
return this.translate.getLangs();
|
|
538
|
+
return [...this.translate.getLangs()];
|
|
433
539
|
}
|
|
434
540
|
getDefaultLanguage() {
|
|
435
541
|
return this.config.defaultLanguage;
|
|
@@ -438,15 +544,13 @@ class TranslationService {
|
|
|
438
544
|
const result = params ? this.translate.instant(key, params) : this.translate.instant(key);
|
|
439
545
|
if (result === key) {
|
|
440
546
|
const currentLang = this.getCurrentLanguage();
|
|
441
|
-
const loadedTranslations = this.translate.translations[currentLang] || {};
|
|
442
|
-
const loadedKeys = Object.keys(loadedTranslations);
|
|
443
547
|
this.logger.warn('Translation key not found', {
|
|
444
548
|
component: 'TranslationService',
|
|
445
549
|
action: 'instant',
|
|
446
550
|
key,
|
|
447
551
|
currentLanguage: currentLang,
|
|
448
552
|
hasParams: !!params,
|
|
449
|
-
|
|
553
|
+
availableLanguages: this.translate.getLangs(),
|
|
450
554
|
});
|
|
451
555
|
}
|
|
452
556
|
return result;
|
|
@@ -489,7 +593,7 @@ class TranslationService {
|
|
|
489
593
|
return this.ready.asReadonly();
|
|
490
594
|
}
|
|
491
595
|
async waitForTranslations(timeoutMs = 10000) {
|
|
492
|
-
return new Promise((resolve
|
|
596
|
+
return new Promise((resolve) => {
|
|
493
597
|
if (this.ready()) {
|
|
494
598
|
resolve();
|
|
495
599
|
return;
|
|
@@ -508,7 +612,8 @@ class TranslationService {
|
|
|
508
612
|
timeoutMs,
|
|
509
613
|
isReady: this.ready(),
|
|
510
614
|
});
|
|
511
|
-
|
|
615
|
+
this.ready.set(true);
|
|
616
|
+
resolve();
|
|
512
617
|
}
|
|
513
618
|
}, 50);
|
|
514
619
|
});
|
|
@@ -521,10 +626,11 @@ class TranslationService {
|
|
|
521
626
|
if (this.hasAppliedInitialLanguage) {
|
|
522
627
|
this.applyLanguage();
|
|
523
628
|
}
|
|
524
|
-
this.translate.onLangChange.
|
|
629
|
+
const subscription = this.translate.onLangChange.subscribe({
|
|
525
630
|
next: (event) => {
|
|
526
631
|
this.currentLanguage.set(event.lang);
|
|
527
632
|
this.onLanguageChange.update((val) => val + 1);
|
|
633
|
+
this.translationTick.update((value) => value + 1);
|
|
528
634
|
this.ready.set(true);
|
|
529
635
|
this.logger.debug('Translations ready - language loaded', {
|
|
530
636
|
component: 'TranslationService',
|
|
@@ -541,24 +647,115 @@ class TranslationService {
|
|
|
541
647
|
this.ready.set(true);
|
|
542
648
|
},
|
|
543
649
|
});
|
|
650
|
+
this.destroyRef.onDestroy(() => {
|
|
651
|
+
subscription.unsubscribe();
|
|
652
|
+
});
|
|
544
653
|
}
|
|
545
|
-
|
|
546
|
-
if (
|
|
547
|
-
this.
|
|
654
|
+
async applyRuntimeConfig(result, loader) {
|
|
655
|
+
if (loader) {
|
|
656
|
+
this.runtimeLoader = loader;
|
|
657
|
+
}
|
|
658
|
+
this.isUsingFallbackConfig = result.source === 'fallback';
|
|
659
|
+
this.runtimeHash = result.hash;
|
|
660
|
+
this.runtimeMeta = result.meta;
|
|
661
|
+
this.updateAvailable.set(false);
|
|
662
|
+
await this.setRuntimeConfig(result.data);
|
|
663
|
+
this.ready.set(true);
|
|
664
|
+
if (result.source === 'cache') {
|
|
665
|
+
void this.validateBootstrapCache();
|
|
548
666
|
}
|
|
549
|
-
return this.translationResourceLoader;
|
|
550
667
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
668
|
+
setRuntimeLoader(loader, hash) {
|
|
669
|
+
this.runtimeLoader = loader;
|
|
670
|
+
this.runtimeHash = hash ?? null;
|
|
671
|
+
this.updateAvailable.set(false);
|
|
672
|
+
this.lastRefreshFailed.set(false);
|
|
673
|
+
}
|
|
674
|
+
async checkForTranslationUpdates(loader, event) {
|
|
675
|
+
this.runtimeLoader = loader;
|
|
676
|
+
if (event?.resource && event.resource !== 'translation' && event.resource !== 'both') {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
const eventHash = event?.hash;
|
|
680
|
+
const eventLang = event && 'lang' in event ? event.lang : undefined;
|
|
681
|
+
if (eventHash) {
|
|
682
|
+
if (eventHash === this.runtimeHash) {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
this.queueUpdatedLanguage(eventLang);
|
|
686
|
+
if (!this.updateAvailable()) {
|
|
687
|
+
this.updateAvailable.set(true);
|
|
688
|
+
}
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const currentHash = this.runtimeHash;
|
|
692
|
+
if (currentHash) {
|
|
693
|
+
const check = await loader.checkForUpdates(currentHash);
|
|
694
|
+
if (check.updated && !this.updateAvailable()) {
|
|
695
|
+
this.updateAvailable.set(true);
|
|
696
|
+
}
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (!this.updateAvailable()) {
|
|
700
|
+
this.updateAvailable.set(true);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
async refreshTranslation(loader) {
|
|
704
|
+
const runtimeLoader = loader ?? this.runtimeLoader;
|
|
705
|
+
if (!runtimeLoader) {
|
|
706
|
+
this.logger.warn('Translation refresh requested without runtime loader', {
|
|
707
|
+
component: 'TranslationService',
|
|
708
|
+
action: 'refreshTranslation',
|
|
709
|
+
});
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
try {
|
|
713
|
+
const result = await runtimeLoader.refresh();
|
|
714
|
+
await this.applyRuntimeConfig(result, runtimeLoader);
|
|
715
|
+
const pendingLanguages = Array.from(this.pendingUpdatedLanguages);
|
|
716
|
+
this.pendingUpdatedLanguages.clear();
|
|
717
|
+
const current = this.currentLanguage();
|
|
718
|
+
if (pendingLanguages.length > 0) {
|
|
719
|
+
await this.reloadLanguages(pendingLanguages.filter((lang) => lang !== current));
|
|
720
|
+
}
|
|
721
|
+
this.updateAvailable.set(false);
|
|
722
|
+
this.lastRefreshFailed.set(false);
|
|
723
|
+
}
|
|
724
|
+
catch (error) {
|
|
725
|
+
this.lastRefreshFailed.set(true);
|
|
726
|
+
this.logger.error('Translation refresh failed', error, {
|
|
727
|
+
component: 'TranslationService',
|
|
728
|
+
action: 'refreshTranslation',
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
withTranslationsReady(fn) {
|
|
733
|
+
this.changes();
|
|
734
|
+
if (!this.ready()) {
|
|
735
|
+
return undefined;
|
|
736
|
+
}
|
|
737
|
+
return fn();
|
|
738
|
+
}
|
|
739
|
+
getOrCreateHttpClient() {
|
|
740
|
+
if (!this.translationHttpClient) {
|
|
741
|
+
this.translationHttpClient = new RuntimeHttpClient({
|
|
742
|
+
retries: 2,
|
|
743
|
+
retryDelayMs: 400,
|
|
744
|
+
timeoutMs: 6000,
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
return this.translationHttpClient;
|
|
748
|
+
}
|
|
749
|
+
async fetchTranslation(url) {
|
|
750
|
+
try {
|
|
751
|
+
const response = await this.getOrCreateHttpClient().fetch(url, { cache: 'no-store' });
|
|
752
|
+
return (await response.json());
|
|
753
|
+
}
|
|
754
|
+
catch {
|
|
755
|
+
return {};
|
|
756
|
+
}
|
|
558
757
|
}
|
|
559
758
|
createTranslateLoader() {
|
|
560
|
-
const loader = this.getOrCreateResourceLoader();
|
|
561
|
-
const options = this.buildResourceOptions();
|
|
562
759
|
const suffix = '.json';
|
|
563
760
|
return {
|
|
564
761
|
getTranslation: (lang) => {
|
|
@@ -573,14 +770,11 @@ class TranslationService {
|
|
|
573
770
|
}
|
|
574
771
|
const loadPromises = pathsToUse.map((path) => {
|
|
575
772
|
const url = `${path.endsWith('/') ? path : `${path}/`}${lang}${suffix}`;
|
|
576
|
-
return
|
|
577
|
-
...options,
|
|
578
|
-
cacheKey: `${lang}:${url}`,
|
|
579
|
-
});
|
|
773
|
+
return this.fetchTranslation(url);
|
|
580
774
|
});
|
|
581
775
|
return from(Promise.all(loadPromises).then((results) => {
|
|
582
776
|
const merged = results.reduce((acc, result) => {
|
|
583
|
-
return this.deepMergeTranslations(acc, result
|
|
777
|
+
return this.deepMergeTranslations(acc, result ?? {});
|
|
584
778
|
}, {});
|
|
585
779
|
this.logger.debug('Translations loaded and merged', {
|
|
586
780
|
language: lang,
|
|
@@ -592,18 +786,16 @@ class TranslationService {
|
|
|
592
786
|
},
|
|
593
787
|
};
|
|
594
788
|
}
|
|
789
|
+
isTranslationObject(value) {
|
|
790
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
791
|
+
}
|
|
595
792
|
deepMergeTranslations(target, source) {
|
|
596
793
|
const result = { ...target };
|
|
597
794
|
for (const key in source) {
|
|
598
795
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
599
796
|
const sourceValue = source[key];
|
|
600
797
|
const targetValue = result[key];
|
|
601
|
-
if (
|
|
602
|
-
sourceValue !== null &&
|
|
603
|
-
!Array.isArray(sourceValue) &&
|
|
604
|
-
typeof targetValue === 'object' &&
|
|
605
|
-
targetValue !== null &&
|
|
606
|
-
!Array.isArray(targetValue)) {
|
|
798
|
+
if (this.isTranslationObject(sourceValue) && this.isTranslationObject(targetValue)) {
|
|
607
799
|
result[key] = this.deepMergeTranslations(targetValue, sourceValue);
|
|
608
800
|
}
|
|
609
801
|
else {
|
|
@@ -613,46 +805,13 @@ class TranslationService {
|
|
|
613
805
|
}
|
|
614
806
|
return result;
|
|
615
807
|
}
|
|
616
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, deps: [
|
|
808
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
617
809
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, providedIn: 'root' });
|
|
618
810
|
}
|
|
619
811
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, decorators: [{
|
|
620
812
|
type: Injectable,
|
|
621
813
|
args: [{ providedIn: 'root' }]
|
|
622
|
-
}], ctorParameters: () => [
|
|
623
|
-
type: Optional
|
|
624
|
-
}, {
|
|
625
|
-
type: Inject,
|
|
626
|
-
args: [TRANSLATION_CONFIG_TOKEN]
|
|
627
|
-
}] }] });
|
|
628
|
-
|
|
629
|
-
/**
|
|
630
|
-
* Default resource loader options for runtime translation config files
|
|
631
|
-
* Matches theme's resilient loading pattern
|
|
632
|
-
*/
|
|
633
|
-
const RUNTIME_TRANSLATION_LOADER_DEFAULTS = {
|
|
634
|
-
cacheName: 'translation-runtime-config',
|
|
635
|
-
indexedDBName: TRANSLATION_INDEXED_DB_NAME,
|
|
636
|
-
storageOrder: ['indexedDB', 'memory'],
|
|
637
|
-
cacheTTL: 1000 * 60 * 60 * 24,
|
|
638
|
-
freshOnNavigation: true, // Hot-reload on every navigation by default
|
|
639
|
-
staleWhileRevalidate: true,
|
|
640
|
-
useStaleOnError: true,
|
|
641
|
-
revalidateOnFresh: true,
|
|
642
|
-
retries: 3,
|
|
643
|
-
retryDelayMs: 400,
|
|
644
|
-
timeoutMs: 8000,
|
|
645
|
-
seedCacheWithFallback: true,
|
|
646
|
-
logErrors: true,
|
|
647
|
-
};
|
|
648
|
-
/**
|
|
649
|
-
* Fallback translation config when file loading fails
|
|
650
|
-
*/
|
|
651
|
-
const FALLBACK_RUNTIME_TRANSLATION_CONFIG = {
|
|
652
|
-
additionalLanguages: [],
|
|
653
|
-
defaultLang: 'en',
|
|
654
|
-
translationPaths: ['/assets/i18n/'],
|
|
655
|
-
};
|
|
814
|
+
}], ctorParameters: () => [] });
|
|
656
815
|
|
|
657
816
|
// ============================================================
|
|
658
817
|
// CUSTOM LOADER - Deferred injection pattern
|
|
@@ -667,99 +826,45 @@ const FALLBACK_RUNTIME_TRANSLATION_CONFIG = {
|
|
|
667
826
|
* Key: DO NOT use providedIn: 'root' - let ngx-translate manage the lifecycle.
|
|
668
827
|
*/
|
|
669
828
|
class RuntimeTranslationCustomLoader {
|
|
670
|
-
injector;
|
|
671
|
-
constructor(injector) {
|
|
672
|
-
this.injector = injector;
|
|
673
|
-
}
|
|
829
|
+
injector = inject(Injector);
|
|
674
830
|
getTranslation(lang) {
|
|
675
831
|
// Use runInInjectionContext to safely inject TranslationService
|
|
676
832
|
// even when called outside the normal DI context
|
|
677
833
|
return runInInjectionContext(this.injector, () => {
|
|
678
834
|
const translationService = inject(TranslationService);
|
|
679
|
-
return translationService
|
|
835
|
+
return translationService.createTranslateLoader().getTranslation(lang);
|
|
680
836
|
});
|
|
681
837
|
}
|
|
682
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader, deps: [
|
|
838
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
683
839
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader });
|
|
684
840
|
}
|
|
685
841
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader, decorators: [{
|
|
686
842
|
type: Injectable
|
|
687
|
-
}]
|
|
688
|
-
// ============================================================
|
|
689
|
-
// DEPRECATED PROVIDER - STANDALONE (will be removed in major)
|
|
690
|
-
// ============================================================
|
|
691
|
-
/**
|
|
692
|
-
* @deprecated Use `provideRuntimeTranslation()` instead.
|
|
693
|
-
*
|
|
694
|
-
* Provide the Translation service with static configuration.
|
|
695
|
-
* This provider is completely standalone and does NOT include ngx-translate setup.
|
|
696
|
-
* It just provides the configuration token for the service to use.
|
|
697
|
-
*
|
|
698
|
-
* Configuration is baked into the app at build time. For dynamic configuration,
|
|
699
|
-
* use `provideRuntimeTranslation()` to load from a JSON file.
|
|
700
|
-
*
|
|
701
|
-
* @param config - Configuration for languages and paths (optional)
|
|
702
|
-
* @returns Environment providers for bootstrapping
|
|
703
|
-
*
|
|
704
|
-
* @example
|
|
705
|
-
* ```typescript
|
|
706
|
-
* // DEPRECATED: Static config - do not use in new code
|
|
707
|
-
* bootstrapApplication(AppComponent, [
|
|
708
|
-
* provideTranslation({
|
|
709
|
-
* defaultLang: 'es',
|
|
710
|
-
* translationPaths: ['/assets/i18n/'],
|
|
711
|
-
* }),
|
|
712
|
-
* ]);
|
|
713
|
-
*
|
|
714
|
-
* // RECOMMENDED: Use runtime config instead
|
|
715
|
-
* bootstrapApplication(AppComponent, [
|
|
716
|
-
* provideRuntimeTranslation('/assets/config/translation-config.json'),
|
|
717
|
-
* ]);
|
|
718
|
-
* ```
|
|
719
|
-
*/
|
|
720
|
-
function provideTranslation(config) {
|
|
721
|
-
return makeEnvironmentProviders([
|
|
722
|
-
{
|
|
723
|
-
provide: TRANSLATION_CONFIG_TOKEN,
|
|
724
|
-
useValue: config || {},
|
|
725
|
-
},
|
|
726
|
-
]);
|
|
727
|
-
}
|
|
843
|
+
}] });
|
|
728
844
|
// ============================================================
|
|
729
845
|
// RUNTIME PROVIDER - WITH NGXTRANSLATE SETUP
|
|
730
846
|
// ============================================================
|
|
731
847
|
/**
|
|
732
848
|
* Configuration options for the runtime translation provider (like themes).
|
|
733
849
|
*
|
|
734
|
-
* @property
|
|
735
|
-
* @property
|
|
850
|
+
* @property appId - Optional namespace to avoid cache collisions across MFEs
|
|
851
|
+
* @property sse - Optional SSE config for runtime update checks (disabled by default)
|
|
852
|
+
* @property updateStream - Optional Observable for runtime update checks (disabled by default)
|
|
736
853
|
*
|
|
737
854
|
* @example
|
|
738
855
|
* ```typescript
|
|
739
|
-
* // Default mode
|
|
856
|
+
* // Default mode
|
|
740
857
|
* provideRuntimeTranslation('/assets/config/translation-config.json')
|
|
741
858
|
*
|
|
742
|
-
* //
|
|
859
|
+
* // SSE updates (optional)
|
|
743
860
|
* provideRuntimeTranslation('/assets/config/translation-config.json', {
|
|
744
|
-
*
|
|
745
|
-
* freshOnNavigation: false,
|
|
746
|
-
* retries: 3,
|
|
747
|
-
* },
|
|
861
|
+
* sse: { url: '/api/updates' }
|
|
748
862
|
* })
|
|
749
863
|
* ```
|
|
750
864
|
*/
|
|
751
865
|
/**
|
|
752
866
|
* Build runtime translation loader options with defaults
|
|
753
867
|
*/
|
|
754
|
-
function buildRuntimeTranslationLoaderOptions(configPath, overrides) {
|
|
755
|
-
const merged = { ...RUNTIME_TRANSLATION_LOADER_DEFAULTS, ...overrides };
|
|
756
|
-
return {
|
|
757
|
-
...merged,
|
|
758
|
-
cacheKey: overrides?.cacheKey ?? configPath,
|
|
759
|
-
fallbackData: overrides?.fallbackData ?? FALLBACK_RUNTIME_TRANSLATION_CONFIG,
|
|
760
|
-
parser: overrides?.parser ?? (async (response) => (await response.json())),
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
868
|
/**
|
|
764
869
|
* Provide Translation service with configuration loaded from a JSON file at runtime (like themes).
|
|
765
870
|
*
|
|
@@ -781,94 +886,72 @@ function buildRuntimeTranslationLoaderOptions(configPath, overrides) {
|
|
|
781
886
|
* ```
|
|
782
887
|
*/
|
|
783
888
|
function provideRuntimeTranslation(configPath, options) {
|
|
784
|
-
const initialConfig = options?.loaderOptions?.fallbackData ?? FALLBACK_RUNTIME_TRANSLATION_CONFIG;
|
|
785
889
|
return makeEnvironmentProviders([
|
|
786
|
-
// Provide initial config token FIRST
|
|
787
|
-
{
|
|
788
|
-
provide: TRANSLATION_CONFIG_TOKEN,
|
|
789
|
-
useValue: initialConfig,
|
|
790
|
-
},
|
|
791
890
|
// NOW provide ngx-translate - TranslationService will be injected when needed
|
|
792
891
|
// Do NOT provide TranslationService directly since it's providedIn: 'root'
|
|
793
892
|
provideTranslateService({
|
|
794
|
-
loader:
|
|
795
|
-
|
|
796
|
-
useClass: RuntimeTranslationCustomLoader,
|
|
797
|
-
},
|
|
798
|
-
missingTranslationHandler: {
|
|
799
|
-
provide: MissingTranslationHandler,
|
|
800
|
-
useClass: PlaceholderMissingTranslationHandler,
|
|
801
|
-
},
|
|
802
|
-
useDefaultLang: false,
|
|
893
|
+
loader: provideTranslateLoader(RuntimeTranslationCustomLoader),
|
|
894
|
+
missingTranslationHandler: provideMissingTranslationHandler(PlaceholderMissingTranslationHandler),
|
|
803
895
|
}),
|
|
804
896
|
// Load runtime config and initialize service
|
|
805
897
|
provideAppInitializer(() => {
|
|
806
898
|
const translationService = inject(TranslationService);
|
|
807
899
|
const logger = inject(LoggerService);
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
configPath,
|
|
822
|
-
source: result.source,
|
|
823
|
-
translationPaths: result.data?.translationPaths,
|
|
824
|
-
});
|
|
825
|
-
// Update the service with the runtime config
|
|
826
|
-
// This will update paths and reload translations
|
|
827
|
-
await translationService.setRuntimeConfig(result.data);
|
|
828
|
-
logger.debug('Service configured with runtime config', {
|
|
829
|
-
component: 'TranslationProvider',
|
|
830
|
-
action: 'loadConfigFromFile',
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
catch (error) {
|
|
834
|
-
logger.error('Failed to load runtime translation config, using fallback', error instanceof Error ? error : new Error(String(error)), {
|
|
835
|
-
component: 'TranslationProvider',
|
|
836
|
-
action: 'loadConfigFromFile',
|
|
837
|
-
configPath,
|
|
838
|
-
});
|
|
900
|
+
const store = new RuntimeConfigStore('translation-runtime-config', options?.appId);
|
|
901
|
+
const loader = new RuntimeConfigLoader(configPath, {
|
|
902
|
+
fallbackData: FALLBACK_RUNTIME_TRANSLATION_CONFIG,
|
|
903
|
+
schemaVersion: TRANSLATION_SCHEMA_VERSION,
|
|
904
|
+
resource: 'translation',
|
|
905
|
+
store,
|
|
906
|
+
logger,
|
|
907
|
+
parser: async (response) => (await response.json()),
|
|
908
|
+
appId: options?.appId,
|
|
909
|
+
});
|
|
910
|
+
const updateAdapter = new RuntimeUpdateAdapter(async (event) => {
|
|
911
|
+
if (event.resource && event.resource !== 'translation' && event.resource !== 'both') {
|
|
912
|
+
return;
|
|
839
913
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
loadConfigFromFile();
|
|
914
|
+
await translationService.checkForTranslationUpdates(loader, event);
|
|
915
|
+
});
|
|
916
|
+
if (options?.sse) {
|
|
917
|
+
updateAdapter.connectSse(options.sse.url, {
|
|
918
|
+
resource: 'translation',
|
|
919
|
+
withCredentials: options.sse.withCredentials,
|
|
920
|
+
eventType: options.sse.eventType,
|
|
921
|
+
transform: options.sse.transform,
|
|
922
|
+
logger,
|
|
850
923
|
});
|
|
851
924
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
925
|
+
if (options?.updateStream) {
|
|
926
|
+
updateAdapter.connectStream(options.updateStream);
|
|
927
|
+
}
|
|
928
|
+
return (async () => {
|
|
929
|
+
let result = await loader.loadLatest();
|
|
930
|
+
if (result.source === 'cache') {
|
|
931
|
+
try {
|
|
932
|
+
const check = await loader.checkForUpdates(result.hash);
|
|
933
|
+
if (check.updated) {
|
|
934
|
+
result = await loader.refresh();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
catch (error) {
|
|
938
|
+
logger.warn('Translation config bootstrap validation failed', {
|
|
939
|
+
component: 'TranslationProvider',
|
|
940
|
+
action: 'bootstrapValidation',
|
|
941
|
+
error: error instanceof Error ? error.message : String(error),
|
|
942
|
+
});
|
|
943
|
+
}
|
|
862
944
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
component: 'TranslationProvider',
|
|
866
|
-
action: 'init',
|
|
867
|
-
error: error instanceof Error ? error.message : String(error),
|
|
868
|
-
});
|
|
869
|
-
// Don't throw - let app continue with partial translations
|
|
945
|
+
if (!result.meta.schemaVersion) {
|
|
946
|
+
throw new Error('Translation config schemaVersion missing');
|
|
870
947
|
}
|
|
871
|
-
|
|
948
|
+
if (result.meta.schemaVersion !== TRANSLATION_SCHEMA_VERSION) {
|
|
949
|
+
throw new Error('Translation config schemaVersion mismatch');
|
|
950
|
+
}
|
|
951
|
+
await translationService.applyRuntimeConfig(result, loader);
|
|
952
|
+
translationService.setRuntimeLoader(loader, result.hash);
|
|
953
|
+
translationService.init();
|
|
954
|
+
})();
|
|
872
955
|
}),
|
|
873
956
|
]);
|
|
874
957
|
}
|
|
@@ -879,5 +962,5 @@ function provideRuntimeTranslation(configPath, options) {
|
|
|
879
962
|
* Generated bundle index. Do not edit.
|
|
880
963
|
*/
|
|
881
964
|
|
|
882
|
-
export { DEFAULT_BASE_LANGUAGE, DEFAULT_LANGUAGES_LIST, DEFAULT_LANGUAGE_CODES, LANGUAGE_ATTRIBUTE_NAME, PlaceholderMissingTranslationHandler,
|
|
965
|
+
export { DEFAULT_BASE_LANGUAGE, DEFAULT_LANGUAGES_LIST, DEFAULT_LANGUAGE_CODES, FALLBACK_RUNTIME_TRANSLATION_CONFIG, LANGUAGE_ATTRIBUTE_NAME, PlaceholderMissingTranslationHandler, TRANSLATION_SCHEMA_VERSION, TRANSLATION_STORAGE_LANGUAGE_KEY, TRANSLATION_STORAGE_NAMESPACE, TranslationDomService, TranslationService, TranslationStorageService, createLanguage, extendDefaultLanguages, provideRuntimeTranslation };
|
|
883
966
|
//# sourceMappingURL=sixbell-telco-sdk-utils-translation.mjs.map
|