Migration Guide
Relevant source files
The following files were used as context for generating this wiki page:
The Migration Guide provides technical instructions for transitioning from traditional i18n solutions, specifically @nuxtjs/i18n, to nuxt-i18n-micro. This module optimizes performance by reducing memory consumption, build times, and bundle sizes while maintaining high-traffic stability.
Sources: README.md:14-25, AGENTS.md:7-14
Performance Motivations for Migration
Migrating to nuxt-i18n-micro resolves critical performance bottlenecks found in larger i18n implementations. The module focuses on minimizing build overhead and server response times through a lightweight core and strategy-based routing.
Comparative Metrics
| Metric | plain-nuxt (baseline) | i18n-micro | @nuxtjs/i18n v10.6 |
|---|---|---|---|
| Build Time | 5.07s | 5.01s | 8.23s |
| Max Memory | 859 MB | 997 MB | 1,292 MB |
| RPS (Artillery) | 102 | 230 | 126 |
Sources: README.md:34-45
Module Configuration Migration
You define module options within the i18n block of nuxt.config.ts. The configuration is grouped into functional areas: routing, translations, payloads, and SEO.
Configuration Mapping
| Option | Type | Purpose |
|---|---|---|
locales | Array | Defines supported languages with code, ISO, and direction. |
strategy | String | Determines URL structure (prefix, no_prefix, etc.). |
translationDir | String | Specifies the directory for JSON translation files. |
defaultLocale | String | Sets the fallback and default language code. |
meta | Boolean | Enables automatic SEO meta tag generation. |
Sources: scripts/src/commands/docs-generate.ts:25-68, README.md:92-108
Injected Helpers and API Changes
The module injects helpers into the Nuxt context. Most helpers follow a $ prefix convention. If you are migrating from vue-i18n, you must update your template calls and script setups to use these specific methods.
Helper Reference
$t(key, params): Translates a specific key with optional interpolation.$tc(key, count): Handles pluralization logic based on the provided count.$tn(number): Formats numbers according to the current locale.$td(date): Formats date objects or strings.$localeRoute(route, locale): Generates a localized URL for a given route name or object.$defineI18nRoute(config): Configures per-page translations and route overrides directly within a component.
Sources: test/fixtures/basic/pages/locale-test.vue:30-48, playground/pages/subpage.vue:157-170, scripts/src/commands/docs-generate.ts:133-145
Routing Strategy Transition
The module utilizes @i18n-micro/route-strategy to localize Nuxt pages at build time. You must select a strategy that matches your desired URL structure.
The diagram shows how different strategies transform a standard page path into localized variants.
Strategy Behaviors
- no_prefix: URLs remain unchanged; the locale is managed via cookies or runtime state.
- prefix: Every localized route receives a mandatory prefix (e.g.,
/en/). - prefix_except_default: Only non-default locales receive a prefix.
- prefix_and_default: The default locale exists at both prefixed and unprefixed paths.
Sources: packages/route-strategy/README.md:27-58
Translation Loading and Fallback
nuxt-i18n-micro uses a hierarchical translation resolution system. It merges global translations with page-specific translations during runtime.
The sequence illustrates the multi-step resolution process involving global files, page files, and fallback locales.
Fallback Logic
The system builds a unique fallback chain for each locale. If a key is missing in the target locale, the engine traverses the fallbackLocale definitions until it finds a value or reaches the globalFallbackLocale.
Sources: packages/utils/tests/merge-source-translations.test.ts:10-55, scripts/src/commands/docs-generate.ts:25-30
Setup and Build Order
When migrating in a monorepo or local development environment, follow the exact build order to ensure type safety and internal package availability.
- Install dependencies:
pnpm install - Build internal packages:
pnpm --filter "./packages/**" --filter "!./packages/*/playground" run build - Prepare Nuxt:
pnpm run dev:prepare - Build playgrounds:
pnpm --filter "./packages/*/playground" run build
Sources: AGENTS.md:30-45
Summary of Migration Steps
- Replace Module: Uninstall
@nuxtjs/i18nand installnuxt-i18n-micro. - Update Config: Migrate the
i18nconfiguration innuxt.config.tsto the new schema, ensuringtranslationDirpoints to your JSON files. - Refactor Components: Replace usage of
useI18nor global$twith the module's injected helpers like$t,$tc, and$localeRoute. - Define Page Translations: For page-specific keys, use the
$defineI18nRoutehelper within your Vue components to provide localized content and route overrides. - Verify Routing: Select the appropriate
strategyto maintain existing SEO and URL structures.
Sources: README.md:88-108, test/fixtures/basic/pages/locale-test.vue:64-105