UNPKG

@singleton-i18n/angular-client

Version:

Singleton client code for Angular 10.

93 lines (92 loc) 4.17 kB
import { DateFormatter } from '../formatters/date.formatter'; import { LocaleService } from './locale.service'; import { I18nLoader } from '../loader'; import { NumberFormatOptions } from '../formatters/number.format.model'; import { BaseService } from './base.service'; import { VIPService } from './vip.service'; export interface FormatOption { numeric?: string; forms?: string; } export declare class I18nService extends BaseService { private dateFormatter; protected localeService: LocaleService; protected vipService: VIPService; currentLoader: I18nLoader; private sourceLocaleData; private plural; private formatter; private relativeFormat; constructor(dateFormatter: DateFormatter, localeService: LocaleService, vipService: VIPService, currentLoader: I18nLoader); resolveLocaleData(locale: string): any; private initSourcePatterns; private validateNumber; getFormattedDateTime(value: any, pattern: string, timezone?: string): any; formatDate(value: any, pattern: string, locale?: string, timezone?: string): any; /** * Get localized pattern by predefined pattern and locale. * The default locale is the locale current in use. * If no exist date formatting data of the locale, fallback to source locale 'en'. * If the pattern is not predefined pattern, return origin pattern directly. */ getLocalizedPattern(pattern: string, locale?: string): string; /** * Get number related formatter from FormatterFactory * @param type currencies, currencySymbol, percent or number * @param categories PatternCategories * @returns formatter */ private getFormatter; /** * Get the localized currency symbol by currency code and locale, * return the currency symbol of the currency code. * The default locale is the locale current in use. * If the currency code invalid, return the currency code. */ getLocalizedCurrencySymbol(currencyCode: string, locale?: string): any; private validateDate; /** * Formats simple relative dates. * @param from The starting time of relative time calculation. * @param to The ending time of relative time calculation. * @param locale The locale to determine which patters need to use. * @param options The formatting style. */ formatRelativeTime(from: Date, to: Date, locale?: string, options?: FormatOption): string; /** * Calculate the most suitable unit and the corresponding offset according to the input time * @param from The starting time of relative time calculation. * @param to The ending time of relative time calculation. */ private getRelativeTimeOffset; /** * Get formatted message reaponseable * @param offset The offset of time * @param unit The unit of offset * @param locale The locale to determine which patters need to use. * @param options The formatting style. */ private relativeTimeFormat; getFormattedDecimal(value: any, locale?: string): string; formatNumber(value: any, locale?: string, formatOptions?: NumberFormatOptions): string; getFormattedPercent(value: any): string; formatPercent(value: any, locale?: string, formatOptions?: NumberFormatOptions): string; getFormattedCurrency(value: any, currencyCode: string): any; formatCurrency(value: any, currencyCode?: string, locale?: string, formatOptions?: NumberFormatOptions): any; /** * This APIs will be call by l10n service when render plural message * @param value Numerals that need to be dealt with * @param locale Locale from l10n service */ getPluralCategory(value: number, locale?: string): string | undefined; getPluralCategoryType(value: number, locale?: string): string | undefined; private getPluralFunction; private validateScope; private getSourcePattern; private getPattern; private getCurrencyData; getSupportedLanguages(): Promise<any>; getSupportedRegions(language: string): Promise<any>; getCities(region: string, language: string): Promise<Object>; private convertObjectToArray; }