javascript - NextJs 13 (i18n) Incorrect locale information provided - Stack Overflow

I have been trying to use the NextJs i18nrouting on a website Archive, but when I followed the exact

I have been trying to use the NextJs i18n routing on a website Archive, but when I followed the exact steps provided in the documentation, I got this error: Incorrect locale information provided

I tried to debug it by checking the headers of the requests but it's all correct.

I tried to solve this by checking the error on console, reading related questions on stackoverflow Archive and GitHub Archive but without success.

I have been trying to use the NextJs i18n routing on a website Archive, but when I followed the exact steps provided in the documentation, I got this error: Incorrect locale information provided

I tried to debug it by checking the headers of the requests but it's all correct.

I tried to solve this by checking the error on console, reading related questions on stackoverflow Archive and GitHub Archive but without success.

Share Improve this question edited Jun 10, 2023 at 19:03 a0m0rajab asked Jun 10, 2023 at 18:56 a0m0rajaba0m0rajab 4954 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

The issue is happening due to getting the language array as: [ "*" ] Which is not defined in the language that we have, I added an if condition to solve this issue:

    if (languages.length === 1 && languages[0] === '*') {
        languages = ['ar']
    }

Then followed the same steps in the documentation and it worked well.

I tried this on my middleware.ts and the issue is solved now:

const locales: string[] = i18n.locales;
  let languages = new Negotiator({ headers: negotiatorHeaders }).languages();
  if (languages.length === 1 && languages[0] === "*") {
    languages = ["en"];
  }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745273270a4619881.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信