【问题标题】:Detect user language who visit my website (React, i18next)检测访问我网站的用户语言 (React, i18next)
【发布时间】:2018-06-24 07:34:45
【问题描述】:

我正在使用 React、i18nexti18next-browser-languagedetector 开发一个多语言应用程序。

i18next-browser-languagedetector 检测浏览器中的用户语言,支持:cookie、localStorage、navigator、querystring、htmlTag

我应该使用另一个模块验证来自 HTTP 请求标头的 Accept-Language 吗?

【问题讨论】:

标签: javascript reactjs internationalization i18next


【解决方案1】:

请求标头在服务器端进行评估,因此不是浏览器语言检测的一部分 -> 服务器端中间件,例如。 express 自带检测器:

https://github.com/i18next/i18next-express-middleware#language-detection

react-i18next 的服务器端渲染示例也使用:https://github.com/i18next/react-i18next/blob/master/example/nextjs/server.js#L16

【讨论】:

  • 感谢您提供详细信息 =)
  • 第二个链接现在无效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 2021-03-22
  • 2015-01-19
  • 2021-06-22
相关资源
最近更新 更多