/
types.d.ts
216 lines (207 loc) · 6.98 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import type { NuxtApp } from '#app'
import type { ComputedRef } from 'vue'
import type {
LocaleObject,
Strategies,
Directions,
ComposerCustomProperties as _ComposerCustomProperties
} from 'vue-i18n-routing'
import type { I18nRoutingCustomProperties } from 'vue-i18n-routing/dist/vue-i18n'
/**
* Called before the app's locale is switched.
*
* @remarks
* Can be used to override the new locale by returning a new locale code.
*
* @param oldLocale - The app's locale before the switch.
* @param newLocale - The app's locale after the switch.
* @param initialSetup - Set to `true` if it's the initial locale switch that triggers on app load. It's a special case since the locale is not technically set yet so we're switching from no locale to locale.
* @param context - the Nuxt app instance.
*
* @returns The new locale to switch, or `undefined` to keep the new locale.
*/
type BeforeLanguageSwitchHandler = (
oldLocale: string,
newLocale: string,
initialSetup: boolean,
context: NuxtApp
) => Promise<string | void>
/**
* Called after the app's locale is switched.
*
* @param oldLocale - The app's locale before the switch
* @param newLocale - The app's locale after the switch.
*/
type LanguageSwitchedHandler = (oldLocale: string, newLocale: string) => Promise<void>
export interface ComposerCustomProperties {
/**
* Routing strategy.
*/
strategy: Strategies
/**
* Current locale properties.
*/
localeProperties: ComputedRef<LocaleObject>
/**
* Whether differentDomains option is enabled.
*/
differentDomains: boolean
/**
* Default direction as specified in options.
*/
defaultDirection: Directions
/**
* Switches locale of the app to specified locale code.
*
* @remarks
* If `useCookie` option is enabled, locale cookie will be updated with new value.
*
* If prefixes are enabled (`strategy` other than `no_prefix`), will navigate to new locale's route.
*
* @param locale - A {@link Locale}
*/
setLocale: (locale: string) => Promise<void>
/**
* Returns browser locale code filtered against the ones defined in options.
*
* @returns The browser locale.
*/
getBrowserLocale: () => string | undefined
/**
* Returns locale code from stored locale cookie.
*
* @returns The locale cookie
*/
getLocaleCookie: () => string | undefined
/**
* Updates stored locale cookie with specified locale code.
*
* @remarks
* Consider using `setLocale` instead if you want to switch locale.
*
* @param locale - A {@link Locale}
*/
setLocaleCookie: (locale: string) => void
/**
* Called before the app's locale is switched.
*
* @remarks
* Can be used to override the new locale by returning a new locale code.
*
* @param oldLocale - The app's locale before the switch.
* @param newLocale - The app's locale after the switch.
* @param initialSetup - Set to `true` if it's the initial locale switch that triggers on app load. It's a special case since the locale is not technically set yet so we're switching from no locale to locale.
* @param context - the Nuxt app instance.
*
* @returns The new locale to switch, or `undefined` to keep the new locale.
*/
onBeforeLanguageSwitch: BeforeLanguageSwitchHandler
/**
* Called after the app's locale is switched.
*
* @param oldLocale - The app's locale before the switch
* @param newLocale - The app's locale after the switch.
*/
onLanguageSwitched: LanguageSwitchedHandler
/**
* Switches to the pending locale that would have been set on navigate, but was prevented by the `skipSettingLocaleOnNavigate` option.
*/
finalizePendingLocaleChange: () => Promise<void>
/**
* Returns a promise that will be resolved once the pending locale is set.
*/
waitForPendingLocaleChange: () => Promise<void>
}
export interface NuxtI18nRoutingCustomProperties {
/**
* Routing strategy.
*/
readonly strategy: Strategies
/**
* Current locale properties.
*/
localeProperties: LocaleObject
/**
* Whether differentDomains option is enabled.
*/
readonly differentDomains: boolean
/**
* Default direction as specified in options.
*/
readonly defaultDirection: Directions
/**
* Switches locale of the app to specified locale code.
*
* @remarks
* If `useCookie` option is enabled, locale cookie will be updated with new value.
*
* If prefixes are enabled (`strategy` other than `no_prefix`), will navigate to new locale's route.
*
* @param locale - A {@link Locale}
*/
setLocale: (locale: string) => Promise<void>
/**
* Returns browser locale code filtered against the ones defined in options.
*
* @returns The browser locale.
*/
getBrowserLocale: () => string | undefined
/**
* Returns locale code from stored locale cookie.
*
* @returns The locale cookie
*/
getLocaleCookie: () => string | undefined
/**
* Updates stored locale cookie with specified locale code.
*
* @remarks
* Consider using `setLocale` instead if you want to switch locale.
*
* @param locale - A {@link Locale}
*/
setLocaleCookie: (locale: string) => void
/**
* Called before the app's locale is switched.
*
* @remarks
* Can be used to override the new locale by returning a new locale code.
*
* @param oldLocale - The app's locale before the switch.
* @param newLocale - The app's locale after the switch.
* @param initialSetup - Set to `true` if it's the initial locale switch that triggers on app load. It's a special case since the locale is not technically set yet so we're switching from no locale to locale.
* @param context - the Nuxt app instance.
*
* @returns The new locale to switch, or `undefined` to keep the new locale.
*/
onBeforeLanguageSwitch: BeforeLanguageSwitchHandler
/**
* Called after the app's locale is switched.
*
* @param oldLocale - The app's locale before the switch
* @param newLocale - The app's locale after the switch.
*/
onLanguageSwitched: LanguageSwitchedHandler
/**
* Switches to the pending locale that would have been set on navigate, but was prevented by the `skipSettingLocaleOnNavigate` option.
*/
finalizePendingLocaleChange: () => Promise<void>
/**
* Returns a promise that will be resolved once the pending locale is set.
*/
waitForPendingLocaleChange: () => Promise<void>
}
declare module 'vue-i18n' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface ComposerCustom extends ComposerCustomProperties, _ComposerCustomProperties {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface ExportedGlobalComposer extends NuxtI18nRoutingCustomProperties, I18nRoutingCustomProperties {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface VueI18n extends NuxtI18nRoutingCustomProperties, I18nRoutingCustomProperties {}
interface I18n {
__pendingLocale?: string
__pendingLocalePromise?: Promise<void>
__resolvePendingLocalePromise?: (value: void | PromiseLike<void>) => void
}
}
export {}