@sixbell-telco/sdk 1.5.0 → 2.0.1
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 +223 -710
- package/README.md +307 -282
- package/_index.css +29 -3
- package/components/audio-player/audio-timeline/audio-timeline.component.d.ts +1 -1
- package/components/audio-player/services/audio.service.d.ts +14 -14
- package/components/countdown/src/countdown.component.d.ts +1 -1
- package/components/dropdown/dropdown-chevron/dropdown-chevron.component.d.ts +6 -1
- package/components/dropdown/dropdown-content/dropdown-content.component.d.ts +1 -1
- package/components/dropdown/dropdown-item/dropdown-item.component.d.ts +6 -1
- package/components/dropdown/dropdown-item-checkbox/dropdown-item-checkbox.component.d.ts +7 -1
- package/components/dropdown/dropdown-item-radio/dropdown-item-radio.component.d.ts +7 -1
- package/components/dropdown/dropdown-trigger/dropdown-trigger.component.d.ts +30 -0
- package/components/dropdown/public-api.d.ts +0 -1
- package/components/dropdown/src/dropdown.component.d.ts +31 -7
- package/components/dropdown-menu/src/dropdown-menu-content/dropdown-menu-content.component.d.ts +2 -3
- package/components/dual-list/src/dual-list.component.d.ts +2 -1
- package/components/file-upload/file-dropzone/file-dropzone.component.d.ts +7 -7
- package/components/file-upload/file-uploader/file-uploader.component.d.ts +7 -7
- package/components/forms/combobox/src/combobox.component.d.ts +24 -0
- package/components/forms/input/src/input.component.d.ts +11 -1
- package/components/forms/select/src/select.component.d.ts +24 -0
- package/components/forms/textarea/src/textarea.component.d.ts +10 -10
- package/components/link/src/link.component.d.ts +0 -3
- package/components/tab/directives/tab-content/tab-content.directive.d.ts +3 -3
- package/components/tab/directives/tab-header/tab-header.directive.d.ts +2 -2
- package/components/wizard/services/wizard.service.d.ts +5 -5
- package/directives/auto-focus/public-api.d.ts +1 -1
- package/directives/auto-focus/src/{autofocus.directive.d.ts → auto-focus.directive.d.ts} +5 -7
- package/directives/only-numbers/public-api.d.ts +6 -1
- package/directives/only-numbers/src/only-numbers.directive.d.ts +37 -0
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs +7 -5
- 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-countdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs +0 -4
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +472 -341
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs +8 -7
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs +6 -4
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs +58 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs +2 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs +15 -5
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs +54 -4
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs +19 -8
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.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 +2 -2
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs +14 -31
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs +42 -8
- 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 +1053 -716
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs +345 -257
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs.map +1 -1
- package/package.json +73 -72
- 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 +8 -0
- 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.service.d.ts +37 -9
- package/components/dropdown/src/services/dropdown.service.d.ts +0 -22
- 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, Injectable, inject, 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
|
/**
|
|
@@ -237,7 +231,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
|
|
|
237
231
|
/**
|
|
238
232
|
* Translation Service
|
|
239
233
|
* Main service for handling language selection, translation loading, and management
|
|
240
|
-
* Mirrors ThemeService - config via DI token +
|
|
234
|
+
* Mirrors ThemeService - config via DI token + multi-path loading
|
|
241
235
|
*/
|
|
242
236
|
function createLanguage(config) {
|
|
243
237
|
return {
|
|
@@ -254,34 +248,39 @@ class PlaceholderMissingTranslationHandler {
|
|
|
254
248
|
}
|
|
255
249
|
}
|
|
256
250
|
class TranslationService {
|
|
257
|
-
translationConfig;
|
|
258
251
|
translate = inject(TranslateService);
|
|
259
252
|
storageService = inject(TranslationStorageService);
|
|
260
253
|
domService = inject(TranslationDomService);
|
|
261
254
|
logger = inject(LoggerService);
|
|
255
|
+
destroyRef = inject(DestroyRef);
|
|
262
256
|
initialized = false;
|
|
263
257
|
currentTranslationPaths = [...DEFAULT_TRANSLATION_PATHS];
|
|
264
|
-
|
|
258
|
+
translationHttpClient = null;
|
|
265
259
|
hasAppliedInitialLanguage = false;
|
|
260
|
+
isUsingFallbackConfig = false;
|
|
261
|
+
prefetchLanguages = true;
|
|
262
|
+
isApplyingRuntimeConfig = false;
|
|
263
|
+
runtimeHash = null;
|
|
264
|
+
runtimeLoader;
|
|
265
|
+
runtimeMeta;
|
|
266
|
+
pendingUpdatedLanguages = new Set();
|
|
267
|
+
bootstrapValidated = false;
|
|
268
|
+
translationTick = signal(0);
|
|
269
|
+
updateAvailable = signal(false);
|
|
270
|
+
lastRefreshFailed = signal(false);
|
|
266
271
|
config = {
|
|
267
272
|
availableLanguages: [...DEFAULT_LANGUAGES],
|
|
268
273
|
defaultLanguage: DEFAULT_LANGUAGE_CODE,
|
|
269
274
|
};
|
|
270
275
|
currentLanguage = signal(DEFAULT_LANGUAGE_CODE);
|
|
271
|
-
onLanguageChange$ = this.translate.onLangChange
|
|
276
|
+
onLanguageChange$ = this.translate.onLangChange;
|
|
272
277
|
onLanguageChange = signal(0);
|
|
273
278
|
ready = signal(false);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (translationConfig) {
|
|
277
|
-
this.configure(translationConfig);
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
this.initializeFromStorage();
|
|
281
|
-
}
|
|
279
|
+
changes = computed(() => this.translationTick());
|
|
280
|
+
constructor() {
|
|
282
281
|
this.currentLanguage.set(this.getCurrentLanguage());
|
|
283
282
|
}
|
|
284
|
-
configure(config
|
|
283
|
+
configure(config) {
|
|
285
284
|
this.logger.debug('configure - starting', {
|
|
286
285
|
component: 'TranslationService',
|
|
287
286
|
action: 'configure',
|
|
@@ -306,7 +305,17 @@ class TranslationService {
|
|
|
306
305
|
action: 'configure',
|
|
307
306
|
newPaths,
|
|
308
307
|
});
|
|
309
|
-
this.
|
|
308
|
+
const targetLang = this.getCurrentLanguage();
|
|
309
|
+
const preloadPromises = this.currentTranslationPaths.map((path) => {
|
|
310
|
+
const normalized = path.endsWith('/') ? path : `${path}/`;
|
|
311
|
+
const url = `${normalized}${targetLang}.json`;
|
|
312
|
+
return this.fetchTranslation(url)
|
|
313
|
+
.then(() => undefined)
|
|
314
|
+
.catch(() => undefined);
|
|
315
|
+
});
|
|
316
|
+
Promise.all(preloadPromises).then(() => {
|
|
317
|
+
this.translate.reloadLang(targetLang);
|
|
318
|
+
});
|
|
310
319
|
}
|
|
311
320
|
this.config = {
|
|
312
321
|
availableLanguages,
|
|
@@ -328,11 +337,14 @@ class TranslationService {
|
|
|
328
337
|
finalDefaultLang: this.config.defaultLanguage,
|
|
329
338
|
availableLangCodes: availableCodes,
|
|
330
339
|
});
|
|
340
|
+
this.resolveStoredLanguage();
|
|
331
341
|
if (this.initialized) {
|
|
332
342
|
// This is a runtime config update (not initial construction)
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
|
|
343
|
+
// Keep current language resolved from storage unless we're doing a fresh init
|
|
344
|
+
if (!this.isApplyingRuntimeConfig) {
|
|
345
|
+
this.currentLanguage.set(this.config.defaultLanguage);
|
|
346
|
+
this.initializeFromStorage();
|
|
347
|
+
}
|
|
336
348
|
// Mark that we've applied the initial language so init() can apply it on next call
|
|
337
349
|
this.hasAppliedInitialLanguage = true;
|
|
338
350
|
}
|
|
@@ -344,35 +356,133 @@ class TranslationService {
|
|
|
344
356
|
// will be deferred until setRuntimeConfig() is called.
|
|
345
357
|
}
|
|
346
358
|
}
|
|
359
|
+
resolveStoredLanguage() {
|
|
360
|
+
const availableCodes = this.config.availableLanguages.map((lang) => lang.code);
|
|
361
|
+
const savedLanguage = this.storageService.getSavedLanguage();
|
|
362
|
+
if (savedLanguage && availableCodes.includes(savedLanguage)) {
|
|
363
|
+
this.currentLanguage.set(savedLanguage);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (savedLanguage && !this.isUsingFallbackConfig) {
|
|
367
|
+
this.storageService.clear();
|
|
368
|
+
}
|
|
369
|
+
this.currentLanguage.set(this.config.defaultLanguage);
|
|
370
|
+
}
|
|
347
371
|
async setRuntimeConfig(config) {
|
|
372
|
+
this.ready.set(false);
|
|
348
373
|
this.logger.debug('setRuntimeConfig - starting', {
|
|
349
374
|
component: 'TranslationService',
|
|
350
375
|
action: 'setRuntimeConfig',
|
|
351
376
|
configPath: config.translationPaths,
|
|
352
377
|
});
|
|
353
378
|
// Update configuration (this will update currentLanguage signal and restore from storage)
|
|
379
|
+
this.isApplyingRuntimeConfig = true;
|
|
354
380
|
this.configure(config);
|
|
355
381
|
// Apply language now that runtime config has loaded
|
|
356
382
|
// This saves to storage with the correct default from config file
|
|
383
|
+
const targetLang = this.currentLanguage();
|
|
384
|
+
await firstValueFrom(this.translate.reloadLang(targetLang));
|
|
357
385
|
this.applyLanguage();
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
currentLanguage: currentLang,
|
|
365
|
-
});
|
|
366
|
-
this.translate.reloadLang(currentLang);
|
|
367
|
-
await this.waitForTranslations();
|
|
386
|
+
await this.loadSelectedLanguage();
|
|
387
|
+
if (this.prefetchLanguages) {
|
|
388
|
+
this.prefetchRemainingLanguages();
|
|
389
|
+
}
|
|
390
|
+
this.isApplyingRuntimeConfig = false;
|
|
391
|
+
this.translationTick.update((value) => value + 1);
|
|
368
392
|
this.logger.debug('setRuntimeConfig - complete', {
|
|
369
393
|
component: 'TranslationService',
|
|
370
394
|
action: 'setRuntimeConfig',
|
|
371
395
|
currentLanguage: this.getCurrentLanguage(),
|
|
372
396
|
});
|
|
373
397
|
}
|
|
398
|
+
enablePrefetch(enable) {
|
|
399
|
+
this.prefetchLanguages = enable;
|
|
400
|
+
}
|
|
401
|
+
async loadSelectedLanguage() {
|
|
402
|
+
const targetLang = this.currentLanguage();
|
|
403
|
+
await this.loadLanguageResources(targetLang);
|
|
404
|
+
}
|
|
405
|
+
prefetchRemainingLanguages() {
|
|
406
|
+
const currentLang = this.currentLanguage();
|
|
407
|
+
const remaining = this.getAvailableLanguagesConfig()
|
|
408
|
+
.map((lang) => lang.code)
|
|
409
|
+
.filter((code) => code !== currentLang);
|
|
410
|
+
for (const lang of remaining) {
|
|
411
|
+
this.loadLanguageResources(lang).catch(() => undefined);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async loadLanguageResources(lang) {
|
|
415
|
+
const loadPromises = this.currentTranslationPaths.map((path) => {
|
|
416
|
+
const normalized = path.endsWith('/') ? path : `${path}/`;
|
|
417
|
+
const url = `${normalized}${lang}.json`;
|
|
418
|
+
return this.fetchTranslation(url);
|
|
419
|
+
});
|
|
420
|
+
await Promise.allSettled(loadPromises);
|
|
421
|
+
}
|
|
422
|
+
queueUpdatedLanguage(lang) {
|
|
423
|
+
if (!lang) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
this.pendingUpdatedLanguages.add(lang);
|
|
427
|
+
}
|
|
428
|
+
async reloadLanguages(languages) {
|
|
429
|
+
const unique = Array.from(new Set(languages)).filter(Boolean);
|
|
430
|
+
if (!unique.length) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
const available = new Set(this.getAvailableLanguageCodes());
|
|
434
|
+
await Promise.all(unique.filter((lang) => available.has(lang)).map((lang) => firstValueFrom(this.translate.reloadLang(lang)).catch(() => undefined)));
|
|
435
|
+
}
|
|
436
|
+
async refreshInactiveLanguages() {
|
|
437
|
+
const current = this.currentLanguage();
|
|
438
|
+
const nonActive = this.getAvailableLanguageCodes().filter((lang) => lang !== current);
|
|
439
|
+
await this.reloadLanguages(nonActive);
|
|
440
|
+
}
|
|
441
|
+
async validateBootstrapCache() {
|
|
442
|
+
if (this.bootstrapValidated) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
this.bootstrapValidated = true;
|
|
446
|
+
const runtimeLoader = this.runtimeLoader;
|
|
447
|
+
if (!runtimeLoader || !this.runtimeHash || this.isUsingFallbackConfig) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (this.runtimeMeta?.schemaVersion && this.runtimeMeta.schemaVersion !== TRANSLATION_SCHEMA_VERSION) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
try {
|
|
454
|
+
const check = await runtimeLoader.checkForUpdates(this.runtimeHash);
|
|
455
|
+
if (!check.updated) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const result = await runtimeLoader.refresh();
|
|
459
|
+
this.isUsingFallbackConfig = result.source === 'fallback';
|
|
460
|
+
this.runtimeHash = result.hash;
|
|
461
|
+
this.runtimeMeta = result.meta;
|
|
462
|
+
this.updateAvailable.set(false);
|
|
463
|
+
await this.setRuntimeConfig(result.data);
|
|
464
|
+
this.ready.set(true);
|
|
465
|
+
const current = this.currentLanguage();
|
|
466
|
+
await this.reloadLanguages([current]);
|
|
467
|
+
void this.refreshInactiveLanguages();
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
this.logger.warn('Translation bootstrap validation failed', {
|
|
471
|
+
component: 'TranslationService',
|
|
472
|
+
action: 'validateBootstrapCache',
|
|
473
|
+
error: error instanceof Error ? error.message : String(error),
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
374
477
|
initializeFromStorage() {
|
|
375
478
|
try {
|
|
479
|
+
if (this.isApplyingRuntimeConfig) {
|
|
480
|
+
this.logger.debug('Skipping storage restore during runtime config apply', {
|
|
481
|
+
component: 'TranslationService',
|
|
482
|
+
action: 'initializeFromStorage',
|
|
483
|
+
});
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
376
486
|
const saved = this.storageService.getSavedLanguage();
|
|
377
487
|
const availableCodes = this.config.availableLanguages.map((l) => l.code);
|
|
378
488
|
if (saved && availableCodes.includes(saved)) {
|
|
@@ -394,6 +504,7 @@ class TranslationService {
|
|
|
394
504
|
}
|
|
395
505
|
applyLanguage() {
|
|
396
506
|
const targetLang = this.currentLanguage();
|
|
507
|
+
this.translate.setFallbackLang(this.config.defaultLanguage);
|
|
397
508
|
this.translate.use(targetLang);
|
|
398
509
|
this.domService.setDocumentLanguage(targetLang);
|
|
399
510
|
// Always save to storage - keeps state consistent from the start
|
|
@@ -429,7 +540,7 @@ class TranslationService {
|
|
|
429
540
|
return saved && availableCodes.includes(saved) ? saved : this.config.defaultLanguage;
|
|
430
541
|
}
|
|
431
542
|
getAvailableLanguages() {
|
|
432
|
-
return this.translate.getLangs();
|
|
543
|
+
return [...this.translate.getLangs()];
|
|
433
544
|
}
|
|
434
545
|
getDefaultLanguage() {
|
|
435
546
|
return this.config.defaultLanguage;
|
|
@@ -438,15 +549,13 @@ class TranslationService {
|
|
|
438
549
|
const result = params ? this.translate.instant(key, params) : this.translate.instant(key);
|
|
439
550
|
if (result === key) {
|
|
440
551
|
const currentLang = this.getCurrentLanguage();
|
|
441
|
-
const loadedTranslations = this.translate.translations[currentLang] || {};
|
|
442
|
-
const loadedKeys = Object.keys(loadedTranslations);
|
|
443
552
|
this.logger.warn('Translation key not found', {
|
|
444
553
|
component: 'TranslationService',
|
|
445
554
|
action: 'instant',
|
|
446
555
|
key,
|
|
447
556
|
currentLanguage: currentLang,
|
|
448
557
|
hasParams: !!params,
|
|
449
|
-
|
|
558
|
+
availableLanguages: this.translate.getLangs(),
|
|
450
559
|
});
|
|
451
560
|
}
|
|
452
561
|
return result;
|
|
@@ -489,7 +598,7 @@ class TranslationService {
|
|
|
489
598
|
return this.ready.asReadonly();
|
|
490
599
|
}
|
|
491
600
|
async waitForTranslations(timeoutMs = 10000) {
|
|
492
|
-
return new Promise((resolve
|
|
601
|
+
return new Promise((resolve) => {
|
|
493
602
|
if (this.ready()) {
|
|
494
603
|
resolve();
|
|
495
604
|
return;
|
|
@@ -508,7 +617,8 @@ class TranslationService {
|
|
|
508
617
|
timeoutMs,
|
|
509
618
|
isReady: this.ready(),
|
|
510
619
|
});
|
|
511
|
-
|
|
620
|
+
this.ready.set(true);
|
|
621
|
+
resolve();
|
|
512
622
|
}
|
|
513
623
|
}, 50);
|
|
514
624
|
});
|
|
@@ -521,10 +631,11 @@ class TranslationService {
|
|
|
521
631
|
if (this.hasAppliedInitialLanguage) {
|
|
522
632
|
this.applyLanguage();
|
|
523
633
|
}
|
|
524
|
-
this.translate.onLangChange.
|
|
634
|
+
const subscription = this.translate.onLangChange.subscribe({
|
|
525
635
|
next: (event) => {
|
|
526
636
|
this.currentLanguage.set(event.lang);
|
|
527
637
|
this.onLanguageChange.update((val) => val + 1);
|
|
638
|
+
this.translationTick.update((value) => value + 1);
|
|
528
639
|
this.ready.set(true);
|
|
529
640
|
this.logger.debug('Translations ready - language loaded', {
|
|
530
641
|
component: 'TranslationService',
|
|
@@ -541,24 +652,115 @@ class TranslationService {
|
|
|
541
652
|
this.ready.set(true);
|
|
542
653
|
},
|
|
543
654
|
});
|
|
655
|
+
this.destroyRef.onDestroy(() => {
|
|
656
|
+
subscription.unsubscribe();
|
|
657
|
+
});
|
|
544
658
|
}
|
|
545
|
-
|
|
546
|
-
if (
|
|
547
|
-
this.
|
|
659
|
+
async applyRuntimeConfig(result, loader) {
|
|
660
|
+
if (loader) {
|
|
661
|
+
this.runtimeLoader = loader;
|
|
662
|
+
}
|
|
663
|
+
this.isUsingFallbackConfig = result.source === 'fallback';
|
|
664
|
+
this.runtimeHash = result.hash;
|
|
665
|
+
this.runtimeMeta = result.meta;
|
|
666
|
+
this.updateAvailable.set(false);
|
|
667
|
+
await this.setRuntimeConfig(result.data);
|
|
668
|
+
this.ready.set(true);
|
|
669
|
+
if (result.source === 'cache') {
|
|
670
|
+
void this.validateBootstrapCache();
|
|
548
671
|
}
|
|
549
|
-
return this.translationResourceLoader;
|
|
550
672
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
673
|
+
setRuntimeLoader(loader, hash) {
|
|
674
|
+
this.runtimeLoader = loader;
|
|
675
|
+
this.runtimeHash = hash ?? null;
|
|
676
|
+
this.updateAvailable.set(false);
|
|
677
|
+
this.lastRefreshFailed.set(false);
|
|
678
|
+
}
|
|
679
|
+
async checkForTranslationUpdates(loader, event) {
|
|
680
|
+
this.runtimeLoader = loader;
|
|
681
|
+
if (event?.resource && event.resource !== 'translation' && event.resource !== 'both') {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const eventHash = event?.hash;
|
|
685
|
+
const eventLang = event && 'lang' in event ? event.lang : undefined;
|
|
686
|
+
if (eventHash) {
|
|
687
|
+
if (eventHash === this.runtimeHash) {
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
this.queueUpdatedLanguage(eventLang);
|
|
691
|
+
if (!this.updateAvailable()) {
|
|
692
|
+
this.updateAvailable.set(true);
|
|
693
|
+
}
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const currentHash = this.runtimeHash;
|
|
697
|
+
if (currentHash) {
|
|
698
|
+
const check = await loader.checkForUpdates(currentHash);
|
|
699
|
+
if (check.updated && !this.updateAvailable()) {
|
|
700
|
+
this.updateAvailable.set(true);
|
|
701
|
+
}
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (!this.updateAvailable()) {
|
|
705
|
+
this.updateAvailable.set(true);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
async refreshTranslation(loader) {
|
|
709
|
+
const runtimeLoader = loader ?? this.runtimeLoader;
|
|
710
|
+
if (!runtimeLoader) {
|
|
711
|
+
this.logger.warn('Translation refresh requested without runtime loader', {
|
|
712
|
+
component: 'TranslationService',
|
|
713
|
+
action: 'refreshTranslation',
|
|
714
|
+
});
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
try {
|
|
718
|
+
const result = await runtimeLoader.refresh();
|
|
719
|
+
await this.applyRuntimeConfig(result, runtimeLoader);
|
|
720
|
+
const pendingLanguages = Array.from(this.pendingUpdatedLanguages);
|
|
721
|
+
this.pendingUpdatedLanguages.clear();
|
|
722
|
+
const current = this.currentLanguage();
|
|
723
|
+
if (pendingLanguages.length > 0) {
|
|
724
|
+
await this.reloadLanguages(pendingLanguages.filter((lang) => lang !== current));
|
|
725
|
+
}
|
|
726
|
+
this.updateAvailable.set(false);
|
|
727
|
+
this.lastRefreshFailed.set(false);
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
this.lastRefreshFailed.set(true);
|
|
731
|
+
this.logger.error('Translation refresh failed', error, {
|
|
732
|
+
component: 'TranslationService',
|
|
733
|
+
action: 'refreshTranslation',
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
withTranslationsReady(fn) {
|
|
738
|
+
this.changes();
|
|
739
|
+
if (!this.ready()) {
|
|
740
|
+
return undefined;
|
|
741
|
+
}
|
|
742
|
+
return fn();
|
|
743
|
+
}
|
|
744
|
+
getOrCreateHttpClient() {
|
|
745
|
+
if (!this.translationHttpClient) {
|
|
746
|
+
this.translationHttpClient = new RuntimeHttpClient({
|
|
747
|
+
retries: 2,
|
|
748
|
+
retryDelayMs: 400,
|
|
749
|
+
timeoutMs: 6000,
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
return this.translationHttpClient;
|
|
753
|
+
}
|
|
754
|
+
async fetchTranslation(url) {
|
|
755
|
+
try {
|
|
756
|
+
const response = await this.getOrCreateHttpClient().fetch(url, { cache: 'no-store' });
|
|
757
|
+
return (await response.json());
|
|
758
|
+
}
|
|
759
|
+
catch {
|
|
760
|
+
return {};
|
|
761
|
+
}
|
|
558
762
|
}
|
|
559
763
|
createTranslateLoader() {
|
|
560
|
-
const loader = this.getOrCreateResourceLoader();
|
|
561
|
-
const options = this.buildResourceOptions();
|
|
562
764
|
const suffix = '.json';
|
|
563
765
|
return {
|
|
564
766
|
getTranslation: (lang) => {
|
|
@@ -573,14 +775,11 @@ class TranslationService {
|
|
|
573
775
|
}
|
|
574
776
|
const loadPromises = pathsToUse.map((path) => {
|
|
575
777
|
const url = `${path.endsWith('/') ? path : `${path}/`}${lang}${suffix}`;
|
|
576
|
-
return
|
|
577
|
-
...options,
|
|
578
|
-
cacheKey: `${lang}:${url}`,
|
|
579
|
-
});
|
|
778
|
+
return this.fetchTranslation(url);
|
|
580
779
|
});
|
|
581
780
|
return from(Promise.all(loadPromises).then((results) => {
|
|
582
781
|
const merged = results.reduce((acc, result) => {
|
|
583
|
-
return this.deepMergeTranslations(acc, result
|
|
782
|
+
return this.deepMergeTranslations(acc, result ?? {});
|
|
584
783
|
}, {});
|
|
585
784
|
this.logger.debug('Translations loaded and merged', {
|
|
586
785
|
language: lang,
|
|
@@ -592,18 +791,16 @@ class TranslationService {
|
|
|
592
791
|
},
|
|
593
792
|
};
|
|
594
793
|
}
|
|
794
|
+
isTranslationObject(value) {
|
|
795
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
796
|
+
}
|
|
595
797
|
deepMergeTranslations(target, source) {
|
|
596
798
|
const result = { ...target };
|
|
597
799
|
for (const key in source) {
|
|
598
800
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
599
801
|
const sourceValue = source[key];
|
|
600
802
|
const targetValue = result[key];
|
|
601
|
-
if (
|
|
602
|
-
sourceValue !== null &&
|
|
603
|
-
!Array.isArray(sourceValue) &&
|
|
604
|
-
typeof targetValue === 'object' &&
|
|
605
|
-
targetValue !== null &&
|
|
606
|
-
!Array.isArray(targetValue)) {
|
|
803
|
+
if (this.isTranslationObject(sourceValue) && this.isTranslationObject(targetValue)) {
|
|
607
804
|
result[key] = this.deepMergeTranslations(targetValue, sourceValue);
|
|
608
805
|
}
|
|
609
806
|
else {
|
|
@@ -613,46 +810,13 @@ class TranslationService {
|
|
|
613
810
|
}
|
|
614
811
|
return result;
|
|
615
812
|
}
|
|
616
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, deps: [
|
|
813
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
617
814
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, providedIn: 'root' });
|
|
618
815
|
}
|
|
619
816
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: TranslationService, decorators: [{
|
|
620
817
|
type: Injectable,
|
|
621
818
|
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
|
-
};
|
|
819
|
+
}], ctorParameters: () => [] });
|
|
656
820
|
|
|
657
821
|
// ============================================================
|
|
658
822
|
// CUSTOM LOADER - Deferred injection pattern
|
|
@@ -667,99 +831,45 @@ const FALLBACK_RUNTIME_TRANSLATION_CONFIG = {
|
|
|
667
831
|
* Key: DO NOT use providedIn: 'root' - let ngx-translate manage the lifecycle.
|
|
668
832
|
*/
|
|
669
833
|
class RuntimeTranslationCustomLoader {
|
|
670
|
-
injector;
|
|
671
|
-
constructor(injector) {
|
|
672
|
-
this.injector = injector;
|
|
673
|
-
}
|
|
834
|
+
injector = inject(Injector);
|
|
674
835
|
getTranslation(lang) {
|
|
675
836
|
// Use runInInjectionContext to safely inject TranslationService
|
|
676
837
|
// even when called outside the normal DI context
|
|
677
838
|
return runInInjectionContext(this.injector, () => {
|
|
678
839
|
const translationService = inject(TranslationService);
|
|
679
|
-
return translationService
|
|
840
|
+
return translationService.createTranslateLoader().getTranslation(lang);
|
|
680
841
|
});
|
|
681
842
|
}
|
|
682
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader, deps: [
|
|
843
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
683
844
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader });
|
|
684
845
|
}
|
|
685
846
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: RuntimeTranslationCustomLoader, decorators: [{
|
|
686
847
|
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
|
-
}
|
|
848
|
+
}] });
|
|
728
849
|
// ============================================================
|
|
729
850
|
// RUNTIME PROVIDER - WITH NGXTRANSLATE SETUP
|
|
730
851
|
// ============================================================
|
|
731
852
|
/**
|
|
732
853
|
* Configuration options for the runtime translation provider (like themes).
|
|
733
854
|
*
|
|
734
|
-
* @property
|
|
735
|
-
* @property
|
|
855
|
+
* @property appId - Optional namespace to avoid cache collisions across MFEs
|
|
856
|
+
* @property sse - Optional SSE config for runtime update checks (disabled by default)
|
|
857
|
+
* @property updateStream - Optional Observable for runtime update checks (disabled by default)
|
|
736
858
|
*
|
|
737
859
|
* @example
|
|
738
860
|
* ```typescript
|
|
739
|
-
* // Default mode
|
|
861
|
+
* // Default mode
|
|
740
862
|
* provideRuntimeTranslation('/assets/config/translation-config.json')
|
|
741
863
|
*
|
|
742
|
-
* //
|
|
864
|
+
* // SSE updates (optional)
|
|
743
865
|
* provideRuntimeTranslation('/assets/config/translation-config.json', {
|
|
744
|
-
*
|
|
745
|
-
* freshOnNavigation: false,
|
|
746
|
-
* retries: 3,
|
|
747
|
-
* },
|
|
866
|
+
* sse: { url: '/api/updates' }
|
|
748
867
|
* })
|
|
749
868
|
* ```
|
|
750
869
|
*/
|
|
751
870
|
/**
|
|
752
871
|
* Build runtime translation loader options with defaults
|
|
753
872
|
*/
|
|
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
873
|
/**
|
|
764
874
|
* Provide Translation service with configuration loaded from a JSON file at runtime (like themes).
|
|
765
875
|
*
|
|
@@ -781,94 +891,72 @@ function buildRuntimeTranslationLoaderOptions(configPath, overrides) {
|
|
|
781
891
|
* ```
|
|
782
892
|
*/
|
|
783
893
|
function provideRuntimeTranslation(configPath, options) {
|
|
784
|
-
const initialConfig = options?.loaderOptions?.fallbackData ?? FALLBACK_RUNTIME_TRANSLATION_CONFIG;
|
|
785
894
|
return makeEnvironmentProviders([
|
|
786
|
-
// Provide initial config token FIRST
|
|
787
|
-
{
|
|
788
|
-
provide: TRANSLATION_CONFIG_TOKEN,
|
|
789
|
-
useValue: initialConfig,
|
|
790
|
-
},
|
|
791
895
|
// NOW provide ngx-translate - TranslationService will be injected when needed
|
|
792
896
|
// Do NOT provide TranslationService directly since it's providedIn: 'root'
|
|
793
897
|
provideTranslateService({
|
|
794
|
-
loader:
|
|
795
|
-
|
|
796
|
-
useClass: RuntimeTranslationCustomLoader,
|
|
797
|
-
},
|
|
798
|
-
missingTranslationHandler: {
|
|
799
|
-
provide: MissingTranslationHandler,
|
|
800
|
-
useClass: PlaceholderMissingTranslationHandler,
|
|
801
|
-
},
|
|
802
|
-
useDefaultLang: false,
|
|
898
|
+
loader: provideTranslateLoader(RuntimeTranslationCustomLoader),
|
|
899
|
+
missingTranslationHandler: provideMissingTranslationHandler(PlaceholderMissingTranslationHandler),
|
|
803
900
|
}),
|
|
804
901
|
// Load runtime config and initialize service
|
|
805
902
|
provideAppInitializer(() => {
|
|
806
903
|
const translationService = inject(TranslationService);
|
|
807
904
|
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
|
-
});
|
|
905
|
+
const store = new RuntimeConfigStore('translation-runtime-config', options?.appId);
|
|
906
|
+
const loader = new RuntimeConfigLoader(configPath, {
|
|
907
|
+
fallbackData: FALLBACK_RUNTIME_TRANSLATION_CONFIG,
|
|
908
|
+
schemaVersion: TRANSLATION_SCHEMA_VERSION,
|
|
909
|
+
resource: 'translation',
|
|
910
|
+
store,
|
|
911
|
+
logger,
|
|
912
|
+
parser: async (response) => (await response.json()),
|
|
913
|
+
appId: options?.appId,
|
|
914
|
+
});
|
|
915
|
+
const updateAdapter = new RuntimeUpdateAdapter(async (event) => {
|
|
916
|
+
if (event.resource && event.resource !== 'translation' && event.resource !== 'both') {
|
|
917
|
+
return;
|
|
839
918
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
loadConfigFromFile();
|
|
919
|
+
await translationService.checkForTranslationUpdates(loader, event);
|
|
920
|
+
});
|
|
921
|
+
if (options?.sse) {
|
|
922
|
+
updateAdapter.connectSse(options.sse.url, {
|
|
923
|
+
resource: 'translation',
|
|
924
|
+
withCredentials: options.sse.withCredentials,
|
|
925
|
+
eventType: options.sse.eventType,
|
|
926
|
+
transform: options.sse.transform,
|
|
927
|
+
logger,
|
|
850
928
|
});
|
|
851
929
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
930
|
+
if (options?.updateStream) {
|
|
931
|
+
updateAdapter.connectStream(options.updateStream);
|
|
932
|
+
}
|
|
933
|
+
return (async () => {
|
|
934
|
+
let result = await loader.loadLatest();
|
|
935
|
+
if (result.source === 'cache') {
|
|
936
|
+
try {
|
|
937
|
+
const check = await loader.checkForUpdates(result.hash);
|
|
938
|
+
if (check.updated) {
|
|
939
|
+
result = await loader.refresh();
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
catch (error) {
|
|
943
|
+
logger.warn('Translation config bootstrap validation failed', {
|
|
944
|
+
component: 'TranslationProvider',
|
|
945
|
+
action: 'bootstrapValidation',
|
|
946
|
+
error: error instanceof Error ? error.message : String(error),
|
|
947
|
+
});
|
|
948
|
+
}
|
|
862
949
|
}
|
|
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
|
|
950
|
+
if (!result.meta.schemaVersion) {
|
|
951
|
+
throw new Error('Translation config schemaVersion missing');
|
|
870
952
|
}
|
|
871
|
-
|
|
953
|
+
if (result.meta.schemaVersion !== TRANSLATION_SCHEMA_VERSION) {
|
|
954
|
+
throw new Error('Translation config schemaVersion mismatch');
|
|
955
|
+
}
|
|
956
|
+
await translationService.applyRuntimeConfig(result, loader);
|
|
957
|
+
translationService.setRuntimeLoader(loader, result.hash);
|
|
958
|
+
translationService.init();
|
|
959
|
+
})();
|
|
872
960
|
}),
|
|
873
961
|
]);
|
|
874
962
|
}
|
|
@@ -879,5 +967,5 @@ function provideRuntimeTranslation(configPath, options) {
|
|
|
879
967
|
* Generated bundle index. Do not edit.
|
|
880
968
|
*/
|
|
881
969
|
|
|
882
|
-
export { DEFAULT_BASE_LANGUAGE, DEFAULT_LANGUAGES_LIST, DEFAULT_LANGUAGE_CODES, LANGUAGE_ATTRIBUTE_NAME, PlaceholderMissingTranslationHandler,
|
|
970
|
+
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
971
|
//# sourceMappingURL=sixbell-telco-sdk-utils-translation.mjs.map
|