1
1
import { ComponentOptions , getCurrentInstance } from 'vue'
2
2
import { Path } from './path'
3
3
import { Locale } from './core/context'
4
- import { Composer , ComposerInternalOptions } from './composer'
4
+ import { Composer , ComposerInternalOptions , CustomBlocks } from './composer'
5
5
import {
6
6
VueI18n ,
7
7
VueI18nInternal ,
@@ -13,6 +13,129 @@ import {
13
13
} from './legacy'
14
14
import { I18nInternal } from './i18n'
15
15
16
+ declare module '@vue/runtime-core' {
17
+ interface ComponentCustomOptions {
18
+ /**
19
+ * VueI18n options
20
+ *
21
+ * @remarks
22
+ * See the {@link VueI18nOptions}
23
+ */
24
+ i18n ?: VueI18nOptions
25
+ /**
26
+ * For custom blocks options
27
+ * @internal
28
+ */
29
+ __i18n ?: CustomBlocks
30
+ }
31
+ interface ComponentCustomProperties {
32
+ /**
33
+ * VueI18n class compatible interface. See {@link VueI18n}
34
+ *
35
+ * @remarks
36
+ * If you have specified an `i18n` option at component options,
37
+ * you will be able to get a VueI18n instance at the component,
38
+ * Otherwise, you will be able get root VueI18n instance.
39
+ *
40
+ * This property is supported for legacy API only
41
+ */
42
+ $i18n ?: VueI18n
43
+ /**
44
+ * translation method
45
+ *
46
+ * @param key - required, type {@link Path}
47
+ * @param locale - optional, type {@link Locale}
48
+ * @param values - optional, type `Array` or `Object`
49
+ * @returns translated string
50
+ *
51
+ * @remarks
52
+ * Localize the locale message of `key`.
53
+ * Localize in preferentially component locale messages than global locale messages.
54
+ * If not specified component locale messages, localize with global locale messages.
55
+ * If you specified `locale`, localize the locale messages of `locale`.
56
+ * If you specified `key` of list / named formatting local messages, you must specify `values` too.
57
+ *
58
+ * This property is supported for legacy API only
59
+ */
60
+ $t ?: ( ...args : unknown [ ] ) => TranslateResult
61
+ /**
62
+ * pluralization method
63
+ *
64
+ * @param key - required, type {@link Path}
65
+ * @param choice - optional, type `number`, default `1`
66
+ * @param locale - optional, type {@link Locale}
67
+ * @param values - optional, type `string` or `Array` or `Object`
68
+ * @returns pluralized string
69
+ *
70
+ * @remarks
71
+ * Localize the locale message of `key` with pluralization.
72
+ * Localize in preferentially component locale messages than global locale messages.
73
+ * If not specified component locale messages, localize with global locale messages.
74
+ * If you specified `locale`, localize the locale messages of `locale`.
75
+ * If you will specify string value to `values`, localize the locale messages of value.
76
+ * If you will specify Array or Object value to `values`, you must specify with `values` of `$t`.
77
+ *
78
+ * This property is supported for legacy API only
79
+ */
80
+ $tc ?: ( ...args : unknown [ ] ) => TranslateResult
81
+ /**
82
+ * translation exist method
83
+ *
84
+ * @param key - required, type {@link Path}
85
+ * @param locale - optional, type {@link Locale}
86
+ * @returns key exsiting result
87
+ *
88
+ * @remarks
89
+ * Check whether key exists.
90
+ * In Vue instance, If not specified component locale messages,
91
+ * check with global locale messages. If you specified `locale`, check the locale messages of `locale`
92
+ *
93
+ * This property is supported for legacy API only
94
+ */
95
+ $te ?: ( key : Path , locale ?: Locale ) => boolean
96
+ /**
97
+ * datetime method
98
+ *
99
+ * @param value - required, type `number` or `Date`
100
+ * @param key - optional, type {@link Path} or `Object`
101
+ * @param locale - optional, type {@link Locale}
102
+ * @returns formatted datetime result
103
+ *
104
+ * @remarks
105
+ * Localize the datetime of `value` with datetime format of `key`.
106
+ * The datetime format of `key` need to register to `dateTimeFormats` option of {@link VueI18nOptions},
107
+ * and depend on `locale` option of {@link VueI18nOptions}.
108
+ * If you will specify locale argument, it will have priority over `locale` of {@link VueI18nOptions}.
109
+ *
110
+ * If the datetime format of `key` not exist in `dateTimeFormats` option,
111
+ * fallback to depend on `fallbackLocale` of {@link VueI18nOptions}.
112
+ *
113
+ * This property is supported for legacy API only
114
+ */
115
+ $d ?: ( ...args : unknown [ ] ) => DateTimeFormatResult
116
+ /**
117
+ * number method
118
+ *
119
+ * @param value - required, type `number`
120
+ * @param format - optional, type {@link Path} or `Object`
121
+ * @param locale - optional, type {@link Locale}
122
+ * @returns formatted number result
123
+ *
124
+ * @remarks
125
+ * Localize the number of `value` with number format of `format`.
126
+ * The number format of `format` need to register to `numberFormats` option of {@link VueI18nOptions},
127
+ * and depend on `locale` option of {@link VueI18nOptions}.
128
+ * If you will specify `locale` argument, it will have priority over `locale` option of {@link VueI18nOptions}
129
+ *
130
+ * If the number format of `format` not exist in `numberFormats` option,
131
+ * fallback to depend on `fallbackLocale` option of {@link VueI18nOptions}
132
+ *
133
+ * This property is supported for legacy API only
134
+ */
135
+ $n ?: ( ...args : unknown [ ] ) => NumberFormatResult
136
+ }
137
+ }
138
+
16
139
// supports compatibility for legacy vue-i18n APIs
17
140
export function defineMixin (
18
141
legacy : VueI18n & VueI18nInternal ,
0 commit comments