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

locales fetched from url in defineI18nLocale not working after nuxi generate #2156

Closed
fcieminski opened this issue Jun 13, 2023 · 2 comments · Fixed by #2199
Closed

locales fetched from url in defineI18nLocale not working after nuxi generate #2156

fcieminski opened this issue Jun 13, 2023 · 2 comments · Fixed by #2199
Labels
locale ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf spa v8

Comments

@fcieminski
Copy link

fcieminski commented Jun 13, 2023

Environment

Nuxi 3.5.3
Nuxt project info: 20:20:10


Reproduction

Because it's happens only on generated app, there's no reproduction. But I'll precisly describe the bug.

Describe the bug

While playing with the development environment, all the locales fetched by defineI18nLocale work fine. I can change my locale through switchLocalePath in my language menu, and the changes are propagated instantly. However, the problem arises with the generated build for static production when ssr: false is used. The default language of my page is not respected, and none of the options inside the language selector menu work. Manually adding a prefix to the URL also does not work. The app remains in English.

Here's my nuxt config:

i18n: {
    experimental: {
      jsTsFormatResource: true
    },
    defaultLocale: 'pl',
    locales: [
      {
        code: 'en',
        name: 'english',
        file: 'locale.ts'
      },
      {
        code: 'pl',
        name: 'polish',
        file: 'locale.ts'
      },
      {
        code: 'ua',
        name: 'український',
        file: 'locale.ts'
      },
    ],
    langDir: 'locales',
    precompile: {
      strictMessage: false
    }
  },

Here's how my defineI18nLocale looks like:

import { MAPPED_LOCALES } from '@/enums'
import { Locale, StrapiResponse } from '@/types'

export default defineI18nLocale(async (locale: keyof typeof MAPPED_LOCALES) => {
  const currentLocale = MAPPED_LOCALES[locale]

  const { data } = await $fetch<StrapiResponse<Locale>>(`URL?locale=${currentLocale}`, {
    headers: {
      Authorization: 'AUTH'
    }
  })

  return data.attributes.content
})

To sum up, everythings work great on dev, but not after nuxi generate/nuxi preview, it's like locales are not fetched during generate proces.

Additional context

No response

Logs

No response

Copy link
Collaborator

kazupon commented Jun 14, 2023

Thank you for your reporting!

I appreciate your issue reporting info.
But, We need minimal reproduction with stackbliz or GitHub repo, to resolve your issue.
Could you give us it please?

@fcieminski
Copy link
Author

fcieminski commented Jun 14, 2023

@kazupon here's stackblitz example - https://stackblitz.com/edit/github-2c5yt2-3hxgw4?file=nuxt.config.ts but remember, you have to generate and preview the project to see the issue.

@kazupon kazupon added ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf and removed need reproduction 💻 labels Jun 15, 2023 — with Volta.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
locale ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf spa v8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants