nuxt-modules / i18n

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

Playground mergeLayerLocales is broken #2802

Open Eugene313 opened 9 months ago

Eugene313 commented 9 months ago

Environment

Environment

Reproduction

https://codesandbox.io/p/devbox/nuxtjs-i18n-8-1-1-mergelayerlocales-is-broken-9jmwtm?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clsonr6je0007356n1ja7217e%2522%252C%2522sizes%2522%253A%255B58.84422110552764%252C41.15577889447236%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clsonr6je0002356nonq53eeu%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clsonr6je0004356n8iab1507%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clsonr6je0006356npbsy3ex4%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B44.54374772496504%252C55.45625227503496%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clsonr6je0002356nonq53eeu%2522%253A%257B%2522id%2522%253A%2522clsonr6je0002356nonq53eeu%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clsonr6je0006356npbsy3ex4%2522%253A%257B%2522id%2522%253A%2522clsonr6je0006356npbsy3ex4%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clsonr6je0004356n8iab1507%2522%253A%257B%2522id%2522%253A%2522clsonr6je0004356n8iab1507%2522%252C%2522tabs%2522%253A%255B%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Describe the bug

After update from 8.0.0-beta.12 you have changed mergeLayerLocales function and now my local config in Nuxt module cant be merged after start playground

in mergeLayerLocales function you have Code to filter layer

const configs = nuxt.options._layers.filter

but at the time of assembly i dont have layer from my Nuxt module option

so after filter _layers the mergeConfigLocales function merge undefined

so you need edit last function like this

const mergeLayerLocales = (options, nuxt) => {
  debug$9("project layer `lazy` option", options.lazy);
  const projectLangDir = getProjectPath(nuxt, nuxt.options.srcDir);
  options.locales ??= [];
  const configs = nuxt.options._layers.filter((layer) => {
    const i18n = getLayerI18n(layer);
    return i18n?.locales != null;
  }).map((layer) => {
    const i18n = getLayerI18n(layer);
    return {
      ...i18n,
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
      langDir: resolve(layer.config.srcDir, i18n?.langDir ?? layer.config.srcDir),
      projectLangDir
    };
  });
  return mergeConfigLocales([options, ...configs]);
};

Additional context

No response

Logs

No response