Translation Management & Data Flow
Relevant source files
The following files were used as context for generating this wiki page:
Nuxt I18n Micro manages translation data through a performance-optimized pipeline that spans build-time processing, runtime delivery, and development-time tooling. The system prioritizes small bundle sizes and fast builds by splitting translations between global files and page-specific payloads.
The project architecture separates shared domain logic into packages like core, types, and utils, while framework bindings and runtime behaviors are handled in specialized modules. This structure ensures that translation data remains consistent across different environments, including SSR and client-side hydration.
Sources: AGENTS.md:1-25, README.md:9-25
Build-Time Data Orchestration
During the Nuxt build process, the module orchestrates translation data by scanning defined directories and merging sources from various layers.
Translation Merging and Payload Generation
The module processes translations using two primary utilities: buildTranslationSourceLayers and preMergeLocales.
- Compact Source Build:
buildTranslationSourceLayerscreates a compact translation source from all Nuxt layers into a temporary directory. - Pre-merged Matrix:
preMergeLocalescombines translations from all layers, including additional translation directories, into a final matrix based on locale and page. This processes fallback locales and handles page-level splitting.
If translationPayloads.mode is set to source, the module serves compact sources. Otherwise, it generates a pre-merged matrix for optimal runtime lookup.
Sources: src/module.ts:250-272, packages/utils/tests/additional-translation-dirs.test.ts:25-45
Cache Management
The system uses a dateBuild parameter or a hash of translation files as a cache-buster. This fingerprint ensures that clients only re-download translation payloads when the actual source content changes, rather than on every build.
Sources: src/module.ts:161-171
The diagram above shows the build-time flow where raw JSON files from various directories are scanned, merged, and written to the public assets directory for delivery.
Runtime Data Flow
At runtime, the module delivers translation data based on the application's environment (SSR or Client) and the configured strategy.
Payload Modes
The module supports different delivery modes to balance server load and bundle size:
| Mode | Description |
|---|---|
premerged | Embeds the full page/locale matrix via Nitro serverAssets or serves from public files. |
source | Embeds only compact sources, requiring more runtime processing but smaller initial payloads. |
serverAssets | Embeds payloads directly into the server bundle via Rollup. |
publicAssets | Serves payloads as static JSON files via the web server. |
Sources: src/module.ts:182-191, src/module.ts:607-620
Route and Locale Detection
The RouteGenerator handles the mapping between URL paths and localized routes. It ensures that translation files exist for every resolved page in the Nuxt application and generates data routes for pre-rendering.
Sources: src/module.ts:315-326, src/module.ts:515-528
Development Tooling and HMR
Nuxt I18n Micro includes a dedicated DevTools UI and Hot Module Replacement (HMR) to streamline the translation workflow.
DevTools API and File Management
The DevTools plugin provides a Vite middleware that interacts with the filesystem. It exposes several endpoints for managing translation data:
/__i18n_api/files: Scans thetranslationDirrecursively to build a directory structure of JSON files./__i18n_api/file: Reads a specific JSON file, ensuring the path is safe within the project root./__i18n_api/save: Writes updated translation content back to the local disk, creating directories if necessary.
Sources: packages/devtools-ui/vite/plugin.ts:14-34, packages/devtools-ui/vite/plugin.ts:376-430
Hot Module Replacement (HMR)
When HMR is enabled, the module generates a plugin that watches translation files in the root and additional directories. This allows the application to update translations in the browser without a full page reload when a developer edits a JSON file.
Sources: src/module.ts:464-490
The sequence diagram illustrates the data flow when a developer saves a translation through the DevTools UI, resulting in a filesystem write and a subsequent UI update.
Summary
Translation Management in Nuxt I18n Micro is a multi-stage process that transforms raw JSON files into optimized payloads. By combining build-time merging with flexible runtime delivery modes and robust development tools, the system maintains high performance for large-scale localized applications while providing a seamless developer experience.
Sources: README.md:52-65, AGENTS.md:50-65