Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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? #2978

Open
lna1989 opened this issue Jun 14, 2024 · 3 comments
Assignees
Labels

Comments

@lna1989
Copy link

lna1989 commented Jun 14, 2024

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: npm@10.2.3
  • Builder: -
  • User Config: devtools, extends, modules, i18n
  • Runtime Modules: @nuxtjs/i18n@8.3.1
  • 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 lna1989 changed the title 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?tion on pro 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? Jun 14, 2024
@kazupon kazupon added the layers label Jun 24, 2024
@kazupon
Copy link
Collaborator

kazupon commented Jun 24, 2024

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

@kazupon kazupon added v8 and removed pending triage labels Jun 24, 2024
@BobbieGoede
Copy link
Collaborator

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 BobbieGoede self-assigned this Jun 24, 2024
@lna1989
Copy link
Author

lna1989 commented Jun 24, 2024

@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 - unjs/c12#145

@BobbieGoede BobbieGoede removed the v8 label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants