UA自动选择合适的语言 [英] UA automatically choosing appropriate language

查看:166
本文介绍了UA自动选择合适的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想开发一个应该有几种语言的网站,比如英语,法语和德语。我的问题是:我怎么能建议访问者的浏览器根据他们的偏好显示正确的语言?




让我更清楚地解释一下:在许多浏览器中,你有可能选择你喜欢的语言:fr,en,de等。

通常,在Mozilla中,此选项详述如下:

网页有时以多种语言提供。选择

语言显示网页,按优先顺序排列。


这很酷,但它是如何工作的?我的意思是,网站地址是

,对于所有用户来说,他们在他们的

浏览器中选择英语或法语,所以他们总是指向相同的HTML

网站上的默认页面:这个页面显然用一种语言写成,说英语,所以

即使这个人的首选语言是德语,所有他都是将获得

将是英文...


然后这个主页可以为访问者提供德语版的

点击某个链接的网站,但随后我正在谈论的选项

关于没有意义,对吗?


有没有我想念的东西(我猜所以,但我不知道是什么)?我很高兴你的帮助...


Vincent。


I would like to develop a site that should be available in several
languages, say English, French and German. My question is: how can I
suggest browsers of visitors to display the correct language depending
on their preferences ?

Let me explain this more clearly: in many browsers, you are given the
possibility to choose your preferred language: fr, en, de, etc.
Typically, in Mozilla, this option is detailed as follows:
"Web pages are sometimes available in more than one language. Choose
languages for displaying web pages, in order of preference".

This is cool, but how does it work ? I mean, the web site address is the
same for all users wether they selected english or french in their
browser, so they''ll always point to the same HTML default page on the
site: this page is obviously written in ONE language, say english, so
that even if the guy''s preferred language is german, all he will get
will be english...

Then this main page could offer the visitor to go to a german version of
the site by clicking on some link, but then the option I was talking
about is pointless, right ?

Is there something I missed (I guess so, but I don''t know what) ? I
would appreciate your help...

Vincent.

推荐答案

Vincent< vi ************ @ wanadoo.fr>在< bg ********** @ news-reader3.wanadoo.fr>中大声说:
Vincent <vi************@wanadoo.fr> exclaimed in <bg**********@news-reader3.wanadoo.fr>:
我想开发一个应该有几个网站的网站
语言,比如英语,法语和德语。我的问题是:我如何建议访问者的浏览器根据他们的偏好显示正确的语言?
I would like to develop a site that should be available in several
languages, say English, French and German. My question is: how can I
suggest browsers of visitors to display the correct language depending
on their preferences ?




你指的是什么这里被称为内容协商。非常好

简单地说,它的工作原理如下:


(a)用户选择她喜欢的UA语言,说英语。


(b)当UA联系网络服务器时,它会沿着HTTP标头发送

,称为Accept-Language,它向服务器解释说哪种语言

或者她更喜欢的语言。


(c)服务器然后使用一种方法或其他方法选择要发回的资源




有几种方法可以在服务器上实现这一点;可能最简单的是调查你的服务器是否有内置的内容。对于Apache,请参阅

< a rel =nofollowhref =http://httpd.apache.org/docs/content-negotiation.htmltarget =_ blank> http://httpd.apache.org/docs/content-negotiation.html


这被认为是一个非常好的解决方案,虽然我从来没有用过它自己的b $ b。阅读

HTTP规范中的第12节也是值得的。

nofollowhref =http://www.w3.org /Protocols/rfc2616/rfc2616-sec12.html#sec12\"target =_ blank> http://www.w3.org/Protocols/rfc2616/...c12.html#sec12
<祝你好运。祝你好运。


-

- Tina Holmboe Greytower Technologies
ti ** @ greytower.net http:// www .greytower.net /

[+46] 0708 557 905



What you are referring to here is known as "content negotiation". Very
simply put, it works as follows:

(a) The user chooses which language she prefers in her UA, say English.

(b) When the UA contact the webserver it sends along a HTTP header
called Accept-Language which explains to the server which language
or languages she would prefer.

(c) The server then choose, using one method or other, which resource
to send back.

There are several ways of implementing this on the server; it''s quite
likely that the easiest is to look into whether your server has something
built in. For Apache, see

http://httpd.apache.org/docs/content-negotiation.html

which is said to be a very nice solution, though I have never used it
myself. It would also be worth your while to read section 12 in the
HTTP specification

http://www.w3.org/Protocols/rfc2616/...c12.html#sec12

Good luck.

--
- Tina Holmboe Greytower Technologies
ti**@greytower.net http://www.greytower.net/
[+46] 0708 557 905


文章< bg ****** ****@news-reader3.wanadoo.fr>,
vi ***** *******@wanadoo.fr 说...
In article <bg**********@news-reader3.wanadoo.fr>,
vi************@wanadoo.fr says...

我想开发一个应该有几种语言版本的网站,说英语,法语和德语。我的问题是:我如何建议访问者的浏览器根据他们的偏好显示正确的语言?

I would like to develop a site that should be available in several
languages, say English, French and German. My question is: how can I
suggest browsers of visitors to display the correct language depending
on their preferences ?



....

这是一个很好的起点:

http://ppewww.ph.gla.ac.uk/~flavell/www/lang-neg.html


和请确保按照底部的链接进行操作!


....
This is a good starting point:

http://ppewww.ph.gla.ac.uk/~flavell/www/lang-neg.html

and make sure you follow the link at the bottom!


>有几种方法可以在服务器上实现这一点;它可能是最简单的
> There are several ways of implementing this on the server; it''s quite
可能最简单的是调查你的服务器是否内置了
。对于Apache,请参阅

http://httpd.apache.org/docs/content-negotiation.html
likely that the easiest is to look into whether your server has something built in. For Apache, see

http://httpd.apache.org/docs/content-negotiation.html




这很有趣,我不知道这个。现在看看php.net显示了

,PHP能够得到这个标题,所以如果你无法访问

服务器配置,你可以这样做用PHP。


if(



That''s interesting, I did not know about this. Now a look at php.net showed
that PHP is able to get this header, so if you don''t have access to the
server configuration you can do it with PHP.

if(


这篇关于UA自动选择合适的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆