UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

147 lines (146 loc) 7.1 kB
import { Subject } from 'rxjs'; import { LocaleStorage } from './locale-storage'; import { L10nConfigRef } from "../models/l10n-config"; import { ISOCode, DateTimeOptions, DigitsOptions, RelativeTimeOptions, Unit } from '../models/types'; export interface ILocaleService { languageCodeChanged: Subject<string>; defaultLocaleChanged: Subject<string>; currencyCodeChanged: Subject<string>; timezoneChanged: Subject<string>; getConfiguration(): L10nConfigRef['locale']; init(): Promise<void>; getBrowserLanguage(): string | null; getAvailableLanguages(): string[]; getLanguageDirection(languageCode?: string): string; getCurrentLanguage(): string; getCurrentCountry(): string; getCurrentScript(): string; getCurrentLocale(): string; getCurrentNumberingSystem(): string; getCurrentCalendar(): string; getDefaultLocale(): string; getCurrentCurrency(): string; getCurrencySymbol(currencyDisplay?: string, defaultLocale?: string, currency?: string): string; getCurrentTimezone(): string; setCurrentLanguage(languageCode: string): void; setDefaultLocale(languageCode: string, countryCode?: string, scriptCode?: string, numberingSystem?: string, calendar?: string): void; setCurrentCurrency(currencyCode: string): void; setCurrentTimezone(zoneName: string): void; formatDate(value: any, format?: string | DateTimeOptions, defaultLocale?: string, timezone?: string): string; formatRelativeTime(value: any, unit: Unit, format?: RelativeTimeOptions, defaultLocale?: string): string; formatDecimal(value: any, digits?: string | DigitsOptions, defaultLocale?: string): string; formatPercent(value: any, digits?: string | DigitsOptions, defaultLocale?: string): string; formatCurrency(value: any, digits?: string | DigitsOptions, currencyDisplay?: string, defaultLocale?: string, currency?: string): string; composeLocale(codes: ISOCode[]): string; rollback(): void; } /** * Manages language, default locale, currency & timezone. */ export declare class LocaleService implements ILocaleService { private configuration; private storage; /** * Fired when the language changes. Returns the language code. */ languageCodeChanged: Subject<string>; /** * Fired when the default locale changes. Returns the default locale. */ defaultLocaleChanged: Subject<string>; /** * Fired when the currency changes. Returns the currency code. */ currencyCodeChanged: Subject<string>; /** * Fired when the timezone changes. Returns the timezone. */ timezoneChanged: Subject<string>; private defaultLocale; private currencyCode; private timezone; private rollbackLanguageCode; private rollbackDefaultLocale; private rollbackCurrencyCode; private rollbackTimezone; constructor(configuration: L10nConfigRef, storage: LocaleStorage); getConfiguration(): L10nConfigRef['locale']; init(): Promise<void>; getBrowserLanguage(): string | null; getAvailableLanguages(): string[]; getLanguageDirection(languageCode?: string): string; getCurrentLanguage(): string; getCurrentCountry(): string; getCurrentScript(): string; /** * Returns the well formatted locale as {languageCode}[-scriptCode][-countryCode] */ getCurrentLocale(): string; getCurrentNumberingSystem(): string; getCurrentCalendar(): string; getDefaultLocale(): string; getCurrentCurrency(): string; getCurrencySymbol(currencyDisplay: 'code' | 'symbol' | 'name', defaultLocale?: string, currency?: string): string; getCurrentTimezone(): string; setCurrentLanguage(languageCode: string): void; setDefaultLocale(languageCode: string, countryCode?: string, scriptCode?: string, numberingSystem?: string, calendar?: string): void; setCurrentCurrency(currencyCode: string): void; setCurrentTimezone(zoneName: string): void; /** * Formats a date according to default locale. * @param value A Date, a number (milliseconds since UTC epoch) or an ISO string * @param format An alias or a DateTimeOptions object of the format. Default is 'mediumDate' * @param defaultLocale The default locale to use. Default is the current locale * @param timezone The time zone name. Default is the current timezone */ formatDate(value: any, format?: string | DateTimeOptions, defaultLocale?: string, timezone?: string): string; /** * Formats a relative time according to default locale. * @param value Negative (or positive) number * @param unit Unit of the value. Possible values are: 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second' * @param format RelativeTimeOptions object of the format * @param defaultLocale The default locale to use. Default is the current locale */ formatRelativeTime(value: any, unit: Unit, format?: RelativeTimeOptions, defaultLocale?: string): string; /** * Formats a decimal number according to default locale. * @param value The number to be formatted * @param digits An alias or a DigitsOptions object of the format * @param defaultLocale The default locale to use. Default is the current locale */ formatDecimal(value: any, digits?: string | DigitsOptions, defaultLocale?: string): string; /** * Formats a number as a percentage according to default locale. * @param value The number to be formatted * @param digits An alias or a DigitsOptions object of the format * @param defaultLocale The default locale to use. Default is the current locale */ formatPercent(value: any, digits?: string | DigitsOptions, defaultLocale?: string): string; /** * Formats a number as a currency according to default locale. * @param value The number to be formatted * @param digits An alias or a DigitsOptions object of the format * @param currencyDisplay The format for the currency. Possible values are 'code', 'symbol', 'name'. Default is 'symbol' * @param defaultLocale The default locale to use. Default is the current locale * @param currency The currency to use. Default is the current currency */ formatCurrency(value: any, digits?: string | DigitsOptions, currencyDisplay?: 'code' | 'symbol' | 'name', defaultLocale?: string, currency?: string): string; composeLocale(codes: ISOCode[]): string; /** * Rollbacks to previous language, default locale, currency & timezone. */ rollback(): void; private initLanguage; private initDefaultLocale; private initCurrency; private initTimezone; private matchLanguage; private releaseLanguage; private releaseDefaultLocale; private releaseCurrency; private releaseTimezone; private sendLanguageEvents; private sendDefaultLocaleEvents; private sendCurrencyEvents; private sendTimezoneEvents; }