You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Language switching is implemented using the `select` element on `form`.
@@ -183,6 +183,7 @@ touch locales/ja.json # for japanese
183
183
And more then, We will have saved each created locale resource file for each language as follows:
184
184
185
185
For english at `locales/en.json`:
186
+
186
187
```json
187
188
{
188
189
"hello": "Hello, {name}!",
@@ -191,6 +192,7 @@ For english at `locales/en.json`:
191
192
```
192
193
193
194
For french at `locales/fr.json`:
195
+
194
196
```json
195
197
{
196
198
"hello": "Bonjour, {name}!",
@@ -199,6 +201,7 @@ For french at `locales/fr.json`:
199
201
```
200
202
201
203
For japanese at `locales/ja.json`:
204
+
202
205
```json
203
206
{
204
207
"hello": "こんにちは、{name}!",
@@ -212,29 +215,29 @@ We will import locale resources that is defined in the `locales` directory for u
212
215
213
216
And then, change `plugins/i18n.ts` as follows:
214
217
215
-
```diff
216
-
import { createI18n } from 'vue-i18n'
217
-
+import en from '../locales/en.json'
218
-
+import fr from '../locales/fr.json'
219
-
+import ja from '../locales/ja.json'
220
-
221
-
export default defineNuxtPlugin(({ vueApp }) => {
222
-
const i18n = createI18n({
223
-
legacy: false,
224
-
globalInjection: true,
225
-
locale: 'en',
226
-
messages: {
227
-
- en: {
228
-
- hello: "Hello, {name}!"
229
-
- }
230
-
+ en,
231
-
+ fr,
232
-
+ ja
233
-
}
234
-
})
235
-
236
-
vueApp.use(i18n)
237
-
})
218
+
```js
219
+
import { createI18n } from'vue-i18n'
220
+
importenfrom'../locales/en.json'// [!code ++]
221
+
importfrfrom'../locales/fr.json'// [!code ++]
222
+
importjafrom'../locales/ja.json'// [!code ++]
223
+
224
+
exportdefaultdefineNuxtPlugin(({ vueApp }) => {
225
+
consti18n=createI18n({
226
+
legacy:false,
227
+
globalInjection:true,
228
+
locale:'en',
229
+
messages: {
230
+
en: {// [!code --]
231
+
hello:"Hello, {name}!"// [!code --]
232
+
}// [!code --]
233
+
en,// [!code ++]
234
+
fr,// [!code ++]
235
+
ja// [!code ++]
236
+
}
237
+
})
238
+
239
+
vueApp.use(i18n)
240
+
})
238
241
```
239
242
240
243
It’s set locale resources for each imported language to `messages` option, so you can manage locale resources with separating from code in the `locales` directory. It also facilitates integration with the localization service.
0 commit comments