UNPKG

@o3r/localization

Version:

This module provides a runtime dynamic language/translation support and debug tools.

114 lines 4.91 kB
import { Store } from '@ngrx/store'; import { TranslateService } from '@ngx-translate/core'; import { LoggerService } from '@o3r/logger'; import { Observable } from 'rxjs'; import { LocalizationConfiguration } from '../core/localization.configuration'; import { LocalizationOverrideStore } from '../stores/index'; import * as i0 from "@angular/core"; /** * Service which is wrapping the configuration logic of TranslateService from ngx-translate * Any application willing to use localization just needs to inject LocalizationService * in the root component and call its configure() method. */ export declare class LocalizationService { private readonly translateService; private readonly logger; private readonly configuration; private readonly store?; private readonly localeSplitIdentifier; /** * Internal subject that we use to track changes between keys only and translation mode */ private readonly _showKeys$; /** * Map of localization keys to replace a key to another */ private readonly keyMapping$?; /** * _showKeys$ exposed as an Observable */ showKeys$: Observable<boolean>; constructor(translateService: TranslateService, logger: LoggerService, configuration: LocalizationConfiguration, store?: Store<LocalizationOverrideStore> | undefined); /** * This will handle the fallback language hierarchy to find out fallback language. * supportedLocales language has highest priority, next priority goes to fallbackLocalesMap and default would be * fallbackLanguage. * @param language Selected language. * @returns selected language if supported, fallback language otherwise. */ private checkFallbackLocalesMap; /** * This function checks if fallback language can be provided from fallbackLocalesMap. * supportedLocales: ['en-GB', 'en-US', 'fr-FR'], fallbackLocalesMap: {'en-CA': 'en-US', 'de': 'fr-FR'} * translate to en-CA -> fallback to en-US, translate to de-DE -> fallback to fr-FR * translate to en-NZ -> fallback to en-GB * @param language Selected language. * @returns Fallback language if available, undefined otherwise. */ private getFallbackMapLangCode; /** * This function checks if closest supported language available incase of selected language is not * supported language. * supportedLocales: ['en-GB', 'en-US', 'fr-FR'] * translate to en-CA -> fallback to en-GB * @param language Selected language. * @returns Closest supported language if available, undefined otherwise. */ private getFirstClosestSupportedLanguageCode; /** * Returns a stream of translated values of a key which updates whenever the language changes. * @param translationKey Key to translate * @param interpolateParams Object to use in translation binding * @returns A stream of the translated key */ private getTranslationStream; /** * Configures TranslateService and registers locales. This method is called from the application level. */ configure(): Promise<void>; /** * Is the translation deactivation enabled */ isTranslationDeactivationEnabled(): boolean; /** * Wrapper to call the ngx-translate service TranslateService method getLangs(). */ getLanguages(): string[]; /** * Wrapper to call the ngx-translate service TranslateService method use(language). * @param language */ useLanguage(language: string): Observable<any>; /** * Wrapper to get the ngx-translate service TranslateService currentLang. */ getCurrentLanguage(): string; /** * Get the instance of the ngx-translate TranslateService used by LocalizationService. */ getTranslateService(): TranslateService; /** * Toggle the ShowKeys mode between active and inactive. * @param value if specified, set the ShowKeys mode to value. If not specified, toggle the ShowKeys mode. */ toggleShowKeys(value?: boolean): void; /** * Return the current value of debug show/hide translation keys. */ get showKeys(): boolean; /** * Get an observable of translation key after global mapping * @param requestedKey Original translation key */ getKey(requestedKey: string): Observable<any>; /** * Returns a stream of translated values of a key which updates whenever the language changes. * @param key Key to translate * @param interpolateParams Object to use in translation binding * @returns A stream of the translated key */ translate(key: string, interpolateParams?: object): Observable<any>; static ɵfac: i0.ɵɵFactoryDeclaration<LocalizationService, [null, null, null, { optional: true; }]>; static ɵprov: i0.ɵɵInjectableDeclaration<LocalizationService>; } //# sourceMappingURL=localization.service.d.ts.map