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 |
|
48 | declare type TranslateResult = string | LocaleMessages;
|
49 | declare type DateTimeFormatResult = string;
|
50 | declare type NumberFormatResult = string;
|
51 | declare type MissingHandler = (locale: Locale, key: Path, vm?: any) => string | void;
|
52 |
|
53 | declare type I18nOptions = {
|
54 | locale?: Locale,
|
55 | fallbackLocale?: Locale,
|
56 | messages?: LocaleMessages,
|
57 | dateTimeFormats?: DateTimeFormats,
|
58 | numberFormats?: NumberFormats,
|
59 | formatter?: Formatter,
|
60 | missing?: MissingHandler,
|
61 | root?: I18n,
|
62 | fallbackRoot?: boolean,
|
63 | sync?: boolean,
|
64 | silentTranslationWarn?: boolean,
|
65 | silentFallbackWarn?: boolean,
|
66 | pluralizationRules?: {
|
67 | [lang: string]: (choice: number, choicesLength: number) => number,
|
68 | },
|
69 | preserveDirectiveContent?: boolean,
|
70 | };
|
71 |
|
72 | declare type IntlAvailability = {
|
73 | dateTimeFormat: boolean,
|
74 | numberFormat: boolean
|
75 | };
|
76 |
|
77 | declare interface I18n {
|
78 | static install: () => void,
|
79 | static version: string,
|
80 | static availabilities: IntlAvailability,
|
81 | get vm (): any, // for internal
|
82 | get locale (): Locale,
|
83 | set locale (locale: Locale): void,
|
84 | get fallbackLocale (): Locale,
|
85 | set fallbackLocale (locale: Locale): void,
|
86 | get messages (): LocaleMessages,
|
87 | get dateTimeFormats (): DateTimeFormats,
|
88 | get missing (): ?MissingHandler,
|
89 | set missing (handler: MissingHandler): void,
|
90 | get formatter (): Formatter,
|
91 | set formatter (formatter: Formatter): void,
|
92 | get silentTranslationWarn (): boolean,
|
93 | set silentTranslationWarn (silent: boolean): void,
|
94 | get silentFallbackWarn (): boolean,
|
95 | set silentFallbackWarn (slient: boolean): void,
|
96 | getLocaleMessage (locale: Locale): LocaleMessageObject,
|
97 | setLocaleMessage (locale: Locale, message: LocaleMessageObject): void,
|
98 | mergeLocaleMessage (locale: Locale, message: LocaleMessageObject): void,
|
99 | t (key: Path, ...values: any): TranslateResult,
|
100 | i (key: Path, locale: Locale, values: Object): TranslateResult,
|
101 | tc (key: Path, choice?: number, ...values: any): TranslateResult,
|
102 | te (key: Path, locale?: Locale): boolean,
|
103 | getDateTimeFormat (locale: Locale): DateTimeFormat,
|
104 | setDateTimeFormat (locale: Locale, format: DateTimeFormat): void,
|
105 | mergeDateTimeFormat (locale: Locale, format: DateTimeFormat): void,
|
106 | d (value: number | Date, ...args: any): DateTimeFormatResult,
|
107 | getNumberFormat (locale: Locale): NumberFormat,
|
108 | setNumberFormat (locale: Locale, format: NumberFormat): void,
|
109 | mergeNumberFormat (locale: Locale, format: NumberFormat): void,
|
110 | n (value: number, ...args: any): NumberFormatResult,
|
111 | pluralizationRules: {
|
112 | [lang: string]: (choice: number, choicesLength: number) => number
|
113 | },
|
114 | preserveDirectiveContent: boolean
|
115 | };
|
116 |
|
117 | declare interface Formatter {
|
118 | interpolate (message: string, values: any, path: string): (Array<any> | null)
|
119 | };
|