Translation Payloads
Relevant source files
The following files were used as context for generating this wiki page:
Translation Payloads deliver localized data to the browser and server as discrete JSON files. This system prevents large translation catalogs from bloating the main application bundle. The module manages the generation, routing, and fetching of these payloads based on the current page and locale.
Payload Architecture
The translation payload system operates by splitting translations into logical units. The module resolves configuration at build time to determine how to serve these units.
Workflow Overview
- Resolution: The module identifies which payload mode to use (
premergedorsource). - Generation: Nitro hooks handle the compilation and placement of JSON files in the output directory.
- Routing: Specific API endpoints are registered to serve the files.
- Retrieval: The client or server fetches the necessary payload based on the route and locale.
Sources: [src/module.ts:503-520](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/src/module.ts#L503-L520), [packages/utils/src/payload-config.ts:31-35](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L31-L35)
Configuration and Modes
Translation payloads support two primary operational modes defined in the translationPayloads configuration object.
Mode Descriptions
- premerged: The module merges all translation layers and page-specific keys into a single matrix per locale/page. This is the default mode.
- source: The module provides raw source files. This mode is recommended for extremely large catalogs to reduce the number of generated files in public output.
Sources: [packages/utils/src/payload-config.ts:3-16](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L3-L16), [packages/utils/src/payload-config.ts:37-48](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L37-L48)
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
mode | premerged | source | premerged | Determines the format of output files. |
serverAssets | boolean | true | Embeds payloads in the Nitro server bundle. |
serverHandler | boolean | true | Registers the /_locales/... API handler. |
publicAssets | boolean | true (premerged) | Copies payloads to the public directory. |
prerenderRoutes | boolean | false | Adds payload paths to the Nitro prerenderer. |
Sources: [packages/utils/src/payload-config.ts:7-16](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L7-L16), [packages/utils/src/payload-config.ts:37-48](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L37-L48), [src/module.ts:403-413](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/src/module.ts#L403-L413)
URL and Path Resolution
Payloads are accessed via a structured URL pattern. The default base path is /_locales, but you can customize this via the apiBaseUrl option.
Path Construction
The standard path for a payload follows this structure:
/{apiBaseUrl}/{page}/{locale}/data.json
If a route name is missing, the system defaults to index. The module also resolves route aliases defined in routesLocaleLinks before constructing the path.
Sources: [packages/utils/src/payload-url.ts:16-19](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-url.ts#L16-L19), [packages/utils/src/payload-url.ts:25-27](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-url.ts#L25-L27)
Cache Management
The system uses build-time hashing or timestamps to manage browser caching.
- Cache Buster: A version parameter
?v={timestamp}is appended to fetch requests. - Cache-Control: If a cache buster exists, the server sends
public, max-age={duration}, immutable. Otherwise, it sendspublic, max-age=0, must-revalidate.
Sources: [packages/utils/src/payload-url.ts:76-85](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-url.ts#L76-L85), [src/module.ts:182-192](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/src/module.ts#L182-L192)
Data Fetching Logic
The fetchTranslationPayloadFromHost function handles the retrieval of translations. It supports fetching from local paths or external hosts.
Fetch Process Sequence
Sources: [packages/utils/src/payload-fetch.ts:12-19](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-fetch.ts#L12-L19), [packages/utils/src/payload-url.ts:48-73](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-url.ts#L48-L73)
Deployment Considerations
The module adapts its behavior based on the Nitro deployment preset.
Server Assets vs Public Directory
- Node/Static Presets: Nitro serves
public/from disk. The module copies payloads to the public directory to allow direct file access. - Cloud Functions/Edge: Presets like Vercel or Netlify deploy
public/to a CDN. In these cases, the module embeds payloads into the server bundle asserverAssetsto ensure they are available during SSR.
Sources: [packages/utils/src/payload-config.ts:63-70](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L63-L70), [packages/utils/src/payload-config.ts:77-83](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L77-L83), [src/module.ts:717-735](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/src/module.ts#L717-L735)
Performance Monitoring
The module includes a monitoring utility to prevent accidental deployment of excessively large translation sets.
Thresholds and Warnings
The module triggers a warning during the build if the payload stats exceed the following default thresholds:
- File Count: 500 files
- Total Size: 10 MB
Sources: [packages/utils/src/payload-config.ts:28-29](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L28-L29), [packages/utils/src/payload-stats.ts:19-22](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-stats.ts#L19-L22), [packages/utils/src/payload-config.ts:114-121](https://github.com/s00d/nuxt-i18n-micro/blob/0664dea2bb97ce56ab149acfa16b5f45a48b0247/packages/utils/src/payload-config.ts#L114-L121)
Conclusion
Translation Payloads enable scalable internationalization by decoupling translation data from the application logic. Through configurable modes and deployment-aware asset management, the system ensures optimal performance across various hosting environments while maintaining strict cache control and resource monitoring.