什么是内容语言和接受语言? [英] What are Content-Language and Accept-Language?

查看:322
本文介绍了什么是内容语言和接受语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过 Content-Language 的HTTP标头和 Accept-Language ,有人可以解释一下这些是什么为了和它们之间的区别?我有一个多语言网站,想知道我是否应该由用户设置网站当前所选语言。

I have seen the HTTP headers of Content-Language and Accept-Language, could someone explain what these are for and the difference between them? I have a multilingual site and wondering should I be setting both to the sites current selected language, by the user.

推荐答案

Content-Language 来自服务器,让客户知道所请求页面上的语言。 Accept-Language 来自客户端,让服务器知道用户的首选语言。可以有多种语言,每种语言都有可选的权重或质量值。例如:

Content-Language is from the server, and lets the client know what language(s) are present on the requested page. Accept-Language is from the client, and lets the server know the user's preferred language(s). There can be multiple languages, each with an optional weight or 'quality' value. For example:

Accept-Language: da, en-gb;q=0.8, en;q=0.7

(默认权重为1,因此相当于 da; q = 1,en -gb; q = 0.8,en; q = 0.7 )。

(The default weight is 1, so this is equivalent to da;q=1, en-gb;q=0.8, en;q=0.7).

您将需要解析值和权重才能看到如果有适当的翻译,并向用户提供最高首选语言权重的翻译。

You're going to have to parse the values and weights to see if an appropriate translation is available, and provide the user the translation in the highest preferred language weight.

建议您为用户提供替代方案,例如cookie集值,强制为您的网站使用某种语言。这是因为某些用户可能希望以某种语言查看您的网站,而不会更改其语言接受偏好。

It is recommended you give the users an alternative, such as a cookie set value, to force a certain language for your site. This is because some users may want to see your site in a certain language, without changing their language acceptance preferences.

这篇关于什么是内容语言和接受语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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