Skip to content

Conversation

@BenjaminOddou
Copy link
Contributor

💬 Description

This PR introduces internationalization (i18n) support to the Nuxt Studio editor, allowing the UI to be translated.

It provides a mechanism for users to add their own translations or override the defaults.

💡 Implementation Details

This PR implements a solution by "injecting" the translations at runtime:

  1. Module (src/module/src/module.ts):

    • Gathers all translations using defu to merge defaults (src/app/locales), user-defined locales (app/locales/studio), app.config options and nuxt.config options.
    • Creates a Vite virtual module (virtual:studio-i18n-messages) to provide this merged JSON.
    • Adds a new Nuxt plugin (studio-i18n-plugin.client.mjs).
  2. Nuxt Plugin (studio-i18n-plugin.client.mjs):

    • This plugin can import from virtual:studio-i18n-messages because it runs within the Nuxt project's context.
    • It attaches the resolved messages to window.__NUXT_STUDIO_I18N_MESSAGES__.
  3. Studio App (src/app):

    • src/app/src/i18n.ts is refactored into a factory function (createStudioI18n) that accepts a messages object.
    • src/app/src/main.ts, during configureApp, now reads the messages from window.__NUXT_STUDIO_I18N_MESSAGES__ and passes them to createStudioI18n to dynamically create the i18n instance.

@vercel
Copy link

vercel bot commented Nov 6, 2025

@BenjaminOddou is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Nov 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
content-studio Ready Ready Preview Comment Nov 13, 2025 7:15pm

@BenjaminOddou BenjaminOddou marked this pull request as ready for review November 7, 2025 08:36
@BenjaminOddou
Copy link
Contributor Author

in playground/docus/nuxt.config.ts you can add

export default defineNuxtConfig({
  studio: {
    i18n: {
      defaultLocale: 'fr',
    },
  },
})

the result

image

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 7, 2025

npm i https://pkg.pr.new/nuxt-content/studio/nuxt-studio@70

commit: 143f720

@larbish
Copy link
Contributor

larbish commented Nov 12, 2025

Hello @BenjaminOddou, thanks a lot for your PR 🙏 I'm finishing a massive refactor (#91) and I'll then resolve conflicts with your branch to merge it!

@BenjaminOddou
Copy link
Contributor Author

@larbish, great news ! Don't hesitate to ping me if there is anything I can do. 😄

larbish and others added 3 commits November 13, 2025 14:37
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@larbish
Copy link
Contributor

larbish commented Nov 13, 2025

Here is what I've updated:

  • Extract i18n logic into separate i18n.ts file for better code organization
  • Removed vite module, it's enough to use addTemplate directly since it's loaded by a plugin
  • Relocate locale files to module/src/locales/ to ensures locale files are bundled with the module at build time (imports from app/src/locales/ wouldn't work in production)
  • Replaced globby with node native
  • Fixed defaultLocale handling it was not override

@farnabaz @atinux Can you see another way instead of window for cross boundary communication between module and app? I'm not a fan of it

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@atinux
Copy link
Contributor

atinux commented Nov 13, 2025

I like using window as shared objects between the website & web elements

Copy link
Contributor

@atinux atinux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Au top :)

@farnabaz
Copy link
Contributor

Generally looks good to me 👍 Great work

Using window to share data between web-component and host is quite alright IMO. However I'm not fan of having translations inside module and passing them to Vue app.

UI and Translations are App's responsibility.

@larbish
Copy link
Contributor

larbish commented Nov 14, 2025

We've decided with @farnabaz to remove the translations override and simplify the PR:

  • no need of plugin (using runtime config and host to share default locale)
  • move locales in app and fetch it at runtime (set locale and load messages at runtime)

@farnabaz Feel free to merge once you've checked option types with build version

@larbish larbish merged commit 5d2099c into nuxt-content:main Nov 14, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants