@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.
Files changed (209) hide show
  1. package/CHANGELOG.md +260 -711
  2. package/README.md +337 -278
  3. package/_index.css +3 -3
  4. package/components/accordion/accordion-item/accordion-item.component.d.ts +3 -4
  5. package/components/audio-player/audio-timeline/audio-timeline.component.d.ts +29 -2
  6. package/components/audio-player/services/audio.service.d.ts +14 -14
  7. package/components/audio-player/src/audio-player.component.d.ts +7 -3
  8. package/components/audio-player/volume-control/volume-control.component.d.ts +28 -1
  9. package/components/button/src/button.component.d.ts +46 -1
  10. package/components/countdown/src/countdown.component.d.ts +1 -1
  11. package/components/data-table/data-table-empty-actions/data-table-empty-actions.component.d.ts +5 -0
  12. package/components/data-table/public-api.d.ts +1 -0
  13. package/components/data-table/src/data-table.component.d.ts +11 -3
  14. package/components/dialog/src/dialog.component.d.ts +51 -5
  15. package/components/dropdown/dropdown-content/dropdown-content.component.d.ts +2 -1
  16. package/components/dropdown/dropdown-item/dropdown-item.component.d.ts +37 -1
  17. package/components/dropdown/dropdown-item-checkbox/dropdown-item-checkbox.component.d.ts +33 -1
  18. package/components/dropdown/dropdown-item-radio/dropdown-item-radio.component.d.ts +33 -1
  19. package/components/dropdown/dropdown-trigger/dropdown-trigger.component.d.ts +53 -2
  20. package/components/dropdown/src/dropdown.component.d.ts +2 -2
  21. package/components/dropdown-menu/bar/dropdown-menu-bar-content/dropdown-menu-bar-content.component.d.ts +2 -1
  22. package/components/dropdown-menu/bar/dropdown-menu-bar-item/dropdown-menu-bar-item.component.d.ts +33 -1
  23. package/components/dropdown-menu/bar/dropdown-menu-bar-item-checkbox/dropdown-menu-bar-item-checkbox.component.d.ts +33 -1
  24. package/components/dropdown-menu/bar/dropdown-menu-bar-item-radio/dropdown-menu-bar-item-radio.component.d.ts +33 -1
  25. package/components/dropdown-menu/src/directives/dropdown-menu.directive.d.ts +1 -3
  26. package/components/dropdown-menu/src/dropdown-menu-content/dropdown-menu-content.component.d.ts +4 -4
  27. package/components/dropdown-menu/src/dropdown-menu-item/dropdown-menu-item.component.d.ts +33 -1
  28. package/components/dropdown-menu/src/dropdown-menu-sub-content/dropdown-menu-sub-content.component.d.ts +2 -1
  29. package/components/dual-list/src/dual-list.component.d.ts +4 -2
  30. package/components/file-upload/file-dropzone/file-dropzone.component.d.ts +53 -8
  31. package/components/file-upload/file-uploader/file-uploader.component.d.ts +40 -9
  32. package/components/forms/checkbox/src/checkbox.component.d.ts +46 -2
  33. package/components/forms/combobox/src/combobox.component.d.ts +40 -5
  34. package/components/forms/date-picker/src/date-picker.component.d.ts +11 -1
  35. package/components/forms/form-group/README.md +114 -0
  36. package/components/forms/form-group/index.d.ts +5 -0
  37. package/components/forms/form-group/public-api.d.ts +1 -0
  38. package/components/forms/form-group/src/form-group.component.d.ts +150 -0
  39. package/components/forms/form-item/README.md +17 -0
  40. package/components/forms/form-item/index.d.ts +5 -0
  41. package/components/forms/form-item/public-api.d.ts +1 -0
  42. package/components/forms/form-item/src/form-item.component.d.ts +5 -0
  43. package/components/forms/input/src/input.component.d.ts +45 -2
  44. package/components/forms/radio/src/radio.component.d.ts +46 -2
  45. package/components/forms/range/src/range.component.d.ts +38 -1
  46. package/components/forms/select/src/select.component.d.ts +40 -5
  47. package/components/forms/switch/src/switch.component.d.ts +46 -2
  48. package/components/forms/textarea/src/textarea.component.d.ts +62 -12
  49. package/components/forms/toggle/src/toggle.component.d.ts +46 -1
  50. package/components/link/src/link.component.d.ts +0 -3
  51. package/components/overlay/overlay-content/overlay-content.component.d.ts +2 -1
  52. package/components/overlay/overlay-trigger/overlay-trigger.component.d.ts +37 -5
  53. package/components/overlay/src/overlay.component.d.ts +4 -5
  54. package/components/paginator/components/pagination-item/pagination-item.component.d.ts +37 -1
  55. package/components/tab/directives/tab-content/tab-content.directive.d.ts +5 -6
  56. package/components/tab/directives/tab-header/tab-header.directive.d.ts +2 -2
  57. package/components/table/public-api.d.ts +1 -0
  58. package/components/table/src/table.component.d.ts +36 -4
  59. package/components/table/table-empty-actions/table-empty-actions.component.d.ts +5 -0
  60. package/components/table/table-header-checkbox/table-header-checkbox.component.d.ts +5 -11
  61. package/components/table/table-row-checkbox/table-row-checkbox.component.d.ts +5 -11
  62. package/components/toast/toast-message/toast-message.component.d.ts +42 -1
  63. package/components/tooltip/src/tooltip.component.d.ts +10 -1
  64. package/components/wizard/services/wizard.service.d.ts +5 -5
  65. package/components/wizard/wizard-marker/wizard-marker.component.d.ts +2 -3
  66. package/directives/auto-focus/public-api.d.ts +1 -1
  67. package/directives/auto-focus/src/{autofocus.directive.d.ts → auto-focus.directive.d.ts} +9 -15
  68. package/directives/click-outside/src/click-outside.directive.d.ts +1 -3
  69. package/directives/only-numbers/public-api.d.ts +6 -1
  70. package/directives/only-numbers/src/only-numbers.directive.d.ts +36 -0
  71. package/fesm2022/sixbell-telco-sdk-components-accordion.mjs +6 -9
  72. package/fesm2022/sixbell-telco-sdk-components-accordion.mjs.map +1 -1
  73. package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs +133 -51
  74. package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs.map +1 -1
  75. package/fesm2022/sixbell-telco-sdk-components-avatar.mjs +1 -1
  76. package/fesm2022/sixbell-telco-sdk-components-avatar.mjs.map +1 -1
  77. package/fesm2022/sixbell-telco-sdk-components-badge.mjs +2 -2
  78. package/fesm2022/sixbell-telco-sdk-components-badge.mjs.map +1 -1
  79. package/fesm2022/sixbell-telco-sdk-components-button.mjs +78 -4
  80. package/fesm2022/sixbell-telco-sdk-components-button.mjs.map +1 -1
  81. package/fesm2022/sixbell-telco-sdk-components-countdown.mjs.map +1 -1
  82. package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs +1 -1
  83. package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs.map +1 -1
  84. package/fesm2022/sixbell-telco-sdk-components-data-table.mjs +53 -27
  85. package/fesm2022/sixbell-telco-sdk-components-data-table.mjs.map +1 -1
  86. package/fesm2022/sixbell-telco-sdk-components-dialog.mjs +82 -12
  87. package/fesm2022/sixbell-telco-sdk-components-dialog.mjs.map +1 -1
  88. package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs +166 -13
  89. package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs.map +1 -1
  90. package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs +68 -24
  91. package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs.map +1 -1
  92. package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +283 -16
  93. package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
  94. package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs +12 -9
  95. package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs.map +1 -1
  96. package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs +151 -10
  97. package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs.map +1 -1
  98. package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs +69 -3
  99. package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs.map +1 -1
  100. package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs +96 -19
  101. package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs.map +1 -1
  102. package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs +15 -3
  103. package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs.map +1 -1
  104. package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs +2 -2
  105. package/fesm2022/sixbell-telco-sdk-components-forms-form-error.mjs.map +1 -1
  106. package/fesm2022/sixbell-telco-sdk-components-forms-form-group.mjs +159 -0
  107. package/fesm2022/sixbell-telco-sdk-components-forms-form-group.mjs.map +1 -0
  108. package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs +20 -0
  109. package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs.map +1 -0
  110. package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs +62 -6
  111. package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs.map +1 -1
  112. package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs +69 -3
  113. package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs.map +1 -1
  114. package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs +57 -4
  115. package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs.map +1 -1
  116. package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs +91 -20
  117. package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs.map +1 -1
  118. package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs +80 -6
  119. package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs.map +1 -1
  120. package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs +131 -13
  121. package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs.map +1 -1
  122. package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs +69 -3
  123. package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs.map +1 -1
  124. package/fesm2022/sixbell-telco-sdk-components-link.mjs +2 -7
  125. package/fesm2022/sixbell-telco-sdk-components-link.mjs.map +1 -1
  126. package/fesm2022/sixbell-telco-sdk-components-overlay.mjs +94 -42
  127. package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -1
  128. package/fesm2022/sixbell-telco-sdk-components-paginator.mjs +71 -10
  129. package/fesm2022/sixbell-telco-sdk-components-paginator.mjs.map +1 -1
  130. package/fesm2022/sixbell-telco-sdk-components-tab.mjs +5 -9
  131. package/fesm2022/sixbell-telco-sdk-components-tab.mjs.map +1 -1
  132. package/fesm2022/sixbell-telco-sdk-components-table.mjs +131 -47
  133. package/fesm2022/sixbell-telco-sdk-components-table.mjs.map +1 -1
  134. package/fesm2022/sixbell-telco-sdk-components-toast.mjs +69 -4
  135. package/fesm2022/sixbell-telco-sdk-components-toast.mjs.map +1 -1
  136. package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs +15 -3
  137. package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs.map +1 -1
  138. package/fesm2022/sixbell-telco-sdk-components-wizard.mjs +4 -4
  139. package/fesm2022/sixbell-telco-sdk-components-wizard.mjs.map +1 -1
  140. package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs +29 -49
  141. package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs.map +1 -1
  142. package/fesm2022/sixbell-telco-sdk-directives-click-outside.mjs +7 -10
  143. package/fesm2022/sixbell-telco-sdk-directives-click-outside.mjs.map +1 -1
  144. package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs +48 -17
  145. package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs.map +1 -1
  146. package/fesm2022/sixbell-telco-sdk-utils-date.mjs +1 -1
  147. package/fesm2022/sixbell-telco-sdk-utils-date.mjs.map +1 -1
  148. package/fesm2022/sixbell-telco-sdk-utils-pipes-to-bytes-extesion.mjs +1 -1
  149. package/fesm2022/sixbell-telco-sdk-utils-pipes-to-bytes-extesion.mjs.map +1 -1
  150. package/fesm2022/sixbell-telco-sdk-utils-runtime-config.mjs +339 -0
  151. package/fesm2022/sixbell-telco-sdk-utils-runtime-config.mjs.map +1 -0
  152. package/fesm2022/sixbell-telco-sdk-utils-sync.mjs +1 -1
  153. package/fesm2022/sixbell-telco-sdk-utils-sync.mjs.map +1 -1
  154. package/fesm2022/sixbell-telco-sdk-utils-theme.mjs +1062 -730
  155. package/fesm2022/sixbell-telco-sdk-utils-theme.mjs.map +1 -1
  156. package/fesm2022/sixbell-telco-sdk-utils-translation.mjs +350 -267
  157. package/fesm2022/sixbell-telco-sdk-utils-translation.mjs.map +1 -1
  158. package/package.json +55 -46
  159. package/utils/runtime-config/README.md +235 -0
  160. package/utils/{resource-loader → runtime-config}/index.d.ts +1 -1
  161. package/utils/runtime-config/public-api.d.ts +5 -0
  162. package/utils/runtime-config/src/http-client.d.ts +11 -0
  163. package/utils/runtime-config/src/runtime-config-loader.d.ts +23 -0
  164. package/utils/runtime-config/src/runtime-config-store.d.ts +11 -0
  165. package/utils/runtime-config/src/runtime-update-adapter.d.ts +15 -0
  166. package/utils/runtime-config/src/types.d.ts +66 -0
  167. package/utils/theme/README.md +324 -986
  168. package/utils/theme/public-api.d.ts +4 -4
  169. package/utils/theme/src/constants.d.ts +6 -12
  170. package/utils/theme/src/models/theme.d.ts +46 -173
  171. package/utils/theme/src/providers/theme.provider.d.ts +0 -10
  172. package/utils/theme/src/providers/theme.provider.types.d.ts +16 -15
  173. package/utils/theme/src/theme-assets/theme-assets.service.d.ts +16 -12
  174. package/utils/theme/src/theme-dom/theme-dom.service.d.ts +10 -3
  175. package/utils/theme/src/theme.service.d.ts +24 -27
  176. package/utils/theme/src/utils/utils.d.ts +2 -10
  177. package/utils/translation/README.md +170 -1390
  178. package/utils/translation/public-api.d.ts +3 -3
  179. package/utils/translation/src/constants.d.ts +7 -9
  180. package/utils/translation/src/models/translation.d.ts +9 -10
  181. package/utils/translation/src/providers/translation.provider.d.ts +17 -28
  182. package/utils/translation/src/providers/translation.provider.types.d.ts +13 -6
  183. package/utils/translation/src/translation-dom/translation-dom.service.d.ts +2 -3
  184. package/utils/translation/src/translation.service.d.ts +37 -9
  185. package/directives/only-numbers/src/just-numbers.directive.d.ts +0 -9
  186. package/fesm2022/sixbell-telco-sdk-utils-resource-loader.mjs +0 -1222
  187. package/fesm2022/sixbell-telco-sdk-utils-resource-loader.mjs.map +0 -1
  188. package/utils/resource-loader/README.md +0 -460
  189. package/utils/resource-loader/public-api.d.ts +0 -1
  190. package/utils/resource-loader/src/cache/index.d.ts +0 -2
  191. package/utils/resource-loader/src/cache/layers/factory.d.ts +0 -38
  192. package/utils/resource-loader/src/cache/layers/index.d.ts +0 -3
  193. package/utils/resource-loader/src/cache/layers/indexed-db-cache.d.ts +0 -118
  194. package/utils/resource-loader/src/cache/layers/local-storage-cache.d.ts +0 -86
  195. package/utils/resource-loader/src/cache/layers/memory-cache.d.ts +0 -76
  196. package/utils/resource-loader/src/cache/types.d.ts +0 -107
  197. package/utils/resource-loader/src/config/index.d.ts +0 -1
  198. package/utils/resource-loader/src/config/load-config.d.ts +0 -32
  199. package/utils/resource-loader/src/constants.d.ts +0 -38
  200. package/utils/resource-loader/src/http/index.d.ts +0 -1
  201. package/utils/resource-loader/src/http/retryable-client.d.ts +0 -43
  202. package/utils/resource-loader/src/index.d.ts +0 -1
  203. package/utils/resource-loader/src/resource-loader.d.ts +0 -67
  204. package/utils/resource-loader/src/types.d.ts +0 -152
  205. package/utils/resource-loader/src/utils/cache-validator.d.ts +0 -72
  206. package/utils/resource-loader/src/utils/helpers.d.ts +0 -15
  207. package/utils/resource-loader/src/utils/index.d.ts +0 -2
  208. package/utils/theme/src/providers/constants.d.ts +0 -7
  209. package/utils/translation/src/providers/constants.d.ts +0 -11
@@ -1,13 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Inject, Injectable, inject, signal, Optional, runInInjectionContext, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
3
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
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 { ResourceLoader } from '@sixbell-telco/sdk/utils/resource-loader';
8
- import { from, filter } from 'rxjs';
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 TRANSLATION_RESOURCE_LOADER_DEFAULTS = {
63
- cacheName: 'translation-resources',
64
- indexedDBName: TRANSLATION_INDEXED_DB_NAME,
65
- storageOrder: ['indexedDB', 'memory'],
66
- cacheTTL: 1000 * 60 * 60 * 12,
67
- freshOnNavigation: true,
68
- staleWhileRevalidate: true,
69
- useStaleOnError: true,
70
- revalidateOnFresh: true,
71
- retries: 3,
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
- constructor(rendererFactory, document) {
91
- this.rendererFactory = rendererFactory;
92
- this.document = document;
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: [{ token: i0.RendererFactory2 }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
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: () => [{ type: i0.RendererFactory2 }, { type: Document, decorators: [{
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 + ResourceLoader for multi-path loading
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
- translationResourceLoader = null;
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.asObservable();
271
+ onLanguageChange$ = this.translate.onLangChange;
272
272
  onLanguageChange = signal(0);
273
273
  ready = signal(false);
274
- constructor(translationConfig) {
275
- this.translationConfig = translationConfig;
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.translate.reloadLang(this.getCurrentLanguage());
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
- // Set signal to defaults, then restore from storage if available
334
- this.currentLanguage.set(this.config.defaultLanguage);
335
- this.initializeFromStorage();
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
- // CRITICAL: Force reload even if paths didn't change
359
- // This ensures fresh translations are loaded when config is updated at runtime
360
- const currentLang = this.getCurrentLanguage();
361
- this.logger.debug('setRuntimeConfig - forcing reload', {
362
- component: 'TranslationService',
363
- action: 'setRuntimeConfig',
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
- totalLoadedKeys: loadedKeys.length,
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, reject) => {
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
- reject(new Error(`Translation service not ready after ${timeoutMs}ms`));
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.pipe(takeUntilDestroyed()).subscribe({
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
- getOrCreateResourceLoader() {
546
- if (!this.translationResourceLoader) {
547
- this.translationResourceLoader = new ResourceLoader(TRANSLATION_RESOURCE_LOADER_DEFAULTS, this.logger);
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
- buildResourceOptions(overrides) {
552
- return {
553
- ...TRANSLATION_RESOURCE_LOADER_DEFAULTS,
554
- ...overrides,
555
- fallbackData: overrides?.fallbackData ?? {},
556
- parser: overrides?.parser ?? (async (response) => (await response.json())),
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 loader.load(url, {
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.data ?? {});
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 (typeof sourceValue === 'object' &&
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: [{ token: TRANSLATION_CONFIG_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
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: () => [{ type: undefined, decorators: [{
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['createTranslateLoader']().getTranslation(lang);
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: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
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
- }], ctorParameters: () => [{ type: i0.Injector }] });
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 loader - Custom loader instance (optional; uses default if not provided)
735
- * @property loaderOptions - Loader configuration options (cache TTL, retries, storage, etc.)
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: Always fetch fresh translations with fallback to cache
856
+ * // Default mode
740
857
  * provideRuntimeTranslation('/assets/config/translation-config.json')
741
858
  *
742
- * // Custom caching mode
859
+ * // SSE updates (optional)
743
860
  * provideRuntimeTranslation('/assets/config/translation-config.json', {
744
- * loaderOptions: {
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
- provide: TranslateLoader,
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 router = inject(Router);
809
- // First initialize the service (will use initial fallback config)
810
- translationService.init();
811
- // Helper to load config from file
812
- const loadConfigFromFile = async () => {
813
- try {
814
- const loader = options?.loader ?? new ResourceLoader(RUNTIME_TRANSLATION_LOADER_DEFAULTS, logger);
815
- const loaderOptions = buildRuntimeTranslationLoaderOptions(configPath, options?.loaderOptions);
816
- logger.debug('Loading runtime translation config file', { component: 'TranslationProvider', action: 'loadConfigFromFile', configPath });
817
- const result = await loader.load(configPath, loaderOptions);
818
- logger.debug('Runtime config loaded', {
819
- component: 'TranslationProvider',
820
- action: 'loadConfigFromFile',
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
- // Load config on init
842
- const initPromise = loadConfigFromFile();
843
- // Get the effective freshOnNavigation value (from overrides or defaults)
844
- const effectiveLoaderOptions = buildRuntimeTranslationLoaderOptions(configPath, options?.loaderOptions);
845
- const shouldUsesFreshOnNavigation = effectiveLoaderOptions.freshOnNavigation ?? false;
846
- // Also reload config on navigation if freshOnNavigation is enabled
847
- if (shouldUsesFreshOnNavigation) {
848
- router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe(() => {
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
- // CRITICAL: Wait for translations to be fully loaded before returning
853
- // This ensures the ready() signal is true before components render
854
- return initPromise.then(async () => {
855
- try {
856
- await translationService.waitForTranslations(5000);
857
- logger.debug('Translation initialization complete', {
858
- component: 'TranslationProvider',
859
- action: 'init',
860
- isReady: translationService.ready(),
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
- catch (error) {
864
- logger.warn('Translation service did not reach ready state', {
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, TRANSLATION_CONFIG_TOKEN, TRANSLATION_STORAGE_LANGUAGE_KEY, TRANSLATION_STORAGE_NAMESPACE, TranslationDomService, TranslationService, TranslationStorageService, createLanguage, extendDefaultLanguages, provideRuntimeTranslation, provideTranslation };
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