Skip to content

Commit 5a9f233

Browse files
authored
Updates to Nuxt 3 integration guide (#1520)
1 parent bb03bc6 commit 5a9f233

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

docs/guide/integrations/nuxt3.md

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nuxt 3 integration
22

3-
We will introduce Vue I18n integration for Nuxt 3.
3+
We will introduce Vue I18n integration with Nuxt 3.
44

55
The following is a tutorial on setting up a Nuxt 3 application from the initial configuration.
66

@@ -39,7 +39,7 @@ Run the following command to create a Nuxt 3 application:
3939
npx nuxi init nuxt3-app-vue-i18n
4040
```
4141

42-
We will have run the above command, it will be created Nuxt 3 initial project with the following directory structure:
42+
Once we have run the above command, the created Nuxt 3 initial project will have the following directory structure:
4343

4444
```
4545
cd nuxt3-app-vue-i18n
@@ -62,21 +62,19 @@ npm install --save-dev vue-i18n
6262

6363
### Setup Nuxt plugin
6464

65-
We will set up the Nuxt plugin.
66-
6765
Create a `plugins` directory as follows:
6866

6967
```sh
7068
mkdir plugins
7169
```
7270

73-
Next, create a Nuxt plugin file to implement for setting up Vue I18n.
71+
Next, create a Nuxt plugin file to set up Vue I18n.
7472

7573
```sh
7674
touch plugins/i18n.ts
7775
```
7876

79-
When we have created it, edit it with the below codes:
77+
Once created, define the plugin as follows:
8078

8179
```ts
8280
import { createI18n } from 'vue-i18n'
@@ -97,9 +95,7 @@ export default defineNuxtPlugin(({ vueApp }) => {
9795
})
9896
```
9997

100-
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)
10399

104100
### Run the Nuxt 3 application
105101

@@ -116,24 +112,25 @@ We will edit `app.vue` of the setup Nuxt 3 application as follows:
116112
</template>
117113
```
118114

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:
120116

121117
```sh
122118
npm run dev
123119
```
124120

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:
126122

127123
![Nuxt3 setup](/nuxt3-setup.png)
128124

129125
## Localize your Nuxt 3 application
130126

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.
133128

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. 🌎 🌍 🌏
135130

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.
137134

138135
### Add language switching
139136

@@ -162,25 +159,25 @@ The value of each option defines the value of the locale code, which will be exp
162159

163160
### Externalize locale resources
164161

165-
We will define the locale resources as externalizing.
162+
We will define the locale resources as external.
166163

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.
168165

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:
170167

171168
```sh
172169
mkdir locales
173170
```
174171

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:
176173

177174
```sh
178175
touch locales/en.json # for english
179176
touch locales/fr.json # for french
180177
touch locales/ja.json # for japanese
181178
```
182179

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:
184181

185182
For english at `locales/en.json`:
186183

@@ -211,9 +208,7 @@ For japanese at `locales/ja.json`:
211208

212209
### Import locale resources
213210

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:
217212

218213
```js
219214
import { createI18n } from 'vue-i18n'
@@ -240,23 +235,23 @@ export default defineNuxtPlugin(({ vueApp }) => {
240235
})
241236
```
242237

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.
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.
244239

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.
246241

247242
![Setup i18n on Nuxt3](/nuxt3-setup-i18n.gif)
248243

249-
Your Nuxt 3 application is now ready for basic internationalization!
244+
The Nuxt 3 application is now ready for basic internationalization! 🎉
250245

251246
## Optimize with `@intlify/unplugin-vue-i18n`
252247

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.
254249

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.
256251

257252
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.
258253

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.
260255

261256
### Install `@intlify/unplugin-vue-i18n`
262257

@@ -294,9 +289,9 @@ In `vite.plugins`, the plugin for `@intlify/unplugin-vue-i18n` is configured. As
294289
295290
### Inside of bundling with optimization
296291
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!
298293
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.
300295

301296
The following is a comparison of bundle sizes measured in the network tab of devtools with and without `@intlify/unplugin-vue-i18n`:
302297

@@ -308,14 +303,14 @@ By setting up this plugin, the plugin will internally set up a Vue I18n module t
308303

309304
About details, see `@intlify/unplugin-vue-i18n` [docs](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#runtimeonly)
310305

311-
Also, you can see the changing in the bandling of locale resources.
306+
Also, you can see the changes in the bundling of locale resources.
312307

313308
Code for locale resources, depending on whether or not the `@intlify/unplugin-vue-i18n` plugin to `vite.plugins` is set. Below:
314309

315310
![Pre-compile](/nuxt3-pre-compile.png)
316311

317312
Without the `@intlify/unplugin-vue-i18n` plugin to `vite.plugins`, locale resources are bundled as **json**, but with this plugin set, locale resources are **converted from json to JavaScript code** for bandwidth.
318313

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 functions since they have already been compiled.
320315

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 this guide, the Nuxt 3 application is small, so we can not enough experience the performance of the optimization but as the application gets larger, it will definitely benefit from it.

0 commit comments

Comments
 (0)