@singleton-i18n/angular-client
Version:
Singleton client code for Angular 10.
82 lines (81 loc) • 3.28 kB
TypeScript
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { VIPConfig } from './config';
import { ResponseParser } from './response.parser';
import { LocaleData } from './services/vip.service';
export interface VIPRequestBody {
language: string;
region: string;
productName: string;
version: string;
components: Array<string>;
scope: string;
pseudo?: boolean;
machineTranslation?: boolean;
checkTranslationStatus?: string;
combine: number;
}
export declare abstract class I18nLoader {
abstract getLocaleData(config: VIPConfig, language: string, region?: string): Observable<any>;
abstract getSupportedLanguages(conf: VIPConfig): Observable<any>;
abstract getSupportedRegions(language: string, conf: VIPConfig): Observable<any>;
abstract getLocalizedCities(language: string, region: string, conf: VIPConfig): Observable<any>;
}
export declare class VIPLoader implements I18nLoader {
responseParser: ResponseParser;
private http;
constructor(responseParser: ResponseParser, http: HttpClient);
/**
* Get the i18n resource through VIP service.
* i18nAssets will be removed in future release.
* And for i18nAsset only support loading translation
* from web server, can't support loading patterns.
* @param url
* @returns Promise<any>
* @memberof VIPRestLoader
*/
getLocaleData(config: VIPConfig, language: string, region?: string): Observable<LocaleData>;
/**
* Get the combine locale data(translations and pattern) through assets folder.
* @param language language code in use
* @param config
*/
private getCombineDataFromAssets;
/**
* Only get translations through VIP service.
* @param language language tag for translation.
* @param config without i18nScope
*/
private getTranslationByComponent;
/**
* Get combine locale data(translations and pattern) through VIP service.
* @param conf with i18nScope
* @param language language tag for translation.
* @param region region code for formatting pattern.
*/
private getCombineLocaleData;
getSupportedLanguages(conf: VIPConfig): Observable<Object>;
getSupportedRegions(language: string, conf: VIPConfig): Observable<Object>;
getLocalizedCities(language: string, region: string, conf: VIPConfig): Observable<any>;
/**
* Fetch I18N resource from backend service through get request.
* @param url request url.
* @param timeout default value is 3000ms, timeoutWith default value is 0ms.
* @param fn a callback function that is executed after the request is completed.
*/
private getRequest;
/**
* Fetch I18N resource from backend service through post request.
* @param url request url.
* @param vipRequestBody parameters
* @param timeout default value is 3000ms, timeoutWith default value is 0ms.
* @param fn a callback function that is executed after the request is completed.
*/
private postRequest;
private getI18nResourceUrl;
private getComponentTranslationUrl;
private getSupportedLanguagesUrl;
private getSupportedRegionsUrl;
private getLocalizedCitiesUrl;
private validateConfig;
}