简体   繁体   English

根据访问者的语言进行重定向

[英]Made a redirection depending on the language of the visitor

I'm building a blog with Gatsby with support for 2 languages.我正在用 Gatsby 构建一个支持 2 种语言的博客。

Most of the concerns about the internationalization of the web are done, but I don't how I could redirect to the visitors based on their language.大多数关于 web 国际化的担忧已经解决,但我不知道如何根据访问者的语言重定向到他们。 For example, if a Spanish person visits the index of my pages, I would like to redirect them to /es/index route.例如,如果一个西班牙人访问我的页面索引,我想将它们重定向到/es/index路由。

You can use vanilla javascript to get the user language from the browser您可以使用 vanilla javascript 从浏览器获取用户语言

window.navigator.language

then redirect based on the language gotten.然后根据获得的语言重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM