{{ $t('hello', { name: 'vue-i18n' }) }}
// [!code ++]
```
Language switching is implemented using the `select` element on `form`.
The value of each option is defined as the value of the locale code, which will be explained later in the externalization of locale resources.
The value of each option defines the value of the locale code, which will be explained later in the externalization of locale resources.
### Externalize locale resources
We will define the locale resources as external.
There are several file formats for resources supported by Vue I18n, we'll opt for JSON in this particular case.
Let's create a non-"Nuxt-3-standard" directory named `locales` by running:
```sh
mkdir locales
```
Now, let's create the JSON files for each of the locales we want to support:
```sh
touch locales/en.json # for english
touch locales/fr.json # for french
touch locales/ja.json # for japanese
```
Let's populate them with the following:
For english at `locales/en.json`:
```json
{
"hello": "Hello, {name}!",
"language": "Language"
}
```
For french at `locales/fr.json`:
```json
{
"hello": "Bonjour, {name}!",
"language": "Langue"
}
```
For japanese at `locales/ja.json`:
```json
{
"hello": "こんにちは、{name}!",
"language": "言語"
}
```
### Import locale resources
Let's "register" the locales in our plugin (`plugins/i18n.ts`) as follows:
```js
import { createI18n } from 'vue-i18n'
import en from '../locales/en.json' // [!code ++]
import fr from '../locales/fr.json' // [!code ++]
import ja from '../locales/ja.json' // [!code ++]
export default defineNuxtPlugin(({ vueApp }) => {
const i18n = createI18n({
globalInjection: true,
locale: 'en',
messages: {
en: { // [!code --]
hello: "Hello, {name}!" // [!code --]
} // [!code --]
en, // [!code ++]
fr, // [!code ++]
ja // [!code ++]
}
})
vueApp.use(i18n)
})
```
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.
Let's run `npm run dev` (or `yarn dev` or `pnpm dev`) and head to `http://localhost:3000` to see if the changes so far work.

The Nuxt application is now ready for basic internationalization! 🎉
## Optimize with `@intlify/unplugin-vue-i18n`
So far, you have been able to use Vue I18n to support language switching on the Nuxt 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.
However, as described in [Optimization](../advanced/optimization), the Nuxt application prepared so far is sub-optimal in its bundle size.
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.
Enter [@intlify/unplugin-vue-i18n](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n), a Vue I18n to optimize performance.
### Install `@intlify/unplugin-vue-i18n`
::: code-group
```sh [npm]
npm install @intlify/unplugin-vue-i18n -D
```
```sh [yarn]
yarn add @intlify/unplugin-vue-i18n -D
```
```sh [pnpm]
pnpm add -D @intlify/unplugin-vue-i18n
```
:::
### Configure Nuxt config
Configure `nuxt.config.ts` like the below:
```js
import { defineNuxtConfig } from 'nuxt'
import { resolve, dirname } from 'node:path' // [!code ++]
import { fileURLToPath } from 'url' // [!code ++]
import VueI18nVitePlugin from '@intlify/unplugin-vue-i18n/vite' // [!code ++]
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
build: { // [!code ++]
transpile: ['vue-i18n'] // [!code ++]
}, // [!code ++]
vite: { // [!code ++]
plugins: [ // [!code ++]
VueI18nVitePlugin({ // [!code ++]
include: [ // [!code ++]
resolve(dirname(fileURLToPath(import.meta.url)), './locales/*.json') // [!code ++]
] // [!code ++]
}) // [!code ++]
] // [!code ++]
} // [!code ++]
})
```
The bundler for Nuxt is vite by default. So we will use the `vite` option here for optimization.
In `vite.plugins`, the plugin for `@intlify/unplugin-vue-i18n` is configured. As an option for this plugin, the `include` option specifies locale resources in json format placed in the `locales` directory. This allows `@intlify/unplugin-vue-i18n` to pre-compile locale resources at bundle time using Vue I18n message compiler internally. This improves the translation performance of Vue I18n and consequently the rendering performance of Nuxt applications.
### Inside of bundling with optimization
Once finished with the setup, run `npm run dev` to check it out!
After accessing `http://localhost:3000`, the behavior of the Nuxt application remains the same, but there is a change in the bandwidth of the Nuxt application.
The following is a comparison of bundle sizes measured in the network tab of devtools with and without `@intlify/unplugin-vue-i18n`:

The area highlighted in blue is the code bundled by vite.
By setting up this plugin, the plugin will internally set up a Vue I18n module that is runtime-only. Specifically, vite config `resolve.alias`, set the `vue-i18n` alias to use only the Vue I18n runtime (`vue-i18n/dist/vue-i18n.runtime.esm-bundler.js`). This setting reduces the bundle size since the message compiler used by Vue I18n is not included.
About details, see `@intlify/unplugin-vue-i18n` [docs](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#runtimeonly)
Also, you can see the changes in the bundling of locale resources.
Code for locale resources, depending on whether or not the `@intlify/unplugin-vue-i18n` plugin to `vite.plugins` is set. Below:

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.
Vue I18n just call the functions since they have already been compiled.
In this guide, the Nuxt 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.