Getting Started
Relevant source files
The following files were used as context for generating this wiki page:
Nuxt I18n Micro provides a high-performance internationalization framework for Nuxt 3 applications. It focuses on minimizing build times, memory consumption, and bundle sizes compared to traditional i18n solutions. This guide outlines the initial setup, core configuration, and development workflow for integrating the module into your project.
Sources: README.md:10-18, AGENTS.md:10-15
Installation and Quick Setup
You must install the nuxt-i18n-micro package via your preferred package manager. After installation, register the module in your nuxt.config.ts file and provide the required locale configurations.
export default defineNuxtConfig({
modules: [
'nuxt-i18n-micro',
],
i18n: {
locales: [
{ code: 'en', iso: 'en-US', dir: 'ltr' },
{ code: 'fr', iso: 'fr-FR', dir: 'ltr' },
{ code: 'ar', iso: 'ar-SA', dir: 'rtl' },
],
defaultLocale: 'en',
translationDir: 'locales',
meta: true,
},
})
Sources: README.md:92-114
Core Configuration Options
The module options are categorized into logical groups to manage routing, translations, and SEO.
| Category | Description | Key Options |
|---|---|---|
| Locales and Routing | Defines available languages and URL structures. | locales, defaultLocale, strategy |
| Translations | Configures translation file resolution and directory. | translationDir, fallbackLocale |
| SEO | Manages meta tag generation for localized pages. | meta |
| Detection | Handles automatic locale detection for new visitors. | autoDetect |
Sources: scripts/src/commands/docs-generate.ts:25-63
Project Architecture and Workspace
The project is structured as a monorepo using pnpm workspaces. It separates core domain logic from framework-specific bindings.
The diagram above shows the relationship between the root Nuxt module and the shared internal packages.
Sources: AGENTS.md:10-25
Development Workflow
When working within the repository or setting up a local development environment, you must follow a specific build order to ensure dependencies are resolved correctly.
First-Time Setup
- Install dependencies: Use
pnpm install. - Build internal packages: Run build for all packages except playgrounds.
- Prepare development environment: Execute
pnpm run dev:prepareto loadsrc/module.tsand generate Nuxt types. - Build playgrounds: Build specific package playgrounds to generate virtual configuration declarations.
Sources: AGENTS.md:33-45
Routing Strategies
The module utilizes @i18n-micro/route-strategy to generate localized route trees during the build phase. You can choose from four primary strategies:
- no_prefix: URLs remain unprefixed; the locale is handled via runtime state or cookies.
- prefix: Every localized route receives a prefix (e.g.,
/en/about). - prefix_except_default: The default locale has no prefix, while others are prefixed.
- prefix_and_default: The default locale is accessible both with and without a prefix.
Sources: packages/route-strategy/README.md:31-50
Basic Usage in Components
You access i18n functionality through Nuxt composables and injected helpers. In a Vue component, you typically use useNuxtApp() to retrieve helpers like $t (translation), $tc (pluralization), and $localeRoute.
<script setup lang="ts">
const { $t, $tc, $getLocale, $switchLocale, $localeRoute } = useNuxtApp()
// Define route-specific translations and custom paths
$defineI18nRoute({
locales: {
en: { greeting: 'Hello' },
ru: { greeting: 'Привет' }
},
localeRoutes: {
ru: '/privet-page'
}
})
</script>
<template>
<div>
<p>{{ $t('greeting') }}</p>
<NuxtLink :to="$localeRoute({ name: 'index' })">Home</NuxtLink>
</div>
</template>
Sources: playground/pages/subpage.vue:128-154
Nuxt I18n Micro optimizes the internationalization process by separating build-time route generation from a lightweight runtime. This architecture ensures that even projects with large translation volumes maintain high performance and low resource overhead.
Sources: README.md:15-25, packages/route-strategy/README.md:10-25