Skip to content

Support i18n inline translations #3509

@JonathanXDR

Description

@JonathanXDR

Is your feature request related to a problem? Please describe

Currently, when using Nuxt Content together with Nuxt i18n, inline translations inside content files (Markdown, YAML, JSON, CSV) are not supported. This means developers need to create a separate file for each locale (e.g., content/{locale}/team/jane-doe.yml), which works in cases where every property requires a different translation, but otherwise becomes redundant and creates unnecessary overhead.

This lack of support prevents content authors from keeping multilingual content in a single file with inline i18n keys. Without a built-in solution, teams are forced to manually extend collection schemas and implement workarounds.

Describe the solution you'd like

I would like Nuxt Content to support inline i18n statements natively across all formats (Markdown, YAML, JSON, CSV).

  • Developers should be able to write translations directly inside the same file using an i18n section.
  • The module should automatically detect those i18n keys and adjust the collection schema to merge translated props into the result of queryCollection.
  • If a top-level property exists alongside translations, it should serve as a fallback value if the translation for the current locale is missing.
  • The solution should be compatible with server-side locale detection (as provided by Nuxt i18n’s defineI18nLocaleDetector) so that translations can be resolved fully on the server side per request. This would allow developers to return localized content directly from the server without requiring any client-side adjustments.

This way, developers can adopt a clean and consistent multilingual content standard with zero configuration or effort on their side, while retaining the option for full server-side translation flows if their project requires it.

Describe alternatives you've considered

  • Separate locale-based files: e.g., content/de/team/jane-doe.yml and content/en/team/jane-doe.yml.

    • Works but is tedious and breaks content maintainability, especially with large datasets.
  • Manual schema adjustments: Extend the collection schema to process inline i18n keys manually.

    • Adds complexity and requires developers to duplicate logic that could be handled automatically by the module.

Both approaches are less efficient and more error-prone compared to built-in inline i18n support.

Additional context

Example content file (jane-doe.yml):

name: Jane Doe
icon: { name: lucide:user }
info:
  age: 25
  # If this top-level prop is defined even tho there are translations, it will be used as fallback description if the translation is missing
  country: Switzerland

# Same fallback approach here as above since the top-level prop is defined
description: Jane likes to read and travel.

i18n:
  de:
    description: Jane mag es zu lesen und zu reisen.
    # The props here will be merged with the top-level props
    info:
      country: Schweiz
  en:
    description: Jane likes to read and travel.
    info:
      country: Switzerland
  it:
    description: Jane ama leggere e viaggiare.
    info:
      country: Svizzera
  fr:
    description: Jane aime lire et voyager.
    info:
      country: Suisse

Expected generated output when using queryCollection (current locale = en):

[
  {
    "id": "team/team/jane-doe.yml",
    "title": "Jane Doe",
    "description": "Jane likes to read and travel.",
    "extension": "yml",
    "icon": {
      "name": "lucide:user"
    },
    "info": {
      "age": 25,
      "country": "Switzerland"
    },
    "meta": {
      "path": "/team/jane-doe",
      "body": {
        "name": "Jane Doe",
        "icon": {
          "name": "lucide:user"
        },
        "info": {
          "age": 25,
          "country": "Switzerland"
        },
        "description": "Jane likes to read and travel."
      }
    },
    "name": "Jane Doe",
    "stem": "team/jane-doe",
    "__hash__": "MoyLlRB-472Xv4vA9p5BpRd1VP-wL8u0N62lnKwhQ4Q"
  }
]

👉 This feature would make multilingual content authoring in Nuxt Content much more intuitive and would standardize inline i18n usage without requiring custom schemas or multiple file structures. With server-side locale detection and translation, developers could even serve localized content directly from the server on a per-request basis, aligning seamlessly with Nuxt i18n’s experimental server-side translation support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions