xiCO2k / laravel-vue-i18n

Allows to connect your `Laravel` Framework translation files with `Vue`.
MIT License
598 stars 49 forks source link

Switching from other language to EN seems to break? #184

Closed tariksadiku-buckaroo closed 1 month ago

tariksadiku-buckaroo commented 1 month ago

I am currently running into an issue where I can switch back and forth between EN and NL just fine, however, when I reload the page, I set the locale depending on the users session (using Sessions instead of API tokens). If my current session of the chosen language is NL, it seems to work great, however when I try to switch to EN, the page breaks, no configs are loaded.

Here is my vite config (I am running my Vue project inside a Package in my Laravel project).

i18n({ langPath: 'src/lang', }),

Here is my config for i18n.

app.use(i18nVue, {
  lang: window?.selectedLanguage ?? 'en',
  fallback: 'en',
  resolve: async lang => {
    const langs = import.meta.glob('../../lang/*.json');
    return await langs[`../../lang/php_${lang}.json`]();
  },
});
xiCO2k commented 1 month ago

I believe you have the wrong resolve.

.use(i18nVue, {
      resolve: async lang => {
          const langs = import.meta.glob('../../lang/*.json');
          return await langs[`../../lang/${lang}.json`]();
      }
  })

and also I would suggest having the <html lang="nl"> instead of window?.selectedLanguage.