admin管理员组

文章数量:1417555

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"];
  }

本文标签: javascriptNextJs 13 (i18n) Incorrect locale information providedStack Overflow