1 | declare var Intl: any;
|
2 |
|
3 | declare type Path = string;
|
4 | declare type Locale = string;
|
5 | declare type LocaleMessage = string | LocaleMessageObject | LocaleMessageArray;
|
6 | declare type LocaleMessageObject = { [key: Path]: LocaleMessage };
|
7 | declare type LocaleMessageArray = Array<LocaleMessage>;
|
8 | declare type LocaleMessages = { [key: Locale]: LocaleMessageObject };
|
9 |
|
10 |
|
11 |
|
12 | declare type DateTimeFormatOptions = {
|
13 | year?: 'numeric' | '2-digit',
|
14 | month?: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long',
|
15 | day?: 'numeric' | '2-digit',
|
16 | hour?: 'numeric' | '2-digit',
|
17 | minute?: 'numeric' | '2-digit',
|
18 | second?: 'numeric' | '2-digit',
|
19 | weekday?: 'narrow' | 'short' | 'long',
|
20 | hour12?: boolean,
|
21 | era?: 'narrow' | 'short' | 'long',
|
22 | timeZone?: string,
|
23 | timeZoneName?: 'short' | 'long',
|
24 | localeMatcher?: 'lookup' | 'best fit',
|
25 | formatMatcher?: 'basic' | 'best fit'
|
26 | };
|
27 | declare type DateTimeFormat = { [key: string]: DateTimeFormatOptions };
|
28 | declare type DateTimeFormats = { [key: Locale]: DateTimeFormat };
|
29 |
|
30 |
|
31 |
|
32 | declare type NumberFormatOptions = {
|
33 | style?: 'decimal' | 'currency' | 'percent',
|
34 | currency?: string,
|
35 | currencyDisplay?: 'symbol' | 'code' | 'name',
|
36 | useGrouping?: boolean,
|
37 | minimumIntegerDigits?: number,
|
38 | minimumFractionDigits?: number,
|
39 | maximumFractionDigits?: number,
|
40 | minimumSignificantDigits?: number,
|
41 | maximumSignificantDigits?: number,
|
42 | localeMatcher?: 'lookup' | 'best fit',
|
43 | formatMatcher?: 'basic' | 'best fit'
|
44 | };
|
45 | declare type NumberFormat = { [key: string]: NumberFormatOptions };
|
46 | declare type NumberFormats = { [key: Locale]: NumberFormat };
|
47 | declare type Modifiers = { [key: string]: (str : string) => string };
|
48 |
|
49 | declare type TranslateResult = string | LocaleMessages;
|
50 | declare type DateTimeFormatResult = string;
|
51 | declare type NumberFormatResult = string;
|
52 | declare type MissingHandler = (locale: Locale, key: Path, vm?: any) => string | void;
|
53 |
|
54 | declare type FormattedNumberPartType = 'currency' | 'decimal' | 'fraction' | 'group' | 'infinity' | 'integer' | 'literal' | 'minusSign' | 'nan' | 'plusSign' | 'percentSign';
|
55 | declare type FormattedNumberPart = {
|
56 | type: FormattedNumberPartType,
|
57 | value: string,
|
58 | };
|
59 |
|
60 |
|
61 | declare type NumberFormatToPartsResult = Array<FormattedNumberPart>;
|
62 |
|
63 | declare type WarnHtmlInMessageLevel = 'off' | 'warn' | 'error';
|
64 |
|
65 | declare type I18nOptions = {
|
66 | locale?: Locale,
|
67 | fallbackLocale?: Locale,
|
68 | messages?: LocaleMessages,
|
69 | dateTimeFormats?: DateTimeFormats,
|
70 | numberFormats?: NumberFormats,
|
71 | formatter?: Formatter,
|
72 | missing?: MissingHandler,
|
73 | modifiers?: Modifiers,
|
74 | root?: I18n,
|
75 | fallbackRoot?: boolean,
|
76 | formatFallbackMessages?: boolean,
|
77 | sync?: boolean,
|
78 | silentTranslationWarn?: boolean | RegExp,
|
79 | silentFallbackWarn?: boolean | RegExp,
|
80 | pluralizationRules?: PluralizationRules,
|
81 | preserveDirectiveContent?: boolean,
|
82 | warnHtmlInMessage?: WarnHtmlInMessageLevel,
|
83 | sharedMessages?: LocaleMessage,
|
84 | };
|
85 |
|
86 | declare type IntlAvailability = {
|
87 | dateTimeFormat: boolean,
|
88 | numberFormat: boolean
|
89 | };
|
90 |
|
91 | declare type PluralizationRules = {
|
92 | [lang: string]: (choice: number, choicesLength: number) => number,
|
93 | }
|
94 |
|
95 | declare interface I18n {
|
96 | static install: () => void,
|
97 | static version: string,
|
98 | static availabilities: IntlAvailability,
|
99 | get vm (): any, // for internal
|
100 | get locale (): Locale,
|
101 | set locale (locale: Locale): void,
|
102 | get fallbackLocale (): Locale,
|
103 | set fallbackLocale (locale: Locale): void,
|
104 | get messages (): LocaleMessages,
|
105 | get dateTimeFormats (): DateTimeFormats,
|
106 | get numberFormats (): NumberFormats,
|
107 | get availableLocales (): Locale[],
|
108 | get missing (): ?MissingHandler,
|
109 | set missing (handler: MissingHandler): void,
|
110 | get formatter (): Formatter,
|
111 | set formatter (formatter: Formatter): void,
|
112 | get formatFallbackMessages (): boolean,
|
113 | set formatFallbackMessages (fallback: boolean): void,
|
114 | get silentTranslationWarn (): boolean | RegExp,
|
115 | set silentTranslationWarn (silent: boolean | RegExp): void,
|
116 | get silentFallbackWarn (): boolean | RegExp,
|
117 | set silentFallbackWarn (slient: boolean | RegExp): void,
|
118 | get pluralizationRules (): PluralizationRules,
|
119 | set pluralizationRules (rules: PluralizationRules): void,
|
120 | get preserveDirectiveContent (): boolean,
|
121 | set preserveDirectiveContent (preserve: boolean): void,
|
122 | get warnHtmlInMessage (): WarnHtmlInMessageLevel,
|
123 | set warnHtmlInMessage (level: WarnHtmlInMessageLevel): void,
|
124 |
|
125 | getLocaleMessage (locale: Locale): LocaleMessageObject,
|
126 | setLocaleMessage (locale: Locale, message: LocaleMessageObject): void,
|
127 | mergeLocaleMessage (locale: Locale, message: LocaleMessageObject): void,
|
128 | t (key: Path, ...values: any): TranslateResult,
|
129 | i (key: Path, locale: Locale, values: Object): TranslateResult,
|
130 | tc (key: Path, choice?: number, ...values: any): TranslateResult,
|
131 | te (key: Path, locale?: Locale): boolean,
|
132 | getDateTimeFormat (locale: Locale): DateTimeFormat,
|
133 | setDateTimeFormat (locale: Locale, format: DateTimeFormat): void,
|
134 | mergeDateTimeFormat (locale: Locale, format: DateTimeFormat): void,
|
135 | d (value: number | Date, ...args: any): DateTimeFormatResult,
|
136 | getNumberFormat (locale: Locale): NumberFormat,
|
137 | setNumberFormat (locale: Locale, format: NumberFormat): void,
|
138 | mergeNumberFormat (locale: Locale, format: NumberFormat): void,
|
139 | n (value: number, ...args: any): NumberFormatResult,
|
140 | getChoiceIndex: (choice: number, choicesLength: number) => number,
|
141 | pluralizationRules: PluralizationRules,
|
142 | preserveDirectiveContent: boolean
|
143 | };
|
144 |
|
145 | declare interface Formatter {
|
146 | interpolate (message: string, values: any, path: string): (Array<any> | null)
|
147 | };
|