如何根据访问者语言设置网页语言
有人可以告诉我如何根据访问者的 IP 地址设置网页语言,以便他自动获取其所在国家/地区语言的页面。当然,如果该语言是由网络开发人员实现的。更好的是,我播下了一些文本自动谷歌翻译的例子。
那么如何实现来自美国的访问者在我的页面上获得英语文本,以及来自法国的访问者获得法语文本。所有这些都是由谷歌从某种第三种原始语言翻译而来的。
多谢。
Can someone tell me how to set language of a web page on the knowledge of IP address of visitor so that he automatically gets page in his country's language. Of course if that language is implemented by web developer. Even better I sow some examples of automatic Google translation of the text.
So how to achieve that visitor from USA gets text on my page in English and visitor from France in French. All that translated by Google from some third original language.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当谈到自动语言选择时,如果您使用 Apache,我会选择 mod_rewrite 路线。在生产环境中更改触摸应用程序代码更容易。 mod_rewrite 从标头中获取“Accept-Language”,然后应用重写规则。
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
您可以堆叠重写条件和规则以捕获所有语言变体(fr、fr-ca、 fr-fr、fr-mo、fr-ch 都转到 fr)
查看官方 mod-rewrite 文档
良好的语言示例:
http://tech-blog.borychowski.com/index.php/2009/03/htaccess/redirect-according-to-browser-language-mod-rewrite-and-http_accept_language/
一旦你推送用户使用正确的通用语言(当 URL 中未定义任何语言时)应用程序可以设置会话语言,使用设置的语言编写链接。允许人们即时更改语言也很好,因为双语当地人(即魁北克省)的大多数用户都使用不止一种语言工作。我曾与讲法语的程序员一起工作过,他们更喜欢阅读英文技术文档。
当涉及到谷歌翻译文本时我会小心。如果您正在进行任何电子商务交易,您的国际客户(或具有国际浏览器设置的本地客户)可能会获得不正确或不准确的产品信息、描述以及“条款和条件”。如果您没有将每个即时翻译的准确 Google 翻译文本保存到您的数据库中,则无法跟踪用户对其语言所做的承诺。一些未翻译的合法副本可能是有序的。
我希望这有帮助。
When it come to automatic language selection I'd go the mod_rewrite route if you're using Apache. It's easier to change in a production environment that touching application code. mod_rewrite grabs the "Accept-Language" out of the header then applies the rewrite rule.
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
You can stack the rewrite conditions and rules to work as a catch all language variations (fr, fr-ca, fr-fr, fr-mo, fr-ch all go to fr)
Checkout the official mod-rewrite documentation
good language example:
http://tech-blog.borychowski.com/index.php/2009/03/htaccess/redirect-according-to-browser-language-mod-rewrite-and-http_accept_language/
Once you push the user to the right general language (when none is defined in the URL) the application can set a session language, write links with the set lang. It's also good to allow people to change language on the fly since most users in bilingual locals (i.e. Quebec) work in more than one language. I've worked with French speaking programmers who prefer reading technical documents in English.
When it comes to Google translating text I'd be careful. If you're doing any e-commerce transaction your international customers (or local customers with international browser settings) may get incorrect or inaccurate product information, descriptions and "terms and conditions". If you don't save the exact Google translation text to your DB for every on the fly translation there is no way to track what the user has committed to in their language. Some non-translated legal copy may be in order.
I hope this helps.
要么:
根据位置猜测语言(您可以从他们的 IP 获取)。
查看请求标头的“accept-language”值。
要查看请求标头中的内容,请查看此处: http://www .ericgiguere.com/tools/http-header-viewer.html
Either:
Guess language from location (which you can get from their IP).
Look at the request header's "accept-language" value.
To see what's in your request header, have a look here: http://www.ericgiguere.com/tools/http-header-viewer.html
从偏移量来看,这是一个坏主意。
This is a bad idea from the offset.