Skip to content

Vue I18n

Vue & Nuxt Translation with Vue I18n

Work with Vue I18n catalogs in Vue 3, or connect them to Nuxt's locale routing and server rendering.

TransLocale documentation · Updated September 17, 2026 · Markdown quick start

New to TransLocale? Follow the screenshot walkthrough to create a project, add keys and translations, review wording, and get credentials. Use this guide’s message format and catalog names for your app. Your project ID is under Project settings → Credentials.

1. Install

Run this from your application directory.

npm install @translocale/vue vue-i18n

2. Connect your project

Create a cloud project and replace PROJECT_UUID with its ID. The source and target languages must match your local configuration. Adjust the example locales to your project.

npx translocale-vue init --api https://translocale.io --project PROJECT_UUID --locales en,fr,ja

Approve translation access in the browser:

npx translocale-vue login --scope translate

Sign-in is shared with your other TransLocale tools for this project. Keep credentials in developer tooling or CI. Your deployed app reads its own translation files.

3. Wire up your app

Vue setup generates src/translocale-i18n.ts. Register its createTransLocaleI18n(locale) factory with your app. For Nuxt, install @nuxtjs/i18n and add --framework nuxt to init instead; use createNuxtI18nOptions from @translocale/vue/nuxt in nuxt.config.ts. The included README has the complete Nuxt configuration. Download all target catalogs before building.

4. Translate, review, and download

Inspect the plan before running translate. The example caps the job at 1,000 source characters across its target languages. Waiting stops after two minutes; a timeout leaves the job running.

npx translocale-vue plan
npx translocale-vue translate --max-characters 1000 --wait
npx translocale-vue pull --job JOB_UUID --locale fr --revision 1
npx translocale-vue check

Replace JOB_UUID with the completed job ID. Before pulling revision 1, save that revision in the dashboard and review its wording. Choose the exact saved revision you want to ship, then repeat pull for each target locale. Revision 0 is the original generated output.

Normal application builds use saved catalogs and make no paid translation requests.

Already have translations?

Run npx translocale-vue discover --source en to find existing JSON catalogs. Nuxt uses the same discovery and sync commands. Sync shows local and incoming changes against the recorded revision and keeps recovery copies when you apply a reviewed update.

Change the language in Vue I18n

Use the global composer when a language switch should update the whole Vue app. With the generated createTransLocaleI18n factory registered through app.use(), the component below binds its selector to that composer's locale. Both languages must have local catalog files and appear in translocale.config.json.

locales/en.json
{
  "welcome": "Hello, {name}",
  "items": "No items | One item | {count} items"
}
locales/fr.json
{
  "welcome": "Bonjour, {name}",
  "items": "Aucun article | Un article | {count} articles"
}
LanguageSwitcher.vue
<script setup>
import {useI18n} from 'vue-i18n';
const {t, locale} = useI18n({useScope: 'global'});
</script>

<template>
  <label>
    Language
    <select v-model="locale">
      <option value="en">English</option>
      <option value="fr">Français</option>
    </select>
  </label>
  <p>{{ t('welcome', {name: 'Sam'}) }}</p>
  <p>{{ t('items', 3) }}</p>
</template>

Selecting Français changes the greeting to “Bonjour, Sam” and the count to “3 articles”. If only one component changes language, check whether it created a local composer. useScope: 'global' selects the app's composer. In script code, assign locale.value; Vue templates unwrap the ref for v-model.

Create a fresh i18n instance for each server-rendered app. The generated factory copies the catalogs for each call. Keep the Node.js package entry point in developer tooling; browser components import Vue I18n and the generated module.

Load JSON translation files in Nuxt

Nuxt uses the same Vue I18n JSON catalogs, with @nuxtjs/i18n responsible for loading them and routing between languages. Install the module, then initialize with the Nuxt option from your app directory. For an existing TransLocale configuration, review its locale list and file pattern instead of initializing again.

Initialize Nuxt catalog tooling
npm install @translocale/vue vue-i18n @nuxtjs/i18n
npx translocale-vue init --framework nuxt --api https://translocale.io --project PROJECT_UUID --source en --locales en,fr

The default files pattern is locales/{locale}.json. Supply both example files above before starting Nuxt. Setup creates a source file if missing; it does not generate target translations. Keep your existing Nuxt options and add the module configuration below.

nuxt.config.ts
import {fileURLToPath} from 'node:url';
import {createNuxtI18nOptions} from '@translocale/vue/nuxt';

export default defineNuxtConfig({
  modules: ['@nuxtjs/i18n'],
  i18n: createNuxtI18nOptions({
    root: fileURLToPath(new URL('.', import.meta.url)),
  }),
});

The helper reads translocale.config.json from root, checks every configured catalog, and returns project-relative paths such as locales/fr.json. It sets restructureDir and langDir to '.' to preserve those paths. If a file cannot be found, compare the configured files pattern with its actual path and confirm root points to the Nuxt app.

The default routing strategy is prefix_except_default: English is unprefixed and French routes use /fr. Browser-language redirection is disabled by this helper. For route-aware language changes, use Nuxt's setLocale API instead of assigning the Vue locale ref directly.

Switch to the French route in Nuxt
<script setup>
const {setLocale} = useI18n();
</script>

<template>
  <button type="button" @click="setLocale('fr')">Français</button>
</template>
Check before starting or building
npx translocale-vue check

A missing French file or a changed {name} placeholder stops the catalog check. Restore the file or placeholder and repeat it. Local checks and builds need no TransLocale credential and do not start translation jobs. Custom plural rules and catalogs embedded in .vue files remain outside this adapter's supported format.

Current limits

  • Use Vue I18n 11.4.x with the default plural rules. Custom compilers, custom plural rules, and catalogs embedded in .vue components are not supported.
  • Nuxt server rendering and hydration have been tested in local Cloudflare. Hosted consumers, Nuxt layers, and domain-based routing still need verification.

The service accepts up to 100 KB and 200 messages per source document. Expanded target messages must also fit the adapter's limits. Read the file compatibility guide.

Check a file before connecting

Try the free source file checker to inspect message structure without an account. For assistant setup and read-only catalog checks, follow the MCP localization guide.