Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server-side translations don't work with yaml files #2606

Closed
tmlmt opened this issue Dec 8, 2023 · 3 comments · Fixed by #2613
Closed

Server-side translations don't work with yaml files #2606

tmlmt opened this issue Dec 8, 2023 · 3 comments · Fixed by #2613
Assignees
Labels
nitro 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage server-side v8

Comments

@tmlmt
Copy link

tmlmt commented Dec 8, 2023

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.8.0
  • CLI Version: 3.9.1
  • Nitro Version: 2.7.2
  • Package Manager: npm@9.4.2
  • Builder: -
  • User Config: modules, i18n
  • Runtime Modules: @nuxtjs/i18n@8.0.0-rc.8
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/bobbiegoede-nuxt-i18n-starter-jxx5u7?file=nuxt.config.ts

Describe the bug

When setting up server-side translation as per the docs, and using .yaml files as locale files, the app crashes.

Additional context

nuxt.config.ts:

export default defineNuxtConfig({
  modules: ['@nuxtjs/i18n'],
  i18n: {
    lazy: true,
    langDir: 'locales',
    defaultLocale: 'en',
    locales: [
      {
        name: 'English',
        code: 'en',
        iso: 'en-US',
        file: 'en.yaml',
      },
      {
        name: 'Nederlands',
        code: 'nl',
        iso: 'nl-NL',
        file: 'nl.yaml',
      },
      {
        name: '日本語',
        code: 'ja',
        iso: 'ja-JA',
        file: 'ja.yaml',
      },
    ],
    strategy: 'prefix',
    detectBrowserLanguage: false,
    experimental: {
      localeDetector: './localeDetector.ts',
    },
  },
});

Content of locales/en.yaml:

hello: Hello

I suspect that an improper parser is being used: the above file is a valid yaml file and works well with client-side translations. And when adding quotes around the strings in the yaml files (i.e. Hello -> "Hello"), the app loads (... but there is another bug ...)

Logs

[nitro] [uncaughtException] Error: Hello is not defined
    at file:///home/projects/bobbiegoede-nuxt-i18n-starter-jxx5u7/.nuxt/dev/index.mjs
    at _0xd48bdb._evaluate (https://bobbiegoedenuxti18nstarterjxx5-54b2.w-credentialless.staticblitz.com/blitz.d3416dfd.js:352:373544)
    at async ModuleJob.run (https://bobbiegoedenuxti18nstarterjxx5-54b2.w-credentialless.staticblitz.com/blitz.d3416dfd.js:181:2372)
[nitro] [unhandledRejection] ReferenceError: Cannot access 'i18n_config$1' before initialization
    at eval (file:///home/projects/bobbiegoede-nuxt-i18n-starter-jxx5u7/.nuxt/dev/index.mjs:870:46)
    at async loadVueI18nOptions (file:///home/projects/bobbiegoede-nuxt-i18n-starter-jxx5u7/.nuxt/dev/index.mjs:964:35)
    at async nitroPlugin (file:///home/projects/bobbiegoede-nuxt-i18n-starter-jxx5u7/.nuxt/dev/index.mjs:1053:19)
[nuxt] [request error] [unhandled] [500] Cannot access 'renderer$1' before initialization
  at eval (./.nuxt/dev/index.mjs:1180:65)  
  at async Object.eval [as handler] (./node_modules/h3/dist/index.mjs:1749:19)  
  at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1959:7)
[nuxt] [request error] [unhandled] [500] Cannot access 'renderer$1' before initialization
  at eval (./.nuxt/dev/index.mjs:1180:65)  
  at async Object.eval [as handler] (./node_modules/h3/dist/index.mjs:1749:19)  
  at async toNodeHandle (./node_modules/h3/dist/index.mjs:1959:7)  
  at async ufetch (./node_modules/unenv/runtime/fetch/index.mjs:28:17)  
  at async errorhandler (./.nuxt/dev/index.mjs:1153:30)  
  at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1966:9)
[nuxt] [request error] [unhandled] [500] Cannot access 'renderer$1' before initialization
  at eval (./.nuxt/dev/index.mjs:1180:65)  
  at async Object.eval [as handler] (./node_modules/h3/dist/index.mjs:1749:19)  
  at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1959:7)
[nuxt] [request error] [unhandled] [500] Cannot access 'renderer$1' before initialization
  at eval (./.nuxt/dev/index.mjs:1180:65)  
  at async Object.eval [as handler] (./node_modules/h3/dist/index.mjs:1749:19)  
  at async toNodeHandle (./node_modules/h3/dist/index.mjs:1959:7)  
  at async ufetch (./node_modules/unenv/runtime/fetch/index.mjs:28:17)  
  at async errorhandler (./.nuxt/dev/index.mjs:1153:30)  
  at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1966:9)
@kazupon
Copy link
Collaborator

kazupon commented Dec 8, 2023

Thank you for your reporting!

Oh...
We need to add a plugin to transform yaml to nitro's rollup.

@kazupon
Copy link
Collaborator

kazupon commented Dec 8, 2023

nuxt i18n has already integrated @intlify/unpluign-vue-i18n, unfortunately it's only vite.

@kazupon kazupon added the 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage label Dec 8, 2023
@tmlmt
Copy link
Author

tmlmt commented Dec 8, 2023

Thank you for confirming the bug and the diagnostic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nitro 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage server-side v8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants