ember-intl
Version:
Internationalization for Ember projects
82 lines (81 loc) • 3.61 kB
TypeScript
import Service from '@ember/service';
import type { FormatDateParameters, FormatDateRangeParameters, FormatListParameters, FormatMessageParameters, FormatNumberParameters, FormatRelativeParameters, FormatRelativeTimeParameters, Formats, FormatTimeParameters, OnErrorFn } from '../-private/formatjs/index';
import { type Translations } from '../-private/utils/translations';
export type { Formats };
type OnFormatjsError = (error: Parameters<OnErrorFn>[0]) => void;
type OnMissingTranslation = (key: string, locales: string[], options?: Record<string, unknown>) => string;
export default class IntlService extends Service {
private _intls;
private _locale?;
private _cache;
private _formats;
private _onFormatjsError;
private _onMissingTranslation;
private _timer?;
get locales(): string[];
get primaryLocale(): string | undefined;
constructor();
addTranslations(locale: string, translations: Translations): void;
private createIntl;
exists(key: string, locale?: string | string[]): boolean;
formatDate(value: FormatDateParameters[0] | undefined | null, options?: FormatDateParameters[1] & {
locale?: string;
}): string;
formatDateRange(from: FormatDateRangeParameters[0] | undefined | null, to: FormatDateRangeParameters[1] | undefined | null, options?: FormatDateRangeParameters[2] & {
locale?: string;
}): string;
formatList(value: FormatListParameters[0] | undefined | null, options?: FormatListParameters[1] & {
locale?: string;
}): string;
formatMessage(value: FormatMessageParameters[0] | string | undefined | null, options?: FormatMessageParameters[1] & {
htmlSafe?: boolean;
locale?: string;
}): string;
formatNumber(value: FormatNumberParameters[0] | undefined | null, options?: FormatNumberParameters[1] & {
locale?: string;
}): string;
/**
* @deprecated
*
* `formatRelative()` will be renamed to `formatRelativeTime()` in `ember-intl@8.0.0`.
* Please rename the method to `formatRelativeTime()` in your class now.
*/
formatRelative(value: FormatRelativeParameters[0] | undefined | null, options?: FormatRelativeParameters[2] & {
locale?: string;
unit?: FormatRelativeParameters[1];
}): string;
formatRelativeTime(value: FormatRelativeTimeParameters[0] | undefined | null, options?: FormatRelativeTimeParameters[2] & {
locale?: string;
unit?: FormatRelativeTimeParameters[1];
}): string;
formatTime(value: FormatTimeParameters[0] | undefined | null, options?: FormatTimeParameters[1] & {
locale?: string;
}): string;
/**
* @deprecated
*
* Formats, defined in the file `app/formats.js`, will have no effect in
* `ember-intl@8.0.0`. Please define formats in `app/ember-intl.{js,ts}`,
* then call `setFormats()` before loading your translations.
*/
private getDefaultFormats;
private getIntl;
private getIntlShape;
getTranslation(key: string, locale: string): string | undefined;
setFormats(formats: Formats): void;
setLocale(locale: string | string[]): void;
setOnFormatjsError(onFormatjsError: OnFormatjsError): void;
setOnMissingTranslation(onMissingTranslation: OnMissingTranslation): void;
t(key: string, options?: FormatMessageParameters[1] & {
htmlSafe?: boolean;
locale?: string;
}): string;
private updateDocumentLanguage;
private updateIntl;
willDestroy(): void;
}
declare module '@ember/service' {
interface Registry {
intl: IntlService;
}
}