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
We aim to set up Vue I18n in the implementation here.
101
-
102
-
Configure up locale resources to localize a Nuxt 3 application is described in the next section.
98
+
Configuration of locale resources to localize a Nuxt 3 application is described in the [next section](#localize-your-nuxt-3-application)
103
99
104
100
### Run the Nuxt 3 application
105
101
@@ -116,24 +112,25 @@ We will edit `app.vue` of the setup Nuxt 3 application as follows:
116
112
</template>
117
113
```
118
114
119
-
We have edited and saved, run the following command to run the Nuxt 3 application at local:
115
+
We have edited and saved, run the following command to run the Nuxt 3 application in local:
120
116
121
117
```sh
122
118
npm run dev
123
119
```
124
120
125
-
After we will run the command and access to`http://localhost:3000`, you can see the display similar to the following:
121
+
Once the application is served on`http://localhost:3000`, we'll see the following:
126
122
127
123

128
124
129
125
## Localize your Nuxt 3 application
130
126
131
-
So far we have been able to integrate Vue I18n into our Nuxt 3 application.
132
-
Next, we will implement language switching and import locale resources from outside.
127
+
So far, we have been able to integrate Vue I18n into our Nuxt 3 application. Let's implement language switching and import locale resources from outside.
133
128
134
-
By implementing language switching, we can i18n our Nuxt 3 application. Also, when we will be separating locale resources from the source code and externalizing them, we can be localized in a separate workflow using the Localization service.
129
+
By implementing language switching we are effectively, i18n our Nuxt 3 application. 🌎 🌍 🌏
135
130
136
-
In the following sections, we will work on Nuxt 3 applications that support English, French, and Japanese.
131
+
Also, when we separate the locale resources from the source code (externalizing them), we can use a separate workflow with the help of the Localization service in order to localize the app.
132
+
133
+
In the following sections, we will enable support for English, French, and Japanese on out Nuxt 3 app.
137
134
138
135
### Add language switching
139
136
@@ -162,25 +159,25 @@ The value of each option defines the value of the locale code, which will be exp
162
159
163
160
### Externalize locale resources
164
161
165
-
We will define the locale resources as externalizing.
162
+
We will define the locale resources as external.
166
163
167
-
There are several file formats for resources supported by Vue I18n, so we will use the json format in here.
164
+
There are several file formats for resources supported by Vue I18n, we'll opt for JSON in this particular case.
168
165
169
-
These are managed separately from the directories managed by Nuxt 3 by creating`locales`directories as follows:
166
+
Let's create a non-"Nuxt-3-standard" directory named`locales`by running:
170
167
171
168
```sh
172
169
mkdir locales
173
170
```
174
171
175
-
Then, We will have created a file defining locale resources for English, French, and Japanese as follows:
172
+
Now, let's create the JSON files for each of the locales we want to support:
176
173
177
174
```sh
178
175
touch locales/en.json # for english
179
176
touch locales/fr.json # for french
180
177
touch locales/ja.json # for japanese
181
178
```
182
179
183
-
And more then, We will have saved each created locale resource file for each language as follows:
180
+
Let's populate them with the follwing:
184
181
185
182
For english at `locales/en.json`:
186
183
@@ -211,9 +208,7 @@ For japanese at `locales/ja.json`:
211
208
212
209
### Import locale resources
213
210
214
-
We will import locale resources that is defined in the `locales` directory for use with Vue I18n.
215
-
216
-
And then, change `plugins/i18n.ts` as follows:
211
+
Let's "register" the locales in our plugin (`plugins/i18n.ts`) as follows:
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.
238
+
The `messages` option will be the one holding the local resources we register to it and being as fine-grained as we want. This granularity facilitates integration with the localization service.
244
239
245
-
Let's run `npm run dev`to see if the fixes so far work. When we will have run the command and have be access to `http://localhost:3000`, you can see the display similar to the following:
240
+
Let's run `npm run dev` and head to `http://localhost:3000` to see if the changes so far work.
246
241
247
242

248
243
249
-
Your Nuxt 3 application is now ready for basic internationalization!
244
+
The Nuxt 3 application is now ready for basic internationalization! 🎉
250
245
251
246
## Optimize with `@intlify/unplugin-vue-i18n`
252
247
253
-
So far, you have been able to use Vue I18n to support language switching for your Nuxt 3 application. Also, by externalizing the locale resources, you have separated them from the code, making it easier to manage locale resources and integrate with the localization service.
248
+
So far, you have been able to use Vue I18n to support language switching on the Nuxt 3 application. Also, by externalizing the locale resources, you have separated them from the source code, making it easier to manage locale resources and integrate with the localization service.
254
249
255
-
However, as described in the [Optimization](../advanced/optimization), your Nuxt 3 application prepared so far is not optimized for bundle size.
250
+
However, as described in [Optimization](../advanced/optimization), the Nuxt 3 application prepared so far is sub-optimal in its bundle size.
256
251
257
252
Since Vue I18n v9, the message compiler allows pre-compiling of locale resources for improved performance, but has not yet been optimized for that performance.
258
253
259
-
Finally, we would to introduce with you [@intlify/unplugin-vue-i18n](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n) a Vue I18n to optimize performance.
254
+
Enter [@intlify/unplugin-vue-i18n](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n), a Vue I18n to optimize performance.
260
255
261
256
### Install `@intlify/unplugin-vue-i18n`
262
257
@@ -294,9 +289,9 @@ In `vite.plugins`, the plugin for `@intlify/unplugin-vue-i18n` is configured. As
294
289
295
290
### Inside of bundling with optimization
296
291
297
-
When you have finished the setup, let’s run `npm run dev` to check it out!
292
+
Once finished with the setup, run `npm run dev` to check it out!
298
293
299
-
When you will access to`http://localhost:3000`, the behavior of the Nuxt 3 application remains the same, but there is a change in the bandwidth of the Nuxt 3 application.
294
+
After accessing`http://localhost:3000`, the behavior of the Nuxt 3 application remains the same, but there is a change in the bandwidth of the Nuxt 3 application.
300
295
301
296
The following is a comparison of bundle sizes measured in the network tab of devtools with and without `@intlify/unplugin-vue-i18n`:
302
297
@@ -308,14 +303,14 @@ By setting up this plugin, the plugin will internally set up a Vue I18n module t
308
303
309
304
About details, see `@intlify/unplugin-vue-i18n` [docs](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#runtimeonly)
310
305
311
-
Also, you can see the changingin the bandlingof locale resources.
306
+
Also, you can see the changesin the bundlingof locale resources.
312
307
313
308
Code for locale resources, depending on whether or not the `@intlify/unplugin-vue-i18n` plugin to `vite.plugins` is set. Below:
314
309
315
310

316
311
317
312
Without the `@intlify/unplugin-vue-i18n` plugin to `vite.plugins`, locale resources are bundled as **json**, but withthis plugin set, locale resources are **converted from json to JavaScript code**for bandwidth.
318
313
319
-
Vue I18n just call the functions!if the locale resource is a function, since it has already been compiled.
314
+
Vue I18n just call the functionssince they have already been compiled.
320
315
321
-
In this tutorial, the Nuxt 3 application is small, so we can not enough experience the performance of this optimization, but as the application gets larger, it will benefit from it.
316
+
In thisguide, the Nuxt 3 application is small, so we can not enough experience the performanceofthe optimization but as the application gets larger, it will definitely benefit from it.
0 commit comments