---
title: "nuxt-i18n"
description: "The preset for @nuxtjs/i18n. It adds everything of vue-i18n, and finds the locale directory of the Nuxt config."
canonical_url: "https://x18n.dev/presets/nuxt-i18n"
---
# nuxt-i18n

> The preset for @nuxtjs/i18n. It adds everything of vue-i18n, and finds the locale directory of the Nuxt config.

The `nuxt-i18n` preset supports [@nuxtjs/i18n](https://i18n.nuxtjs.org), the i18n module for Nuxt.

## Detection

The preset applies when the project depends on `@nuxtjs/i18n` or `nuxt-i18n`. It is not exclusive: x18n still tests the presets after it.

```ts [x18n.config.ts]
import { defineConfig } from '@x18n/core'

export default defineConfig({
  presets: ['nuxt-i18n'],
})
```

## What it adds

The preset includes every plugin of the [`vue-i18n`](https://x18n.dev/presets/vue-i18n) preset: the translate calls, the Vue template syntax, `<i18n>` blocks, the placeholders and the extraction templates.

It also finds the locale files. If your config has no `resources`, the preset reads `nuxt.config.ts` (or `nuxt.config.js`) and looks for `langDir`:

| Nuxt config       | Resource patterns                                                                 |
| ----------------- | --------------------------------------------------------------------------------- |
| `langDir: 'lang'` | `i18n/lang/{locale}.{ext}` and `lang/{locale}.{ext}`                              |
| no `langDir`      | `i18n/locales/{locale}.{ext}`, `locales/{locale}.{ext}` and `lang/{locale}.{ext}` |

The preset reads `langDir` as text. If the value is computed, set `resources` in the config.

Locale files can be JSON, YAML, JavaScript or TypeScript. x18n reads a static object in a `.js` or `.ts` file, also when `defineI18nLocale` wraps it, and edits it in place:

```ts [i18n/locales/en.ts]
export default defineI18nLocale(async locale => ({
  hello: 'Hello',
}))
```

A loader that computes its messages (for example with `fetch`) is not static. x18n reports it as [`X18N2004`](https://x18n.dev/errors/x18n2004).

To read such a file, set `execute: true` on its [resource pattern](https://x18n.dev/references/config#resources). x18n then runs the file in Node, calls the loader with the locale, and shows the messages read-only. The file runs outside Nuxt, so auto-imports are not defined: import `defineI18nLocale` from `@nuxtjs/i18n` (or drop the wrapper), as well as anything else the file uses.

## Supported syntax

The syntax is the same as for [vue-i18n](https://x18n.dev/presets/vue-i18n#supported-syntax):

```vue
<script setup lang="ts">
const { t } = useI18n()
const title = t('app.title')
</script>

<template>
  <h1>{{ $t('app.greeting', { name: 'Ada' }) }}</h1>
  <a v-t="'nav.home'" />
</template>
```


## Sitemap

See the full [sitemap](https://x18n.dev/sitemap.md) for all pages.
