@sixbell-telco/sdk 4.2.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +108 -1
- package/README.md +98 -66
- package/_index.css +2 -1586
- package/components/accordion/accordion-item/accordion-item.component.d.ts +1 -1
- package/components/alert/README.md +27 -0
- package/components/alert/index.d.ts +5 -0
- package/components/alert/public-api.d.ts +1 -0
- package/components/alert/src/alert.component.d.ts +85 -0
- package/components/audio-player/audio-timeline/audio-timeline.component.d.ts +1 -1
- package/components/audio-player/button-play/button-play.component.d.ts +7 -7
- package/components/audio-player/src/audio-player.component.d.ts +2 -2
- package/components/audio-player/volume-control/volume-control.component.d.ts +1 -1
- package/components/avatar/README.md +1 -0
- package/components/avatar/src/avatar.component.d.ts +2 -2
- package/components/badge/src/badge.component.d.ts +4 -4
- package/components/button/README.md +5 -4
- package/components/button/src/button.component.d.ts +38 -16
- package/components/card/README.md +2 -0
- package/components/card/card-footer/card-footer.component.d.ts +37 -2
- package/components/card/card-section-group/card-section-group.component.d.ts +1 -1
- package/components/card/src/card.component.d.ts +6 -6
- package/components/countdown/src/countdown.component.d.ts +4 -4
- package/components/data-table/README.md +26 -0
- package/components/data-table/expandable/expandable.component.d.ts +4 -4
- package/components/data-table/sortable-header/sortable-header.component.d.ts +1 -1
- package/components/data-table/src/data-table.component.d.ts +15 -8
- package/components/data-table/sub-component-toggle/sub-component-toggle.component.d.ts +1 -1
- package/components/description-list/README.md +27 -0
- package/components/description-list/index.d.ts +5 -0
- package/components/description-list/public-api.d.ts +1 -0
- package/components/description-list/src/description-list.component.d.ts +90 -0
- package/components/dialog/README.md +10 -6
- package/components/dialog/dialog-actions/dialog-actions.component.d.ts +4 -0
- package/components/dialog/src/dialog.component.d.ts +27 -6
- package/components/dialog/src/fullscreen-block-scroll-strategy.d.ts +31 -0
- package/components/divider/src/divider.component.d.ts +1 -1
- package/components/dropdown/README.md +2 -2
- package/components/dropdown/dropdown-chevron/dropdown-chevron.component.d.ts +1 -1
- package/components/dropdown/dropdown-content/dropdown-content.component.d.ts +1 -1
- package/components/dropdown/dropdown-item/dropdown-item.component.d.ts +4 -4
- package/components/dropdown/dropdown-item-checkbox/dropdown-item-checkbox.component.d.ts +5 -5
- package/components/dropdown/dropdown-item-radio/dropdown-item-radio.component.d.ts +5 -5
- package/components/dropdown/dropdown-trigger/dropdown-trigger.component.d.ts +11 -14
- package/components/dropdown-menu/README.md +2 -2
- package/components/dropdown-menu/bar/dropdown-menu-bar/dropdown-menu-bar.component.d.ts +1 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-content/dropdown-menu-bar-content.component.d.ts +6 -2
- package/components/dropdown-menu/bar/dropdown-menu-bar-item/dropdown-menu-bar-item.component.d.ts +3 -3
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-checkbox/dropdown-menu-bar-item-checkbox.component.d.ts +4 -4
- package/components/dropdown-menu/bar/dropdown-menu-bar-item-radio/dropdown-menu-bar-item-radio.component.d.ts +4 -4
- package/components/dropdown-menu/bar/dropdown-menu-bar-sub-trigger/dropdown-menu-bar-sub-trigger.component.d.ts +3 -1
- package/components/dropdown-menu/bar/dropdown-menu-bar-trigger/dropdown-menu-bar-trigger.component.d.ts +3 -1
- package/components/dropdown-menu/context/dropdown-context-menu-trigger/dropdown-context-menu-trigger.component.d.ts +2 -1
- package/components/dropdown-menu/dropdown-menu-chevron/dropdown-menu-chevron.component.d.ts +1 -1
- package/components/dropdown-menu/src/dropdown-menu-content/dropdown-menu-content.component.d.ts +2 -0
- package/components/dropdown-menu/src/dropdown-menu-item/dropdown-menu-item.component.d.ts +3 -3
- package/components/dropdown-menu/src/dropdown-menu-sub-content/dropdown-menu-sub-content.component.d.ts +2 -0
- package/components/dropdown-menu/src/dropdown-menu-sub-trigger/dropdown-menu-sub-trigger.component.d.ts +2 -1
- package/components/dropdown-menu/src/dropdown-menu-trigger/dropdown-menu-trigger.component.d.ts +1 -0
- package/components/empty-state/README.md +40 -0
- package/components/empty-state/index.d.ts +5 -0
- package/components/empty-state/public-api.d.ts +1 -0
- package/components/empty-state/src/empty-state.component.d.ts +73 -0
- package/components/file-upload/file-dropzone/file-dropzone.component.d.ts +4 -4
- package/components/file-upload/file-uploader/file-uploader.component.d.ts +2 -2
- package/components/forms/checkbox/src/checkbox.component.d.ts +1 -1
- package/components/forms/combobox/README.md +2 -1
- package/components/forms/combobox/src/combobox.component.d.ts +31 -18
- package/components/forms/date-picker/src/date-picker.component.d.ts +16 -9
- package/components/forms/form-hint/README.md +29 -0
- package/components/forms/form-hint/index.d.ts +5 -0
- package/components/forms/form-hint/public-api.d.ts +1 -0
- package/components/forms/form-hint/src/form-hint.component.d.ts +38 -0
- package/components/forms/form-item/src/form-item.component.d.ts +45 -1
- package/components/forms/input/src/input.component.d.ts +15 -8
- package/components/forms/radio/src/radio.component.d.ts +1 -1
- package/components/forms/range/src/range.component.d.ts +18 -4
- package/components/forms/select/README.md +2 -1
- package/components/forms/select/src/select.component.d.ts +30 -16
- package/components/forms/switch/src/switch.component.d.ts +1 -1
- package/components/forms/textarea/src/textarea.component.d.ts +12 -5
- package/components/forms/toggle/src/toggle.component.d.ts +1 -1
- package/components/notification/src/notification.component.d.ts +1 -1
- package/components/overlay/README.md +7 -2
- package/components/overlay/overlay-trigger/overlay-trigger.component.d.ts +1 -1
- package/components/overlay/src/overlay.component.d.ts +10 -9
- package/components/paginator/components/pagination-item/pagination-item.component.d.ts +3 -3
- package/components/progress/src/progress.component.d.ts +1 -1
- package/components/segmented-button/README.md +57 -0
- package/components/segmented-button/index.d.ts +5 -0
- package/components/segmented-button/public-api.d.ts +1 -0
- package/components/segmented-button/src/segmented-button.component.d.ts +110 -0
- package/components/sonner/toaster/src/toaster.component.d.ts +3 -3
- package/components/tab/src/tab.component.d.ts +2 -2
- package/components/table/README.md +51 -3
- package/components/table/public-api.d.ts +1 -0
- package/components/table/src/table.component.d.ts +20 -13
- package/components/table/table-action/table-action.component.d.ts +14 -3
- package/components/table/table-actions/table-actions.component.d.ts +12 -1
- package/components/table/tokens/README.md +7 -0
- package/components/table/tokens/index.d.ts +5 -0
- package/components/table/tokens/public-api.d.ts +1 -0
- package/components/table/tokens/table-empty-state.d.ts +6 -0
- package/components/tooltip/README.md +25 -7
- package/components/tooltip/src/tooltip.component.d.ts +44 -12
- package/components/tree/README.md +73 -0
- package/components/tree/index.d.ts +5 -0
- package/components/tree/public-api.d.ts +1 -0
- package/components/tree/src/tree.component.d.ts +180 -0
- package/components/wizard/README.md +9 -0
- package/components/wizard/wizard-content/wizard-content.component.d.ts +1 -1
- package/components/wizard/wizard-wrapper/wizard-wrapper.component.d.ts +15 -6
- package/directives/auto-focus/src/auto-focus.directive.d.ts +1 -1
- package/directives/only-numbers/src/only-numbers.directive.d.ts +1 -1
- package/directives/truncate/README.md +49 -0
- package/directives/truncate/index.d.ts +5 -0
- package/directives/truncate/public-api.d.ts +1 -0
- package/directives/truncate/src/truncate-popover.component.d.ts +11 -0
- package/directives/truncate/src/truncate.directive.d.ts +96 -0
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-accordion.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-alert.mjs +152 -0
- package/fesm2022/sixbell-telco-sdk-components-alert.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs +15 -15
- package/fesm2022/sixbell-telco-sdk-components-audio-player.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-avatar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs +5 -5
- package/fesm2022/sixbell-telco-sdk-components-badge.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-button.mjs +53 -19
- package/fesm2022/sixbell-telco-sdk-components-button.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-card.mjs +61 -14
- package/fesm2022/sixbell-telco-sdk-components-card.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-countdown.mjs +5 -5
- package/fesm2022/sixbell-telco-sdk-components-countdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs +3 -3
- package/fesm2022/sixbell-telco-sdk-components-data-table-sub-component-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs +34 -33
- package/fesm2022/sixbell-telco-sdk-components-data-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-description-list.mjs +200 -0
- package/fesm2022/sixbell-telco-sdk-components-description-list.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs +128 -17
- package/fesm2022/sixbell-telco-sdk-components-dialog.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-divider.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-divider.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs +33 -24
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-bar.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-context.mjs +7 -3
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu-context.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs +25 -14
- package/fesm2022/sixbell-telco-sdk-components-dropdown-menu.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs +43 -72
- package/fesm2022/sixbell-telco-sdk-components-dropdown.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs +1 -1
- package/fesm2022/sixbell-telco-sdk-components-dual-list.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-empty-state.mjs +131 -0
- package/fesm2022/sixbell-telco-sdk-components-empty-state.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs +9 -9
- package/fesm2022/sixbell-telco-sdk-components-file-upload.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-checkbox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs +104 -72
- package/fesm2022/sixbell-telco-sdk-components-forms-combobox.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs +23 -12
- package/fesm2022/sixbell-telco-sdk-components-forms-date-picker.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-form-hint.mjs +81 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-hint.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs +45 -3
- package/fesm2022/sixbell-telco-sdk-components-forms-form-item.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs +27 -13
- package/fesm2022/sixbell-telco-sdk-components-forms-input.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-radio.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs +29 -7
- package/fesm2022/sixbell-telco-sdk-components-forms-range.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs +84 -56
- package/fesm2022/sixbell-telco-sdk-components-forms-select.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-switch.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs +27 -22
- package/fesm2022/sixbell-telco-sdk-components-forms-textarea.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-forms-toggle.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-notification.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-notification.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs +41 -79
- package/fesm2022/sixbell-telco-sdk-components-overlay.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-paginator.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-progress.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-components-progress.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-segmented-button.mjs +329 -0
- package/fesm2022/sixbell-telco-sdk-components-segmented-button.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-sonner-toaster.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-sonner-toaster.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-sonner.mjs +4 -4
- package/fesm2022/sixbell-telco-sdk-components-sonner.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs +3 -3
- package/fesm2022/sixbell-telco-sdk-components-tab.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-table-tokens.mjs +14 -0
- package/fesm2022/sixbell-telco-sdk-components-table-tokens.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-table.mjs +63 -32
- package/fesm2022/sixbell-telco-sdk-components-table.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs +187 -75
- package/fesm2022/sixbell-telco-sdk-components-tooltip.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-components-tree.mjs +478 -0
- package/fesm2022/sixbell-telco-sdk-components-tree.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs +18 -9
- package/fesm2022/sixbell-telco-sdk-components-wizard.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-directives-auto-focus.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs +2 -2
- package/fesm2022/sixbell-telco-sdk-directives-only-numbers.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-directives-truncate.mjs +339 -0
- package/fesm2022/sixbell-telco-sdk-directives-truncate.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-layouts.mjs +69 -41
- package/fesm2022/sixbell-telco-sdk-layouts.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs +15 -2
- package/fesm2022/sixbell-telco-sdk-utils-date.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-mfe.mjs +87 -2
- package/fesm2022/sixbell-telco-sdk-utils-mfe.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-popover-motion.mjs +186 -0
- package/fesm2022/sixbell-telco-sdk-utils-popover-motion.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs +234 -4
- package/fesm2022/sixbell-telco-sdk-utils-theme.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-translation-testing.mjs +203 -0
- package/fesm2022/sixbell-telco-sdk-utils-translation-testing.mjs.map +1 -0
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs +129 -14
- package/fesm2022/sixbell-telco-sdk-utils-translation.mjs.map +1 -1
- package/fesm2022/sixbell-telco-sdk-utils-unsaved-changes.mjs +150 -0
- package/fesm2022/sixbell-telco-sdk-utils-unsaved-changes.mjs.map +1 -0
- package/i18n/sdk/en.json +224 -0
- package/i18n/sdk/es.json +224 -0
- package/i18n/sdk/pt.json +224 -0
- package/layouts/README.md +18 -11
- package/layouts/public-api.d.ts +1 -1
- package/layouts/src/app-layout/app-layout.component.d.ts +11 -8
- package/layouts/src/layout.config.d.ts +1 -1
- package/layouts/src/menu/menu-active.d.ts +2 -1
- package/layouts/src/menu/menu-url.d.ts +2 -0
- package/layouts/src/navbar/navbar.component.d.ts +5 -5
- package/layouts/src/page-banner/page-banner.component.d.ts +19 -2
- package/layouts/src/side-menu/side-menu.component.d.ts +2 -2
- package/layouts/src/user-menu/user-menu.component.d.ts +5 -5
- package/package.json +64 -20
- package/src/_index.css +1701 -0
- package/utils/mfe/README.md +1 -0
- package/utils/mfe/src/hoist-property-rules.d.ts +13 -0
- package/utils/mfe/src/mfe-shadow-shell.component.d.ts +3 -0
- package/utils/popover-motion/README.md +38 -0
- package/utils/popover-motion/index.d.ts +5 -0
- package/utils/popover-motion/public-api.d.ts +2 -0
- package/utils/popover-motion/src/popover-menu-motion.d.ts +37 -0
- package/utils/popover-motion/src/popover-motion.d.ts +31 -0
- package/utils/theme/README.md +94 -1
- package/utils/theme/public-api.d.ts +2 -1
- package/utils/theme/src/models/theme.d.ts +32 -0
- package/utils/theme/src/overlay/theme-overlay.d.ts +33 -0
- package/utils/theme/src/providers/theme.provider.types.d.ts +7 -0
- package/utils/translation/README.md +63 -0
- package/utils/translation/src/translation.service.d.ts +24 -0
- package/utils/translation/testing/index.d.ts +5 -0
- package/utils/translation/testing/public-api.d.ts +2 -0
- package/utils/translation/testing/src/translation-testing.d.ts +96 -0
- package/utils/unsaved-changes/README.md +33 -0
- package/utils/unsaved-changes/index.d.ts +5 -0
- package/utils/unsaved-changes/public-api.d.ts +1 -0
- package/utils/unsaved-changes/src/unsaved-changes-dialog.component.d.ts +24 -0
- package/utils/unsaved-changes/src/unsaved-changes.d.ts +50 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, signal, computed, DestroyRef, Injectable } from '@angular/core';
|
|
3
|
+
import { TranslateService, provideTranslateService, TranslateLoader } from '@ngx-translate/core';
|
|
4
|
+
import { extendDefaultLanguages, TranslationService } from '@sixbell-telco/sdk/utils/translation';
|
|
5
|
+
import { of } from 'rxjs';
|
|
6
|
+
|
|
7
|
+
const TRANSLATION_TESTING_OPTIONS = new InjectionToken('TRANSLATION_TESTING_OPTIONS');
|
|
8
|
+
/** Serves translations from memory, synchronously, so `use()` switches language within the same tick. */
|
|
9
|
+
class InMemoryTranslateLoader {
|
|
10
|
+
translations;
|
|
11
|
+
constructor(translations) {
|
|
12
|
+
this.translations = translations;
|
|
13
|
+
}
|
|
14
|
+
getTranslation(lang) {
|
|
15
|
+
return of(this.translations[lang] ?? {});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const resolveLang = (options) => options.lang ?? Object.keys(options.translations)[0] ?? 'en';
|
|
19
|
+
const resolveLanguages = (options) => {
|
|
20
|
+
if (options.languages) {
|
|
21
|
+
return [...options.languages];
|
|
22
|
+
}
|
|
23
|
+
const known = extendDefaultLanguages([]);
|
|
24
|
+
const codes = Object.keys(options.translations);
|
|
25
|
+
return (codes.length ? codes : [resolveLang(options)]).map((code) => known.find((language) => language.code === code) ?? { code, name: code });
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Test double for the SDK `TranslationService` with its full public API. It delegates to the real ngx-translate
|
|
29
|
+
* `TranslateService`, so `instant()` reads the active language when it is called, `{{param}}` placeholders are
|
|
30
|
+
* interpolated, and switching language emits `onLangChange`. Runtime-config methods resolve without network access.
|
|
31
|
+
*/
|
|
32
|
+
class FakeTranslationService {
|
|
33
|
+
translate = inject(TranslateService);
|
|
34
|
+
options = inject(TRANSLATION_TESTING_OPTIONS);
|
|
35
|
+
translationTick = signal(0);
|
|
36
|
+
languages = resolveLanguages(this.options);
|
|
37
|
+
defaultLanguage = resolveLang(this.options);
|
|
38
|
+
localeConfig = signal(this.options.locale ?? {});
|
|
39
|
+
updateAvailable = signal(false);
|
|
40
|
+
lastRefreshFailed = signal(false);
|
|
41
|
+
currentLanguage = signal(this.translate.getCurrentLang() ?? this.defaultLanguage);
|
|
42
|
+
currentLocale = computed(() => this.resolveLocale(this.currentLanguage()));
|
|
43
|
+
onLanguageChange$ = this.translate.onLangChange;
|
|
44
|
+
onLanguageChange = signal(0);
|
|
45
|
+
ready = signal(true);
|
|
46
|
+
changes = computed(() => this.translationTick());
|
|
47
|
+
constructor() {
|
|
48
|
+
const subscription = this.translate.onLangChange.subscribe(({ lang }) => {
|
|
49
|
+
this.currentLanguage.set(lang);
|
|
50
|
+
this.onLanguageChange.update((value) => value + 1);
|
|
51
|
+
this.translationTick.update((value) => value + 1);
|
|
52
|
+
});
|
|
53
|
+
inject(DestroyRef).onDestroy(() => subscription.unsubscribe());
|
|
54
|
+
}
|
|
55
|
+
configure(config) {
|
|
56
|
+
let languages = [...this.languages, ...(config.additionalLanguages ?? [])];
|
|
57
|
+
if (config.excludeLanguages) {
|
|
58
|
+
languages = languages.filter((language) => !config.excludeLanguages?.includes(language.code));
|
|
59
|
+
}
|
|
60
|
+
this.languages = languages;
|
|
61
|
+
if (config.defaultLang) {
|
|
62
|
+
this.defaultLanguage = config.defaultLang;
|
|
63
|
+
}
|
|
64
|
+
if (config.locale) {
|
|
65
|
+
this.localeConfig.set(config.locale);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async setRuntimeConfig(config) {
|
|
69
|
+
this.configure(config);
|
|
70
|
+
this.setLanguage(this.currentLanguage());
|
|
71
|
+
this.translationTick.update((value) => value + 1);
|
|
72
|
+
}
|
|
73
|
+
enablePrefetch() {
|
|
74
|
+
// Translations are in memory; there is nothing to prefetch.
|
|
75
|
+
}
|
|
76
|
+
async refreshInactiveLanguages() {
|
|
77
|
+
// Translations are in memory; there is nothing to reload.
|
|
78
|
+
}
|
|
79
|
+
setLanguage(lang) {
|
|
80
|
+
if (!lang) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const target = this.getAvailableLanguageCodes().includes(lang) ? lang : this.defaultLanguage;
|
|
84
|
+
this.translate.use(target);
|
|
85
|
+
}
|
|
86
|
+
getCurrentLanguage() {
|
|
87
|
+
return this.translate.getCurrentLang() ?? this.defaultLanguage;
|
|
88
|
+
}
|
|
89
|
+
getCurrentLocale() {
|
|
90
|
+
return this.currentLocale();
|
|
91
|
+
}
|
|
92
|
+
getLocaleConfig() {
|
|
93
|
+
return this.localeConfig();
|
|
94
|
+
}
|
|
95
|
+
resolveLocale(language) {
|
|
96
|
+
const normalized = language?.trim();
|
|
97
|
+
if (normalized) {
|
|
98
|
+
return this.localeConfig().languageToLocale?.[normalized] ?? normalized;
|
|
99
|
+
}
|
|
100
|
+
return this.localeConfig().defaultLocale ?? this.defaultLanguage;
|
|
101
|
+
}
|
|
102
|
+
getAvailableLanguages() {
|
|
103
|
+
return [...this.translate.getLangs()];
|
|
104
|
+
}
|
|
105
|
+
getDefaultLanguage() {
|
|
106
|
+
return this.defaultLanguage;
|
|
107
|
+
}
|
|
108
|
+
instant(key, params) {
|
|
109
|
+
return this.translate.instant(key, params);
|
|
110
|
+
}
|
|
111
|
+
get(key, params) {
|
|
112
|
+
return this.translate.get(key, params);
|
|
113
|
+
}
|
|
114
|
+
stream(key, params) {
|
|
115
|
+
return this.translate.stream(key, params);
|
|
116
|
+
}
|
|
117
|
+
getAvailableLanguagesConfig() {
|
|
118
|
+
return this.languages;
|
|
119
|
+
}
|
|
120
|
+
getAvailableLanguageCodes() {
|
|
121
|
+
return this.languages.map((language) => language.code);
|
|
122
|
+
}
|
|
123
|
+
getLanguageByCode(code) {
|
|
124
|
+
return this.languages.find((language) => language.code === code);
|
|
125
|
+
}
|
|
126
|
+
getLanguageDisplayName(code) {
|
|
127
|
+
return this.getLanguageByCode(code)?.name ?? code.toUpperCase();
|
|
128
|
+
}
|
|
129
|
+
getLocalizedLanguageName(code) {
|
|
130
|
+
const key = `sdk.language.languages.${code}`;
|
|
131
|
+
const translated = this.translate.instant(key);
|
|
132
|
+
return translated && translated !== key ? translated : this.getLanguageDisplayName(code);
|
|
133
|
+
}
|
|
134
|
+
isReady() {
|
|
135
|
+
return this.ready.asReadonly();
|
|
136
|
+
}
|
|
137
|
+
async waitForTranslations() {
|
|
138
|
+
// Translations are in memory and always ready.
|
|
139
|
+
}
|
|
140
|
+
init() {
|
|
141
|
+
// The constructor already follows language changes.
|
|
142
|
+
}
|
|
143
|
+
async applyRuntimeConfig(result) {
|
|
144
|
+
await this.setRuntimeConfig(result.data);
|
|
145
|
+
}
|
|
146
|
+
setRuntimeLoader() {
|
|
147
|
+
this.updateAvailable.set(false);
|
|
148
|
+
this.lastRefreshFailed.set(false);
|
|
149
|
+
}
|
|
150
|
+
async checkForTranslationUpdates(_loader, event) {
|
|
151
|
+
if (!event?.resource || event.resource === 'translation' || event.resource === 'both') {
|
|
152
|
+
this.updateAvailable.set(true);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async refreshTranslation() {
|
|
156
|
+
this.updateAvailable.set(false);
|
|
157
|
+
this.translationTick.update((value) => value + 1);
|
|
158
|
+
}
|
|
159
|
+
withTranslationsReady(fn) {
|
|
160
|
+
this.changes();
|
|
161
|
+
return this.ready() ? fn() : undefined;
|
|
162
|
+
}
|
|
163
|
+
createTranslateLoader() {
|
|
164
|
+
return new InMemoryTranslateLoader(this.options.translations);
|
|
165
|
+
}
|
|
166
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FakeTranslationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
167
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FakeTranslationService });
|
|
168
|
+
}
|
|
169
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FakeTranslationService, decorators: [{
|
|
170
|
+
type: Injectable
|
|
171
|
+
}], ctorParameters: () => [] });
|
|
172
|
+
/**
|
|
173
|
+
* Providers for specs: the real ngx-translate `TranslateService` fed from memory, and `FakeTranslationService`
|
|
174
|
+
* for the SDK `TranslationService`. Switch language with either service and assert the re-rendered labels.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* TestBed.configureTestingModule({
|
|
179
|
+
* providers: [provideTranslationTesting({ translations: { en: { greet: 'Hi {{name}}' }, es: { greet: 'Hola {{name}}' } } })],
|
|
180
|
+
* });
|
|
181
|
+
* TestBed.inject(TranslationService).setLanguage('es');
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
function provideTranslationTesting(options) {
|
|
185
|
+
const lang = resolveLang(options);
|
|
186
|
+
return [
|
|
187
|
+
{ provide: TRANSLATION_TESTING_OPTIONS, useValue: options },
|
|
188
|
+
provideTranslateService({
|
|
189
|
+
lang,
|
|
190
|
+
fallbackLang: options.fallbackLang ?? lang,
|
|
191
|
+
loader: { provide: TranslateLoader, useValue: new InMemoryTranslateLoader(options.translations) },
|
|
192
|
+
}),
|
|
193
|
+
FakeTranslationService,
|
|
194
|
+
{ provide: TranslationService, useExisting: FakeTranslationService },
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Generated bundle index. Do not edit.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
export { FakeTranslationService, InMemoryTranslateLoader, TRANSLATION_TESTING_OPTIONS, provideTranslationTesting };
|
|
203
|
+
//# sourceMappingURL=sixbell-telco-sdk-utils-translation-testing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sixbell-telco-sdk-utils-translation-testing.mjs","sources":["../../../projects/sdk/utils/translation/testing/src/translation-testing.ts","../../../projects/sdk/utils/translation/testing/sixbell-telco-sdk-utils-translation-testing.ts"],"sourcesContent":["import { computed, DestroyRef, inject, Injectable, InjectionToken, Provider, signal } from '@angular/core';\nimport { provideTranslateService, TranslateLoader, TranslateService, TranslationObject } from '@ngx-translate/core';\nimport type { RuntimeConfigLoader, RuntimeConfigLoadResult, RuntimeUpdateEvent } from '@sixbell-telco/sdk/utils/runtime-config';\nimport {\n\textendDefaultLanguages,\n\tLanguageDefinition,\n\tTranslationConfig,\n\tTranslationLocaleConfig,\n\tTranslationService,\n} from '@sixbell-telco/sdk/utils/translation';\nimport { Observable, of } from 'rxjs';\n\n/** Translations per language code, for example `{ en: { sdk: { close: 'Close' } }, es: { sdk: { close: 'Cerrar' } } }`. */\nexport type TranslationTestingBundles = Record<string, TranslationObject>;\n\nexport interface TranslationTestingOptions {\n\t/** In-memory translations per language. */\n\ttranslations: TranslationTestingBundles;\n\t/** Active language at start. Defaults to the first language in `translations`, or `en`. */\n\tlang?: string;\n\t/** Language used for keys missing in the active one. Defaults to `lang`. */\n\tfallbackLang?: string;\n\t/** Languages `TranslationService` reports as available. Defaults to the languages in `translations`. */\n\tlanguages?: LanguageDefinition[];\n\t/** Locale mapping returned by `TranslationService.resolveLocale()`. */\n\tlocale?: TranslationLocaleConfig;\n}\n\nexport const TRANSLATION_TESTING_OPTIONS = new InjectionToken<TranslationTestingOptions>('TRANSLATION_TESTING_OPTIONS');\n\n/** Serves translations from memory, synchronously, so `use()` switches language within the same tick. */\nexport class InMemoryTranslateLoader implements TranslateLoader {\n\tconstructor(private readonly translations: TranslationTestingBundles) {}\n\n\tgetTranslation(lang: string): Observable<TranslationObject> {\n\t\treturn of(this.translations[lang] ?? {});\n\t}\n}\n\ntype TranslationServiceApi = { [K in keyof TranslationService]: TranslationService[K] };\n\nconst resolveLang = (options: TranslationTestingOptions): string => options.lang ?? Object.keys(options.translations)[0] ?? 'en';\n\nconst resolveLanguages = (options: TranslationTestingOptions): LanguageDefinition[] => {\n\tif (options.languages) {\n\t\treturn [...options.languages];\n\t}\n\tconst known = extendDefaultLanguages([]);\n\tconst codes = Object.keys(options.translations);\n\treturn (codes.length ? codes : [resolveLang(options)]).map((code) => known.find((language) => language.code === code) ?? { code, name: code });\n};\n\n/**\n * Test double for the SDK `TranslationService` with its full public API. It delegates to the real ngx-translate\n * `TranslateService`, so `instant()` reads the active language when it is called, `{{param}}` placeholders are\n * interpolated, and switching language emits `onLangChange`. Runtime-config methods resolve without network access.\n */\n@Injectable()\nexport class FakeTranslationService implements TranslationServiceApi {\n\tprivate readonly translate = inject(TranslateService);\n\tprivate readonly options = inject(TRANSLATION_TESTING_OPTIONS);\n\tprivate readonly translationTick = signal(0);\n\tprivate languages = resolveLanguages(this.options);\n\tprivate defaultLanguage = resolveLang(this.options);\n\tprivate readonly localeConfig = signal<TranslationLocaleConfig>(this.options.locale ?? {});\n\n\tpublic readonly updateAvailable = signal(false);\n\tpublic readonly lastRefreshFailed = signal(false);\n\tpublic readonly currentLanguage = signal<string>(this.translate.getCurrentLang() ?? this.defaultLanguage);\n\tpublic readonly currentLocale = computed(() => this.resolveLocale(this.currentLanguage()));\n\tpublic readonly onLanguageChange$ = this.translate.onLangChange;\n\tpublic readonly onLanguageChange = signal<number>(0);\n\tpublic readonly ready = signal(true);\n\tpublic readonly changes = computed(() => this.translationTick());\n\n\tconstructor() {\n\t\tconst subscription = this.translate.onLangChange.subscribe(({ lang }) => {\n\t\t\tthis.currentLanguage.set(lang);\n\t\t\tthis.onLanguageChange.update((value) => value + 1);\n\t\t\tthis.translationTick.update((value) => value + 1);\n\t\t});\n\t\tinject(DestroyRef).onDestroy(() => subscription.unsubscribe());\n\t}\n\n\tconfigure(config: TranslationConfig): void {\n\t\tlet languages = [...this.languages, ...(config.additionalLanguages ?? [])];\n\t\tif (config.excludeLanguages) {\n\t\t\tlanguages = languages.filter((language) => !config.excludeLanguages?.includes(language.code));\n\t\t}\n\t\tthis.languages = languages;\n\t\tif (config.defaultLang) {\n\t\t\tthis.defaultLanguage = config.defaultLang;\n\t\t}\n\t\tif (config.locale) {\n\t\t\tthis.localeConfig.set(config.locale);\n\t\t}\n\t}\n\n\tasync setRuntimeConfig(config: TranslationConfig): Promise<void> {\n\t\tthis.configure(config);\n\t\tthis.setLanguage(this.currentLanguage());\n\t\tthis.translationTick.update((value) => value + 1);\n\t}\n\n\tenablePrefetch(): void {\n\t\t// Translations are in memory; there is nothing to prefetch.\n\t}\n\n\tasync refreshInactiveLanguages(): Promise<void> {\n\t\t// Translations are in memory; there is nothing to reload.\n\t}\n\n\tsetLanguage(lang: string): void {\n\t\tif (!lang) {\n\t\t\treturn;\n\t\t}\n\t\tconst target = this.getAvailableLanguageCodes().includes(lang) ? lang : this.defaultLanguage;\n\t\tthis.translate.use(target);\n\t}\n\n\tgetCurrentLanguage(): string {\n\t\treturn this.translate.getCurrentLang() ?? this.defaultLanguage;\n\t}\n\n\tgetCurrentLocale(): string {\n\t\treturn this.currentLocale();\n\t}\n\n\tgetLocaleConfig(): TranslationLocaleConfig {\n\t\treturn this.localeConfig();\n\t}\n\n\tresolveLocale(language?: string | null): string {\n\t\tconst normalized = language?.trim();\n\t\tif (normalized) {\n\t\t\treturn this.localeConfig().languageToLocale?.[normalized] ?? normalized;\n\t\t}\n\t\treturn this.localeConfig().defaultLocale ?? this.defaultLanguage;\n\t}\n\n\tgetAvailableLanguages(): string[] {\n\t\treturn [...this.translate.getLangs()];\n\t}\n\n\tgetDefaultLanguage(): string {\n\t\treturn this.defaultLanguage;\n\t}\n\n\tinstant(key: string, params?: object): string {\n\t\treturn this.translate.instant(key, params);\n\t}\n\n\tget(key: string, params?: object) {\n\t\treturn this.translate.get(key, params);\n\t}\n\n\tstream(key: string, params?: object) {\n\t\treturn this.translate.stream(key, params);\n\t}\n\n\tgetAvailableLanguagesConfig(): LanguageDefinition[] {\n\t\treturn this.languages;\n\t}\n\n\tgetAvailableLanguageCodes(): string[] {\n\t\treturn this.languages.map((language) => language.code);\n\t}\n\n\tgetLanguageByCode(code: string): LanguageDefinition | undefined {\n\t\treturn this.languages.find((language) => language.code === code);\n\t}\n\n\tgetLanguageDisplayName(code: string): string {\n\t\treturn this.getLanguageByCode(code)?.name ?? code.toUpperCase();\n\t}\n\n\tgetLocalizedLanguageName(code: string): string {\n\t\tconst key = `sdk.language.languages.${code}`;\n\t\tconst translated = this.translate.instant(key);\n\t\treturn translated && translated !== key ? translated : this.getLanguageDisplayName(code);\n\t}\n\n\tisReady() {\n\t\treturn this.ready.asReadonly();\n\t}\n\n\tasync waitForTranslations(): Promise<void> {\n\t\t// Translations are in memory and always ready.\n\t}\n\n\tinit(): void {\n\t\t// The constructor already follows language changes.\n\t}\n\n\tasync applyRuntimeConfig(result: RuntimeConfigLoadResult<TranslationConfig>): Promise<void> {\n\t\tawait this.setRuntimeConfig(result.data);\n\t}\n\n\tsetRuntimeLoader(): void {\n\t\tthis.updateAvailable.set(false);\n\t\tthis.lastRefreshFailed.set(false);\n\t}\n\n\tasync checkForTranslationUpdates(_loader: RuntimeConfigLoader<TranslationConfig>, event?: RuntimeUpdateEvent): Promise<void> {\n\t\tif (!event?.resource || event.resource === 'translation' || event.resource === 'both') {\n\t\t\tthis.updateAvailable.set(true);\n\t\t}\n\t}\n\n\tasync refreshTranslation(): Promise<void> {\n\t\tthis.updateAvailable.set(false);\n\t\tthis.translationTick.update((value) => value + 1);\n\t}\n\n\twithTranslationsReady<T>(fn: () => T): T | undefined {\n\t\tthis.changes();\n\t\treturn this.ready() ? fn() : undefined;\n\t}\n\n\tcreateTranslateLoader(): TranslateLoader {\n\t\treturn new InMemoryTranslateLoader(this.options.translations);\n\t}\n}\n\n/**\n * Providers for specs: the real ngx-translate `TranslateService` fed from memory, and `FakeTranslationService`\n * for the SDK `TranslationService`. Switch language with either service and assert the re-rendered labels.\n *\n * @example\n * ```ts\n * TestBed.configureTestingModule({\n * providers: [provideTranslationTesting({ translations: { en: { greet: 'Hi {{name}}' }, es: { greet: 'Hola {{name}}' } } })],\n * });\n * TestBed.inject(TranslationService).setLanguage('es');\n * ```\n */\nexport function provideTranslationTesting(options: TranslationTestingOptions): Provider[] {\n\tconst lang = resolveLang(options);\n\treturn [\n\t\t{ provide: TRANSLATION_TESTING_OPTIONS, useValue: options },\n\t\tprovideTranslateService({\n\t\t\tlang,\n\t\t\tfallbackLang: options.fallbackLang ?? lang,\n\t\t\tloader: { provide: TranslateLoader, useValue: new InMemoryTranslateLoader(options.translations) },\n\t\t}),\n\t\tFakeTranslationService,\n\t\t{ provide: TranslationService, useExisting: FakeTranslationService },\n\t];\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;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CAAC;AAC/B,QAAA,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,KAAK,GAAG,CAAC,CAAC;IAClD;AAEA,IAAA,qBAAqB,CAAI,EAAW,EAAA;QACnC,IAAI,CAAC,OAAO,EAAE;AACd,QAAA,OAAO,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,GAAG,SAAS;IACvC;IAEA,qBAAqB,GAAA;QACpB,OAAO,IAAI,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;IAC9D;wGAnKY,sBAAsB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;4GAAtB,sBAAsB,EAAA,CAAA;;4FAAtB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBADlC;;AAuKD;;;;;;;;;;;AAWG;AACG,SAAU,yBAAyB,CAAC,OAAkC,EAAA;AAC3E,IAAA,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC;IACjC,OAAO;AACN,QAAA,EAAE,OAAO,EAAE,2BAA2B,EAAE,QAAQ,EAAE,OAAO,EAAE;AAC3D,QAAA,uBAAuB,CAAC;YACvB,IAAI;AACJ,YAAA,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI;AAC1C,YAAA,MAAM,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,uBAAuB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;SACjG,CAAC;QACF,sBAAsB;AACtB,QAAA,EAAE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,sBAAsB,EAAE;KACpE;AACF;;ACxPA;;AAEG;;;;"}
|
|
@@ -280,6 +280,8 @@ class TranslationService {
|
|
|
280
280
|
isUsingFallbackConfig = false;
|
|
281
281
|
prefetchLanguages = true;
|
|
282
282
|
isApplyingRuntimeConfig = false;
|
|
283
|
+
bundleRefreshId = 0;
|
|
284
|
+
inactiveRefreshIds = new Map();
|
|
283
285
|
runtimeHash = null;
|
|
284
286
|
runtimeLoader;
|
|
285
287
|
runtimeMeta;
|
|
@@ -332,17 +334,9 @@ class TranslationService {
|
|
|
332
334
|
action: 'configure',
|
|
333
335
|
newPaths,
|
|
334
336
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const url = `${normalized}${targetLang}.json`;
|
|
339
|
-
return this.fetchTranslation(url)
|
|
340
|
-
.then(() => undefined)
|
|
341
|
-
.catch(() => undefined);
|
|
342
|
-
});
|
|
343
|
-
Promise.all(preloadPromises).then(() => {
|
|
344
|
-
this.translate.reloadLang(targetLang);
|
|
345
|
-
});
|
|
337
|
+
if (!this.isApplyingRuntimeConfig) {
|
|
338
|
+
this.reloadForNewPaths(this.getCurrentLanguage());
|
|
339
|
+
}
|
|
346
340
|
}
|
|
347
341
|
this.config = {
|
|
348
342
|
availableLanguages,
|
|
@@ -395,7 +389,32 @@ class TranslationService {
|
|
|
395
389
|
}
|
|
396
390
|
this.currentLanguage.set(this.config.defaultLanguage);
|
|
397
391
|
}
|
|
392
|
+
reloadForNewPaths(targetLang) {
|
|
393
|
+
if (this.ready()) {
|
|
394
|
+
void this.refreshLoadedLanguage(targetLang);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const preloadPromises = this.currentTranslationPaths.map((path) => {
|
|
398
|
+
const normalized = path.endsWith('/') ? path : `${path}/`;
|
|
399
|
+
const url = `${normalized}${targetLang}.json`;
|
|
400
|
+
return this.fetchTranslation(url)
|
|
401
|
+
.then(() => undefined)
|
|
402
|
+
.catch(() => undefined);
|
|
403
|
+
});
|
|
404
|
+
Promise.all(preloadPromises).then(() => {
|
|
405
|
+
this.translate.reloadLang(targetLang);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Applies a runtime config. On the first load `ready()` stays false until the bundle is in. Once
|
|
410
|
+
* translations are ready, a refresh (e.g. a host adding a remote's i18n path) fetches the new bundle
|
|
411
|
+
* first and merges it over the loaded one, so `ready()` and the visible translations never drop.
|
|
412
|
+
*/
|
|
398
413
|
async setRuntimeConfig(config) {
|
|
414
|
+
if (this.ready()) {
|
|
415
|
+
await this.refreshRuntimeConfig(config);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
399
418
|
this.ready.set(false);
|
|
400
419
|
this.logger.debug('setRuntimeConfig - starting', {
|
|
401
420
|
component: 'TranslationService',
|
|
@@ -422,6 +441,104 @@ class TranslationService {
|
|
|
422
441
|
currentLanguage: this.getCurrentLanguage(),
|
|
423
442
|
});
|
|
424
443
|
}
|
|
444
|
+
async refreshRuntimeConfig(config) {
|
|
445
|
+
this.logger.debug('setRuntimeConfig - refreshing loaded translations', {
|
|
446
|
+
component: 'TranslationService',
|
|
447
|
+
action: 'setRuntimeConfig',
|
|
448
|
+
configPath: config.translationPaths,
|
|
449
|
+
});
|
|
450
|
+
const refresh = ++this.bundleRefreshId;
|
|
451
|
+
this.isApplyingRuntimeConfig = true;
|
|
452
|
+
let switchedLanguage = null;
|
|
453
|
+
try {
|
|
454
|
+
this.configure(config);
|
|
455
|
+
const targetLang = this.currentLanguage();
|
|
456
|
+
const languageUnchanged = this.translate.getCurrentLang() === targetLang;
|
|
457
|
+
const bundle = await this.fetchBundle(targetLang);
|
|
458
|
+
if (refresh !== this.bundleRefreshId) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (bundle) {
|
|
462
|
+
this.translate.setTranslation(targetLang, bundle, true);
|
|
463
|
+
}
|
|
464
|
+
if (this.currentLanguage() !== targetLang) {
|
|
465
|
+
switchedLanguage = this.currentLanguage();
|
|
466
|
+
}
|
|
467
|
+
else if (!languageUnchanged) {
|
|
468
|
+
this.applyLanguage();
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
this.translate.setFallbackLang(this.config.defaultLanguage);
|
|
472
|
+
if (bundle) {
|
|
473
|
+
this.announceRefreshedLanguage(targetLang);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (this.prefetchLanguages) {
|
|
477
|
+
this.prefetchRemainingLanguages();
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
finally {
|
|
481
|
+
if (refresh === this.bundleRefreshId) {
|
|
482
|
+
this.isApplyingRuntimeConfig = false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (switchedLanguage) {
|
|
486
|
+
void this.refreshLoadedLanguage(switchedLanguage);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async refreshLoadedLanguage(lang) {
|
|
490
|
+
const refresh = ++this.bundleRefreshId;
|
|
491
|
+
const bundle = await this.fetchBundle(lang);
|
|
492
|
+
if (!bundle || refresh !== this.bundleRefreshId) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
this.translate.setTranslation(lang, bundle, true);
|
|
496
|
+
if (this.currentLanguage() === lang) {
|
|
497
|
+
this.announceRefreshedLanguage(lang);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Re-selects the refreshed active language so `onLangChange` fires once, as it did when a refresh
|
|
502
|
+
* went through `use()`. Its listener ticks `changes()` and `onLanguageChange`; before `init()`
|
|
503
|
+
* subscribes, they are ticked here instead.
|
|
504
|
+
*/
|
|
505
|
+
announceRefreshedLanguage(lang) {
|
|
506
|
+
const tick = this.translationTick();
|
|
507
|
+
this.translate.use(lang);
|
|
508
|
+
if (this.translationTick() === tick) {
|
|
509
|
+
this.notifyTranslationsChanged();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Fetches `lang` through the active loader without touching the loaded bundle. Unlike
|
|
514
|
+
* `TranslateService.reloadLang`, nothing is deleted first, so `instant()` keeps returning the
|
|
515
|
+
* previous values until the caller merges the result, and a failed fetch returns `null`.
|
|
516
|
+
*/
|
|
517
|
+
async fetchBundle(lang) {
|
|
518
|
+
try {
|
|
519
|
+
return await firstValueFrom(this.translate.currentLoader.getTranslation(lang));
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
this.logger.error('Translation bundle refresh failed; keeping the loaded translations', error, {
|
|
523
|
+
component: 'TranslationService',
|
|
524
|
+
action: 'fetchBundle',
|
|
525
|
+
language: lang,
|
|
526
|
+
});
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async swapTranslations(lang) {
|
|
531
|
+
const refresh = (this.inactiveRefreshIds.get(lang) ?? 0) + 1;
|
|
532
|
+
this.inactiveRefreshIds.set(lang, refresh);
|
|
533
|
+
const bundle = await this.fetchBundle(lang);
|
|
534
|
+
if (bundle && refresh === this.inactiveRefreshIds.get(lang)) {
|
|
535
|
+
this.translate.setTranslation(lang, bundle, true);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
notifyTranslationsChanged() {
|
|
539
|
+
this.onLanguageChange.update((value) => value + 1);
|
|
540
|
+
this.translationTick.update((value) => value + 1);
|
|
541
|
+
}
|
|
425
542
|
enablePrefetch(enable) {
|
|
426
543
|
this.prefetchLanguages = enable;
|
|
427
544
|
}
|
|
@@ -458,7 +575,7 @@ class TranslationService {
|
|
|
458
575
|
return;
|
|
459
576
|
}
|
|
460
577
|
const available = new Set(this.getAvailableLanguageCodes());
|
|
461
|
-
await Promise.all(unique.filter((lang) => available.has(lang)).map((lang) =>
|
|
578
|
+
await Promise.all(unique.filter((lang) => available.has(lang)).map((lang) => this.swapTranslations(lang)));
|
|
462
579
|
}
|
|
463
580
|
async refreshInactiveLanguages() {
|
|
464
581
|
const current = this.currentLanguage();
|
|
@@ -489,8 +606,6 @@ class TranslationService {
|
|
|
489
606
|
this.updateAvailable.set(false);
|
|
490
607
|
await this.setRuntimeConfig(result.data);
|
|
491
608
|
this.ready.set(true);
|
|
492
|
-
const current = this.currentLanguage();
|
|
493
|
-
await this.reloadLanguages([current]);
|
|
494
609
|
void this.refreshInactiveLanguages();
|
|
495
610
|
}
|
|
496
611
|
catch (error) {
|