nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.75k stars 483 forks source link

Chosen locale is loading a different locale file that is set in object #2803

Closed nford88 closed 1 month ago

nford88 commented 9 months ago

Environment


Reproduction

https://stackblitz.com/edit/nuxt-starter-ymkpzl?file=nuxt.config.ts

Describe the bug

My site have multiple locales which are language and country specific. For this example, I create one main language file (de.json) which majority of translations, I then create one specific country file (de-CH.json). Both are inserted as locale objects below.

locales: [
      {
        code: 'de-CH',
        iso: 'de-CH',
        files: ['de.json', 'de-CH.json'],
      },
      {
        code: 'de-DE',
        iso: 'de-DE',
        file: 'de.json',
      },
    ]

However, the 'de-DE' locale is accessing the translations from 'de-CH.json' file when that locale should only being 'de.json' file.

There seems to be an issue with the spreading of the locale objects json files and both locales are receiving the same translations object when they should have their own be separate objects.

Additional context

No response

Logs

No response

nford88 commented 9 months ago

hey @BobbieGoede do you know if there is any room on the roadmap to examine this? I can try and find some time to help debug if that's any use.

It's a blocker for myself to move an application from Nuct 2 to Nuxt 3 as we are mid migration. If its going to be a while I might try and find an alternative temporary solution (manually building one json per country) so I can keep on working through. Many thanks!

BobbieGoede commented 8 months ago

@nford88 Sorry I didn't get around to fixing this yet, it seems something is going wrong with caching and I think the imported de.json file is being mutated.

I do have a workaround using dynamic locale files which is less performant but should unblock your migration while this issue exists. I have updated your reproduction to demonstrate the workaround here.

nford88 commented 8 months ago

I implemented your workaround now. I have about 150 translations in the main language files and approximately 20-30 in the locale country files. Not seeing too much of a performant dip. Will see how it goes. Thanks!

BobbieGoede commented 1 month ago

This will be resolved with #3137 since I've fixed the issue upstream! Here's an updated reproduction with using a preview release https://stackblitz.com/edit/nuxt-starter-mwtgfw?file=package.json.