UNPKG

@singleton-i18n/angular-client

Version:

Singleton client code for Angular 10.

87 lines (86 loc) 2.82 kB
import { EventEmitter } from '@angular/core'; import { LocaleService } from './locale.service'; import { I18nLoader } from '../loader'; import { Observable } from 'rxjs'; import { VIPConfig } from '../config'; import { sourceBundleObject } from './l10n.service'; import { I18nContext } from './i18n.context'; export interface LocaleData { categories: Object; messages: { [key: string]: any; }; } export interface LoadingLocaleData { locale: string; data: Observable<any>; } export declare class VIPService { protected localeService: LocaleService; protected i18nContext: I18nContext; currentLoader: I18nLoader; mainConfig: VIPConfig; private pending; private loadingLocaleData; private configs; private availableLocales; private localeSubscription; private _onLocaleChange; private _i18nScope; private _localeData; constructor(localeService: LocaleService, i18nContext: I18nContext, currentLoader: I18nLoader); get onLocaleChange(): EventEmitter<string>; get localeData(): any; get i18nScope(): string[]; /** * Loading the i18n data at app module or root of lazy module. * @param config For root module or lazy load mdule. */ initData(config: VIPConfig): Promise<any>; /** * Init locale by config passed from root module for compatibility. * Will be removed in v9. * @param config */ private initLocale; /** * Subscrible the locale changed event from view layer. * For live UI translation update. */ subscribeLocaleSubject(): void; /** * Specifically, for the feature module which will be imported * to root module or lazy load module. This method should be invoked * in the constructor of feature module. * @param config * @param isMain */ registerComponent(config: VIPConfig, isMain?: boolean): void; /** * Tentative solution, if translation bundle is mounted. * no longer to consider i18n scope which defined in * feature module configuration. * @param config */ private updateI18nScope; /** * If the locale is processed or source locale, skip. */ loadLocaleData(): Promise<any>; private getLocaleData; private resetBundle; private processBundle; private storeResource; /** * current represents current available locale to cover the initial status. * since in some situation, the 'onLocaleChange' haven't be register always, * or there is no event at time. */ get current(): Observable<string | any>; /** * stream of 'available' locale. */ get stream(): Observable<string | any>; private releaseLocale; registerSourceBundles(sourceBundles: sourceBundleObject[], config: VIPConfig): void; }