@tilde-nlp/ngx-common 8.1.44 → 8.1.45
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.
|
@@ -9821,6 +9821,96 @@ function provideUserConfig(options = {}) {
|
|
|
9821
9821
|
]);
|
|
9822
9822
|
}
|
|
9823
9823
|
|
|
9824
|
+
const LOCALIZATION_CONFIGURATION_TOKEN = new InjectionToken("Localization configuration");
|
|
9825
|
+
|
|
9826
|
+
class UILanguageService {
|
|
9827
|
+
#translateService = inject(TranslateService);
|
|
9828
|
+
#configuration = inject(LOCALIZATION_CONFIGURATION_TOKEN);
|
|
9829
|
+
#storage = inject(USER_CONFIG_STORAGE, { optional: true });
|
|
9830
|
+
get currentLanguage() {
|
|
9831
|
+
return this.#getFromStore();
|
|
9832
|
+
}
|
|
9833
|
+
get languages() {
|
|
9834
|
+
return this.#configuration.supportedLanguages ?? [];
|
|
9835
|
+
}
|
|
9836
|
+
/**
|
|
9837
|
+
* Initializes the language service by setting the default language and loading the user's preferred language from storage.
|
|
9838
|
+
*
|
|
9839
|
+
* - Sets the default language using `ngx-translate#setFallbackLang`.
|
|
9840
|
+
* - Attempts to retrieve the user's preferred language from storage (implementation details omitted for brevity).
|
|
9841
|
+
* - If a preferred language is found, calls `useLanguage` to set the current language.
|
|
9842
|
+
*/
|
|
9843
|
+
initialize() {
|
|
9844
|
+
this.#translateService.setFallbackLang(this.#getDefaultLanguage());
|
|
9845
|
+
this.#getFromStore()
|
|
9846
|
+
.pipe(tap(language => this.useLanguage(language))).subscribe();
|
|
9847
|
+
}
|
|
9848
|
+
/**
|
|
9849
|
+
* Sets the current language for the application.
|
|
9850
|
+
* @param languageCode - The desired language code.
|
|
9851
|
+
*
|
|
9852
|
+
* This method attempts to set the language using the provided `languageCode`.
|
|
9853
|
+
* If the language code is not supported (not present in the `languages` array),
|
|
9854
|
+
* it:
|
|
9855
|
+
* - Logs an error message.
|
|
9856
|
+
* - Falls back to the `defaultLanguage`.
|
|
9857
|
+
*
|
|
9858
|
+
* It updates UI language and stores the value in store.
|
|
9859
|
+
*/
|
|
9860
|
+
useLanguage(languageCode) {
|
|
9861
|
+
if (!this.languages.includes(languageCode)) {
|
|
9862
|
+
console.error(`Language with code '${languageCode}' not supported`);
|
|
9863
|
+
languageCode = this.#getDefaultLanguage();
|
|
9864
|
+
}
|
|
9865
|
+
this.#translateService.use(languageCode);
|
|
9866
|
+
this.#updateDocumentLangAttribute(languageCode);
|
|
9867
|
+
this.updateStore(languageCode);
|
|
9868
|
+
}
|
|
9869
|
+
updateStore(language) {
|
|
9870
|
+
if (!this.#storage) {
|
|
9871
|
+
return;
|
|
9872
|
+
}
|
|
9873
|
+
this.#storage.write({ language: { locale: language } }).subscribe();
|
|
9874
|
+
}
|
|
9875
|
+
#getFromStore() {
|
|
9876
|
+
const defaultLanguage = this.#getDefaultLanguage();
|
|
9877
|
+
if (!this.#storage) {
|
|
9878
|
+
return of(defaultLanguage);
|
|
9879
|
+
}
|
|
9880
|
+
return this.#storage.read()
|
|
9881
|
+
.pipe(map(config => config?.language.locale ?? defaultLanguage));
|
|
9882
|
+
}
|
|
9883
|
+
#getDefaultLanguage() {
|
|
9884
|
+
return this.#configuration.defaultLanguage;
|
|
9885
|
+
}
|
|
9886
|
+
#updateDocumentLangAttribute(lang) {
|
|
9887
|
+
const doc = document.documentElement;
|
|
9888
|
+
doc.lang = lang.split('-')[0];
|
|
9889
|
+
}
|
|
9890
|
+
static { this.ɵfac = function UILanguageService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || UILanguageService)(); }; }
|
|
9891
|
+
static { this.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: UILanguageService, factory: UILanguageService.ɵfac, providedIn: 'root' }); }
|
|
9892
|
+
}
|
|
9893
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(UILanguageService, [{
|
|
9894
|
+
type: Injectable,
|
|
9895
|
+
args: [{
|
|
9896
|
+
providedIn: 'root',
|
|
9897
|
+
}]
|
|
9898
|
+
}], null, null); })();
|
|
9899
|
+
|
|
9900
|
+
const provideLanguageService = (config) => {
|
|
9901
|
+
return makeEnvironmentProviders([
|
|
9902
|
+
{
|
|
9903
|
+
provide: LOCALIZATION_CONFIGURATION_TOKEN,
|
|
9904
|
+
useFactory: (...deps) => config.localizationConfiguration.useFactory(...deps),
|
|
9905
|
+
deps: config.localizationConfiguration.deps
|
|
9906
|
+
},
|
|
9907
|
+
provideAppInitializer(() => {
|
|
9908
|
+
const languageService = inject(UILanguageService);
|
|
9909
|
+
languageService.initialize();
|
|
9910
|
+
})
|
|
9911
|
+
]);
|
|
9912
|
+
};
|
|
9913
|
+
|
|
9824
9914
|
/*
|
|
9825
9915
|
* Public API Surface of ngx-common
|
|
9826
9916
|
*/
|
|
@@ -9829,5 +9919,5 @@ function provideUserConfig(options = {}) {
|
|
|
9829
9919
|
* Generated bundle index. Do not edit.
|
|
9830
9920
|
*/
|
|
9831
9921
|
|
|
9832
|
-
export { ALERT_CONFIGURATION_TOKEN, AccessibilityContrasts, AccessibilityDialogComponent, AccessibilityFontSizes, AccessibilityService, AccessibilityTextMagnifierService, AlertService, AnalyticsService, AuthHeadersHelper, COLLECTIONS_MENU, CUSTOM_TITLE_CONFIGURATION_TOKEN, ClickOutsideDirective, ClickOutsideModule, CloseButtonComponent, CloseButtonModule, CombinedCollection, CombinedCollectionTooltipKey, CompanyProductComponent, CompanyProductModule, Confirmation, ConfirmationModalComponent, ConfirmationModalModule, ConfirmationService, ConversionHelper, CookieConsentComponent, CustomPaginatorInernationalizationHelper, CustomTitleStrategyService, CustomTranslateLoader, DEFAULT_ACCESSIBILITY_PREFERENCES, DEFAULT_COOKIE_CONSENT_PREFERENCES, DEFAULT_USER_CONFIG, DEFAULT_USER_CONFIG_IFRAME_URL, DEFAULT_USER_CONFIG_OPTIONS, DISABLE_EXPORT_ATTRIBUTE_NAME, DOMService, DateAgoModule, DateAgoPipe, DomainTranslatePipe, DragAndDropDirective, DragAndDropModule, ERROR_CODES, EngineTermApiService, EngineTermCollectionScope, EngineTermCollectionSource, EngineTermCollectionStatus, EngineTermCollectionSubStatus, ExportFormat, ExtensionDialogComponent, ExtensionDialogModule, ExtensionDialogService, FILE_SIZE_UNIT, FileCategories, FileExtensionHelper, FileExtensions, FileSizeLabelPipe, FileTypeIcons, FileTypes, FileUploadComponent, FileUploadErrorTypeEnum, FileUploadModule, FilterBarComponent, FilterBarModule, FilterWithHighlightModule, FilterWithHighlightPipe, FooterComponent, FooterModule, GlobalMessageComponent, HashHelper, HtmlElementParseHelper, HtmlHelper, IconService, InlineMessageComponent, InlineMessageIconPosition, InlineMessageModule, InlineMessageType, LAST_USED_SYSTEM_LOCAL_STORAGE_KEY, LLMActions, LLMComponent, LLMModule, LLM_CONFIGURATION_TOKEN, LanguageTranslateModule, LanguageTranslatePipe, LanguageTranslateService, MatButtonLoadingDirective, MatButtonLoadingModule, MatomoService, MissingTranslationHandlerService, MissingTranslationHelper, MtCollectionStatus, MultiFunctionalTableComponent, MultiFunctionalTableModule, NewFeatureDialogWrapperComponent, NotificationMessageComponent, NotificationMessageModule, NotificationMessageType, NotificationService, OPEN_CLOSE_BTN_ICONS_TOKEN, ObjectLengthModule, ObjectLengthPipe, OpenCloseButtonComponent, OpenCloseButtonModule, OpenExtensionDialogComponent, Operations, PlausibleEventDirective, PlausibleHelper, PlausibleModule, ResolutionHelper, SCREEN_SIZE, SaveFileHelper, SelectLanguageDialogComponent, SidebarComponent, SidebarService, SortAlphabeticallyModule, SortAlphabeticallyPipe, SortByNumberPipe, SortDomainsPipe, SortHelper, SortLanguageListPipe, SortTranslationsByPropertyModule, SortTranslationsByPropertyPipe, SortTranslationsModule, SortTranslationsPipe, StatusDisplayComponent, StatusDisplayModule, SubscriptionComponent, SubscriptionPlan, SystemService, TerminologyApiService, TerminologyCollectionService, TerminologyComponent, TerminologyConfigService, TerminologyCreateCollectionComponent, TerminologyModule, TerminologyService, TextToSpeechComponent, TldLoaderComponent, TldLoaderModule, ToastComponent, ToastService, USER_CONFIG_IFRAME_NAME, USER_CONFIG_IFRAME_TARGET_ORIGIN, USER_CONFIG_MESSAGE_REQUEST, USER_CONFIG_MESSAGE_SNAPSHOT, USER_CONFIG_MESSAGE_UPDATE, USER_CONFIG_OPTIONS, USER_CONFIG_STORAGE, USER_CONFIG_STORAGE_KEY, USER_CONFIG_VERSION, UserConfigStrategy, createMetadata, getFileSizeLabel, isUserConfigOptionsFactoryProvider, provideCustomTitleStrategy, provideUserConfig, userConfigStorageFactory };
|
|
9922
|
+
export { ALERT_CONFIGURATION_TOKEN, AccessibilityContrasts, AccessibilityDialogComponent, AccessibilityFontSizes, AccessibilityService, AccessibilityTextMagnifierService, AlertService, AnalyticsService, AuthHeadersHelper, COLLECTIONS_MENU, CUSTOM_TITLE_CONFIGURATION_TOKEN, ClickOutsideDirective, ClickOutsideModule, CloseButtonComponent, CloseButtonModule, CombinedCollection, CombinedCollectionTooltipKey, CompanyProductComponent, CompanyProductModule, Confirmation, ConfirmationModalComponent, ConfirmationModalModule, ConfirmationService, ConversionHelper, CookieConsentComponent, CustomPaginatorInernationalizationHelper, CustomTitleStrategyService, CustomTranslateLoader, DEFAULT_ACCESSIBILITY_PREFERENCES, DEFAULT_COOKIE_CONSENT_PREFERENCES, DEFAULT_USER_CONFIG, DEFAULT_USER_CONFIG_IFRAME_URL, DEFAULT_USER_CONFIG_OPTIONS, DISABLE_EXPORT_ATTRIBUTE_NAME, DOMService, DateAgoModule, DateAgoPipe, DomainTranslatePipe, DragAndDropDirective, DragAndDropModule, ERROR_CODES, EngineTermApiService, EngineTermCollectionScope, EngineTermCollectionSource, EngineTermCollectionStatus, EngineTermCollectionSubStatus, ExportFormat, ExtensionDialogComponent, ExtensionDialogModule, ExtensionDialogService, FILE_SIZE_UNIT, FileCategories, FileExtensionHelper, FileExtensions, FileSizeLabelPipe, FileTypeIcons, FileTypes, FileUploadComponent, FileUploadErrorTypeEnum, FileUploadModule, FilterBarComponent, FilterBarModule, FilterWithHighlightModule, FilterWithHighlightPipe, FooterComponent, FooterModule, GlobalMessageComponent, HashHelper, HtmlElementParseHelper, HtmlHelper, IconService, InlineMessageComponent, InlineMessageIconPosition, InlineMessageModule, InlineMessageType, LAST_USED_SYSTEM_LOCAL_STORAGE_KEY, LLMActions, LLMComponent, LLMModule, LLM_CONFIGURATION_TOKEN, LOCALIZATION_CONFIGURATION_TOKEN, LanguageTranslateModule, LanguageTranslatePipe, LanguageTranslateService, MatButtonLoadingDirective, MatButtonLoadingModule, MatomoService, MissingTranslationHandlerService, MissingTranslationHelper, MtCollectionStatus, MultiFunctionalTableComponent, MultiFunctionalTableModule, NewFeatureDialogWrapperComponent, NotificationMessageComponent, NotificationMessageModule, NotificationMessageType, NotificationService, OPEN_CLOSE_BTN_ICONS_TOKEN, ObjectLengthModule, ObjectLengthPipe, OpenCloseButtonComponent, OpenCloseButtonModule, OpenExtensionDialogComponent, Operations, PlausibleEventDirective, PlausibleHelper, PlausibleModule, ResolutionHelper, SCREEN_SIZE, SaveFileHelper, SelectLanguageDialogComponent, SidebarComponent, SidebarService, SortAlphabeticallyModule, SortAlphabeticallyPipe, SortByNumberPipe, SortDomainsPipe, SortHelper, SortLanguageListPipe, SortTranslationsByPropertyModule, SortTranslationsByPropertyPipe, SortTranslationsModule, SortTranslationsPipe, StatusDisplayComponent, StatusDisplayModule, SubscriptionComponent, SubscriptionPlan, SystemService, TerminologyApiService, TerminologyCollectionService, TerminologyComponent, TerminologyConfigService, TerminologyCreateCollectionComponent, TerminologyModule, TerminologyService, TextToSpeechComponent, TldLoaderComponent, TldLoaderModule, ToastComponent, ToastService, UILanguageService, USER_CONFIG_IFRAME_NAME, USER_CONFIG_IFRAME_TARGET_ORIGIN, USER_CONFIG_MESSAGE_REQUEST, USER_CONFIG_MESSAGE_SNAPSHOT, USER_CONFIG_MESSAGE_UPDATE, USER_CONFIG_OPTIONS, USER_CONFIG_STORAGE, USER_CONFIG_STORAGE_KEY, USER_CONFIG_VERSION, UserConfigStrategy, createMetadata, getFileSizeLabel, isUserConfigOptionsFactoryProvider, provideCustomTitleStrategy, provideLanguageService, provideUserConfig, userConfigStorageFactory };
|
|
9833
9923
|
//# sourceMappingURL=tilde-nlp-ngx-common.mjs.map
|