nuxt-modules / i18n

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

@nuxtjs/i18n not picking up vueI18n config when installed via Nuxt Kits `installModule` #2809

Closed riddla closed 7 months ago

riddla commented 9 months ago

Environment

Reproduction

https://stackblitz.com/edit/bobbiegoede-nuxt-i18n-starter-y1vnuv

Describe the bug

We are trying to install @nuxtjs/i18n from a custom module via Nuxt Kits installModule method. So far @nuxtjs/i18n is not picking up the config file configured via the vueI18n option. You can see the empty VueI18nConfigPaths array in the reproduction.

Additional context

No response

Logs

@nuxtjs/i18n:module options {
  experimental: { localeDetector: '' },
  bundle: {
    compositionOnly: true,
    runtimeOnly: false,
    fullInstall: true,
    dropMessageCompiler: false
  },
  compilation: { jit: true, strictMessage: true, escapeHtml: false },
  customBlocks: { defaultSFCLang: 'json', globalSFCScope: false },
  vueI18n: '/home/projects/bobbiegoede-nuxt-i18n-starter-y1vnuv/modules/example/config/i18n/options.ts',
  locales: [],
  defaultLocale: '',
  defaultDirection: 'ltr',
  routesNameSeparator: '___',
  trailingSlash: false,
  defaultLocaleRouteNameSuffix: 'default',
  strategy: 'prefix_except_default',
  lazy: false,
  langDir: 'locales/',
  rootRedirect: null,
  detectBrowserLanguage: false,
  differentDomains: false,
  baseUrl: '',
  dynamicRouteParams: false,
  customRoutes: 'page',
  pages: {},
  skipSettingLocaleOnNavigate: false,
  types: 'composition',
  debug: true,
  parallelPlugin: false
} +0ms
[nuxt] i18n:registerModule: 0.02ms                                                                                                          07:35:34
  @nuxtjs/i18n:module localeInfo [] +1ms
  @nuxtjs/i18n:module VueI18nConfigPaths [] +40ms
  @nuxtjs/i18n:module vueI18nPath for auto-import /home/projects/bobbiegoede-nuxt-i18n-starter-y1vnuv/node_modules/vue-i18n/dist/vue-i18n.mjs
BobbieGoede commented 9 months ago

Honestly the behaviour of installModule is a bit confusing to me, from what I can tell it's not possible to support multiple modules using installModule to install @nuxtjs/i18n.

I will look into supporting it while keeping layers working at the same time, until then I recommend using a layer instead as a workaround.

This issue is similar/related to #2802

urielb commented 8 months ago

Hi, I just noticed I'm also running into this issue, and was trying to make a workaround, but without much success.

Could you expand a bit on the layers temporary solution you've mentioned please?

Chees!

szulcus commented 8 months ago

I have the same problem :/. Module is installed but without any config. Other modules config works fine to me.

await installModule('@nuxtjs/i18n', {
    trailingSlash: true,
    strategy: 'prefix',
    locales: [
        { code: 'en-gb', iso: 'en-GB', apiCode: 'en', dayjsCode: 'en-gb', name: 'English (United Kingdom)' },
        { code: 'en-us', iso: 'en-US', apiCode: 'en', dayjsCode: 'en', name: 'English (United States)' },
        { code: 'en-ca', iso: 'en-CA', apiCode: 'en', dayjsCode: 'en-ca', name: 'English (Canada)' },
        { code: 'nl', iso: 'nl', apiCode: 'nl', dayjsCode: 'nl', name: 'Nederlands' },
    ],
    defaultLocale: 'en-gb',
    detectBrowserLanguage: {
        useCookie: true,
        redirectOn: 'root',
    },
    vueI18n: './config/vue-i18n.ts',
});

For example useI18n().localeProperties is only { code: 'en-gb' } instead of { code: 'en-gb', iso: 'en-GB', apiCode: 'en', dayjsCode: 'en-gb', name: 'English (United Kingdom)' }. Only config in nuxt.config.ts make module works correctly.

szulcus commented 7 months ago

Issue is closed, but for me problem still exist :/

BobbieGoede commented 7 months ago

@szulcus Can you provide a reproduction using the latest release?