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 badges2 Answers
Reset to default 4The 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
版权声明:本文标题:javascript - NextJs 13 (i18n) Incorrect locale information provided - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745273269a2651026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论