Skip to content

fix(i18n): resolve raw studio.* keys when host app uses @nuxtjs/i18n - #501

Open
Codermar wants to merge 6 commits into
nuxt-content:mainfrom
Codermar:fix/i18n-locale-with-host-nuxtjs-i18n
Open

fix(i18n): resolve raw studio.* keys when host app uses @nuxtjs/i18n#501
Codermar wants to merge 6 commits into
nuxt-content:mainfrom
Codermar:fix/i18n-locale-with-host-nuxtjs-i18n

Conversation

@Codermar

@Codermar Codermar commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #104

Summary

When a host Nuxt app uses @nuxtjs/i18n, Studio could show raw translation keys (e.g. studio.nav.content, studio.nav.media) instead of localized labels. This PR fixes locale loading so Studio UI strings resolve correctly in that setup.

Problem

Studio initializes locale from useStudio inside a shared composable scope — not from a Vue component. setLocale() previously relied on getCurrentInstance() to reach i18n.global, so it often ran with no component context. Locale JSON chunks were never loaded, and vue-i18n fell back to displaying keys.

This shows up in real apps that combine Nuxt Content, Studio, and @nuxtjs/i18n (e.g. multilingual CMS sites).

Solution

  • Register Studio's i18n.global at app setup time (main.tsconfigureApp)
  • Read it from a small module-level store (studioI18n.ts) in useUI.setLocale()
  • Eager-load en on startup; lazy-load other locales only when needed
  • Skip the dynamic import when the locale is already registered

Changes

Area What
Core fix studioI18n.ts, main.ts, useUI.ts
Tests Unit tests for setLocale inside effectScope (eager + lazy locales)
Playground playground/minimal-i18n — host app with @nuxtjs/i18n for manual validation

Test plan

Automated

  • pnpm verify (unit tests include studioI18n.test.ts)

Manual

  1. Terminal 1: pnpm dev:app (Studio app on :5151)
  2. Terminal 2: pnpm dev:minimal-i18n (playground on :3000)
  3. Open http://localhost:3000 and toggle Studio (⌘.)
  4. Confirm nav labels show Content / Media (not studio.nav.* keys)
  5. Switch host locale to French (/fr) and reopen Studio — labels should show Contenu / Média

Notes

  • playground/minimal is unchanged; minimal-i18n is an optional sibling playground, not a change to the default dev setup.
  • No change to how host @nuxtjs/i18n is configured — only Studio's internal locale loading.

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
content-studio Ready Ready Preview, Comment Jun 22, 2026 9:42am
nuxt.studio Ready Ready Preview Jun 22, 2026 9:42am

@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/nuxt-studio@501

commit: a132754

@hendrikheil

Copy link
Copy Markdown
Collaborator

Thanks for your pull request, @Codermar !
I see you are actually fixing two independent things here. Could you split them into two separate PRs? One for the i18n fix and one for the size prop fix?

Codermar added 5 commits June 22, 2026 15:29
useUI.setLocale relied on getCurrentInstance(), which is null when
useStudio initializes inside a shared composable effectScope. Capture
Studio i18n.global in configureApp and eager-load en messages so locale
chunks load before the first paint.

Fixes nuxt-content#104
Assert useUI.setLocale resolves Studio labels when called from an
effectScope, including lazy-loaded locale chunks.
Keep playground/minimal as the baseline Content + Studio setup and add
a sibling fixture that mirrors nuxt-content#104.
Split content into locale folders with per-locale collections so Studio
smoke tests show a multi-language tree for nuxt-content#104.
Query the correct content path per locale (/fr for French).
Runs dev:prepare + prepack so pnpm can install nuxt-studio from GitHub
(tarball has no dist/; needed for monorepo deploy pins).
@Codermar
Codermar force-pushed the fix/i18n-locale-with-host-nuxtjs-i18n branch from 5dfea6c to ec69cf9 Compare June 22, 2026 22:30
@Codermar

Copy link
Copy Markdown
Contributor Author

Thanks for your pull request, @Codermar ! I see you are actually fixing two independent things here. Could you split them into two separate PRs? One for the i18n fix and one for the size prop fix?

Done — split into two PRs as suggested. This PR now contains only the i18n locale loading fix (#104). The UIcon size prop fix is in a separate PR: fix(ui): use class sizing on UIcon instead of invalid size prop
.

Regenerate pnpm-lock.yaml after merging main's @nuxt/ui and docus upgrades
with the minimal-i18n playground workspace.
@Codermar

Codermar commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@hendrikheil i noticed this PR is still open after a while as well as others in this repo. This is a package that interests me and I wonder if I can help some more review the prs or some other tasks that can facilitate the package to move forward. Also, I'd be interested to know if there's roadmap for it or if the continued maintenance is in the plans.
Thanks for the hard work!

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.

bug(i18n): locale keys aren't loaded properly

2 participants