1 | import Vue, { PluginFunction } from 'vue';
|
2 |
|
3 | declare namespace VueI18n {
|
4 | type Path = string;
|
5 | type Locale = string;
|
6 | type Values = any[] | { [key: string]: any };
|
7 | type Choice = number;
|
8 | type LocaleMessage = string | LocaleMessageObject | LocaleMessageArray;
|
9 | interface LocaleMessageObject { [key: string]: LocaleMessage; }
|
10 | interface LocaleMessageArray { [index: number]: LocaleMessage; }
|
11 | interface LocaleMessages { [key: string]: LocaleMessageObject; }
|
12 | type TranslateResult = string | LocaleMessages;
|
13 |
|
14 | type LocaleMatcher = 'lookup' | 'best-fit';
|
15 | type FormatMatcher = 'basic' | 'best-fit';
|
16 |
|
17 | type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
|
18 | type DateTimeDigital = 'numeric' | '2-digit';
|
19 |
|
20 | interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
|
21 | year?: DateTimeDigital;
|
22 | month?: DateTimeDigital | DateTimeHumanReadable;
|
23 | day?: DateTimeDigital;
|
24 | hour?: DateTimeDigital;
|
25 | minute?: DateTimeDigital;
|
26 | second?: DateTimeDigital;
|
27 | weekday?: DateTimeHumanReadable;
|
28 | era?: DateTimeHumanReadable;
|
29 | timeZoneName?: 'long' | 'short';
|
30 | localeMatcher?: LocaleMatcher;
|
31 | formatMatcher?: FormatMatcher;
|
32 | }
|
33 |
|
34 | type DateTimeFormatOptions = Intl.DateTimeFormatOptions | SpecificDateTimeFormatOptions;
|
35 |
|
36 | interface DateTimeFormat { [key: string]: DateTimeFormatOptions; }
|
37 | interface DateTimeFormats { [locale: string]: DateTimeFormat; }
|
38 | type DateTimeFormatResult = string;
|
39 |
|
40 | type CurrencyDisplay = 'symbol' | 'code' | 'name';
|
41 |
|
42 | interface SpecificNumberFormatOptions extends Intl.NumberFormatOptions {
|
43 | style?: 'decimal' | 'percent';
|
44 | currency?: string;
|
45 | currencyDisplay?: CurrencyDisplay;
|
46 | localeMatcher?: LocaleMatcher;
|
47 | formatMatcher?: FormatMatcher;
|
48 | }
|
49 |
|
50 | interface CurrencyNumberFormatOptions extends Intl.NumberFormatOptions {
|
51 | style: 'currency';
|
52 | currency: string;
|
53 | currencyDisplay?: CurrencyDisplay;
|
54 | localeMatcher?: LocaleMatcher;
|
55 | formatMatcher?: FormatMatcher;
|
56 | }
|
57 |
|
58 | type NumberFormatOptions = Intl.NumberFormatOptions | SpecificNumberFormatOptions | CurrencyNumberFormatOptions;
|
59 |
|
60 | interface NumberFormat { [key: string]: NumberFormatOptions; }
|
61 | interface NumberFormats { [locale: string]: NumberFormat; }
|
62 | type NumberFormatResult = string;
|
63 | type PluralizationRulesMap = {
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 | [lang: string]: (choice: number, choicesLength: number) => number;
|
70 | };
|
71 |
|
72 | interface Formatter {
|
73 | interpolate(message: string, values: Values | undefined, path: string): (any[] | null);
|
74 | }
|
75 |
|
76 | type MissingHandler = (locale: Locale, key: Path, vm?: Vue) => string | void;
|
77 |
|
78 | interface IntlAvailability {
|
79 | dateTimeFormat: boolean;
|
80 | numberFormat: boolean;
|
81 | }
|
82 |
|
83 |
|
84 | interface I18nOptions {
|
85 | locale?: Locale;
|
86 | fallbackLocale?: Locale;
|
87 | messages?: LocaleMessages;
|
88 | dateTimeFormats?: DateTimeFormats;
|
89 | numberFormats?: NumberFormats;
|
90 | formatter?: Formatter;
|
91 | missing?: MissingHandler;
|
92 | fallbackRoot?: boolean;
|
93 | sync?: boolean;
|
94 | silentTranslationWarn?: boolean;
|
95 | silentFallbackWarn?: boolean;
|
96 | preserveDirectiveContent?: boolean;
|
97 | pluralizationRules?: PluralizationRulesMap;
|
98 | }
|
99 | }
|
100 |
|
101 | export type Path = VueI18n.Path;
|
102 | export type Locale = VueI18n.Locale;
|
103 | export type Values = VueI18n.Values;
|
104 | export type Choice = VueI18n.Choice;
|
105 | export type LocaleMessage = VueI18n.LocaleMessage;
|
106 | export type LocaleMessageObject = VueI18n.LocaleMessageObject;
|
107 | export type LocaleMessageArray = VueI18n.LocaleMessageArray;
|
108 | export type LocaleMessages = VueI18n.LocaleMessages;
|
109 | export type TranslateResult = VueI18n.TranslateResult;
|
110 | export type DateTimeFormatOptions = VueI18n.DateTimeFormatOptions;
|
111 | export type DateTimeFormat = VueI18n.DateTimeFormat;
|
112 | export type DateTimeFormats = VueI18n.DateTimeFormats;
|
113 | export type DateTimeFormatResult = VueI18n.DateTimeFormatResult;
|
114 | export type NumberFormatOptions = VueI18n.NumberFormatOptions;
|
115 | export type NumberFormat = VueI18n.NumberFormat;
|
116 | export type NumberFormats = VueI18n.NumberFormats;
|
117 | export type NumberFormatResult = VueI18n.NumberFormatResult;
|
118 | export type Formatter = VueI18n.Formatter;
|
119 | export type MissingHandler = VueI18n.MissingHandler;
|
120 | export type IntlAvailability = VueI18n.IntlAvailability;
|
121 | export type I18nOptions = VueI18n.I18nOptions;
|
122 |
|
123 | export declare interface IVueI18n {
|
124 | readonly messages: VueI18n.LocaleMessages;
|
125 | readonly dateTimeFormats: VueI18n.DateTimeFormats;
|
126 | readonly numberFormats: VueI18n.NumberFormats;
|
127 |
|
128 | locale: VueI18n.Locale;
|
129 | fallbackLocale: VueI18n.Locale;
|
130 | missing: VueI18n.MissingHandler;
|
131 | formatter: VueI18n.Formatter;
|
132 | silentTranslationWarn: boolean;
|
133 | silentFallbackWarn: boolean;
|
134 | preserveDirectiveContent: boolean;
|
135 | pluralizationRules: VueI18n.PluralizationRulesMap;
|
136 | }
|
137 |
|
138 | declare class VueI18n {
|
139 | constructor(options?: VueI18n.I18nOptions)
|
140 |
|
141 | readonly messages: VueI18n.LocaleMessages;
|
142 | readonly dateTimeFormats: VueI18n.DateTimeFormats;
|
143 | readonly numberFormats: VueI18n.NumberFormats;
|
144 |
|
145 | locale: VueI18n.Locale;
|
146 | fallbackLocale: VueI18n.Locale;
|
147 | missing: VueI18n.MissingHandler;
|
148 | formatter: VueI18n.Formatter;
|
149 | silentTranslationWarn: boolean;
|
150 | silentFallbackWarn: boolean;
|
151 | preserveDirectiveContent: boolean;
|
152 | pluralizationRules: VueI18n.PluralizationRulesMap;
|
153 |
|
154 | t(key: VueI18n.Path, values?: VueI18n.Values): VueI18n.TranslateResult;
|
155 | t(key: VueI18n.Path, locale: VueI18n.Locale, values?: VueI18n.Values): VueI18n.TranslateResult;
|
156 | tc(key: VueI18n.Path, choice?: VueI18n.Choice, values?: VueI18n.Values): string;
|
157 | tc(key: VueI18n.Path, choice: VueI18n.Choice, locale: VueI18n.Locale, values?: VueI18n.Values): string;
|
158 | te(key: VueI18n.Path, locale?: VueI18n.Locale): boolean;
|
159 | d(value: number | Date, key?: VueI18n.Path, locale?: VueI18n.Locale): VueI18n.DateTimeFormatResult;
|
160 | d(value: number | Date, args?: { [key: string]: string }): VueI18n.DateTimeFormatResult;
|
161 | n(value: number, key?: VueI18n.Path, locale?: VueI18n.Locale): VueI18n.NumberFormatResult;
|
162 | n(value: number, args?: { [key: string]: string }): VueI18n.NumberFormatResult;
|
163 |
|
164 | getLocaleMessage(locale: VueI18n.Locale): VueI18n.LocaleMessageObject;
|
165 | setLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void;
|
166 | mergeLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void;
|
167 |
|
168 | getDateTimeFormat(locale: VueI18n.Locale): VueI18n.DateTimeFormat;
|
169 | setDateTimeFormat(locale: VueI18n.Locale, format: VueI18n.DateTimeFormat): void;
|
170 | mergeDateTimeFormat(locale: VueI18n.Locale, format: VueI18n.DateTimeFormat): void;
|
171 |
|
172 | getNumberFormat(locale: VueI18n.Locale): VueI18n.NumberFormat;
|
173 | setNumberFormat(locale: VueI18n.Locale, format: VueI18n.NumberFormat): void;
|
174 | mergeNumberFormat(locale: VueI18n.Locale, format: VueI18n.NumberFormat): void;
|
175 |
|
176 | /**
|
177 | * @param choice {number} a choice index given by the input to $tc: `$tc('path.to.rule', choiceIndex)`
|
178 | * @param choicesLength {number} an overall amount of available choices
|
179 | * @returns a final choice index
|
180 | */
|
181 | getChoiceIndex: (choice: number, choicesLength: number) => number;
|
182 |
|
183 | static install: PluginFunction<never>;
|
184 | static version: string;
|
185 | static availabilities: VueI18n.IntlAvailability;
|
186 | }
|
187 |
|
188 | declare module 'vue/types/vue' {
|
189 | interface Vue {
|
190 | readonly $i18n: VueI18n & IVueI18n;
|
191 | $t: typeof VueI18n.prototype.t;
|
192 | $tc: typeof VueI18n.prototype.tc;
|
193 | $te: typeof VueI18n.prototype.te;
|
194 | $d: typeof VueI18n.prototype.d;
|
195 | $n: typeof VueI18n.prototype.n;
|
196 | }
|
197 | }
|
198 |
|
199 | declare module 'vue/types/options' {
|
200 | interface ComponentOptions<V extends Vue> {
|
201 | i18n?: {
|
202 | messages?: VueI18n.LocaleMessages;
|
203 | dateTimeFormats?: VueI18n.DateTimeFormats;
|
204 | numberFormats?: VueI18n.NumberFormats;
|
205 | };
|
206 | }
|
207 | }
|
208 |
|
209 | export default VueI18n;
|