i18n icon indicating copy to clipboard operation
i18n copied to clipboard

When override locales from Layer, I get an error: When using the langDir option the locales must be a list of objects. How to override Layer configuration from project layer?

Open lna1989 opened this issue 1 year ago • 3 comments

Environment


  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.10.2
  • CLI Version: 3.10.1
  • Nitro Version: 2.8.1
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools, extends, modules, i18n
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

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

Describe the bug

I need to remove unnecessary languages that are present in the Layer. To override, Nuxt tells us to use the arrow function. But I get an error: When using the langDir option the locales must be a list of objects if switch:

locales: [
      {
        code: 'en',
        iso: 'en-US',
        name: 'English',
        file: 'en_US.json',
      },
    ],

to

locales: () => {
    return [
      {
        code: 'en',
        iso: 'en-US',
        name: 'English',
        file: 'en_US.json',
      },
    ];
  },

Additional context

No response

Logs

[6:05:55 PM]  ERROR  Cannot start nuxt:  [@nuxtjs/i18n]: In project layer (/home/projects/nuxt-starter-7ixgvf/nuxt.config) - When using the langDir option the locales must be a list of objects.

  at checkLayerOptions (node_modules/@nuxtjs/i18n/dist/module.mjs:681:13)
  at setup (node_modules/@nuxtjs/i18n/dist/module.mjs:1771:5)
  at normalizedModule (node_modules/@nuxtjs/i18n/node_modules/@nuxt/kit/dist/index.mjs:2212:37)
  at async Module.installModule (node_modules/@nuxt/kit/dist/index.mjs:2499:95)
  at async initNuxt (node_modules/nuxt/dist/index.mjs:4040:7)
  at async NuxtDevServer._load (node_modules/nuxi/dist/chunks/dev2.mjs:267:5)
  at async NuxtDevServer.load (node_modules/nuxi/dist/chunks/dev2.mjs:199:7)
  at async NuxtDevServer.init (node_modules/nuxi/dist/chunks/dev2.mjs:194:5)
  at async Object.run (node_modules/nuxi/dist/chunks/dev-child.mjs:115:5)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.a9f3bca7.mjs:1678:16)

lna1989 avatar Jun 14 '24 14:06 lna1989

@BobbieGoede Can you give some advice for layers if you have any ideas? 🙏

kazupon avatar Jun 24 '24 02:06 kazupon

Hmm I can only find docs about overwriting with a function for app.config.ts here, I'll look into figuring out a way to allow overwriting locales with a function.

BobbieGoede avatar Jun 24 '24 07:06 BobbieGoede

@kazupon @BobbieGoede Oh, I'm sorry, it looks like I really messed up the rewrite functionality in app.config.ts. But in any case, we must have some method not of extending, but of overwriting the configuration described in nuxt.config.ts for i18n.

Under the hood, the functionality uses https://github.com/unjs/c12 And the same approach is used there through specifying the mergeStrategy function, as far as I understand, just like in app.config.ts - https://github.com/unjs/c12/issues/145

lna1989 avatar Jun 24 '24 11:06 lna1989

Closing as this issue is essentially the same as this feature request issue https://github.com/nuxt-modules/i18n/issues/3047

BobbieGoede avatar Oct 30 '25 16:10 BobbieGoede