<html lang="en"> 和 <html lang="en-US"> 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11318961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:26:04  来源:igfitidea点击:

What is the difference between <html lang="en"> and <html lang="en-US">?

htmllang

提问by Celeritas

What is the difference between <html lang="en">and <html lang="en-US">? What other values can follow the dash?

<html lang="en">和 和有<html lang="en-US">什么区别?破折号后面还有哪些其他值?

According to w3.org"Any two-letter subcode is understood to be a [ISO3166] country code." so does that mean any value listed under the alpha-2 codeis an accepted value?

根据w3.org,“任何两个字母的子代码都被理解为 [ISO3166] 国家/地区代码。” 那么这是否意味着alpha-2 代码下列出的任何都是可接受的值?

回答by Jeremy Wiggins

<html lang="en">
<html lang="en-US">

<html lang="en">
<html lang="en-US">

The first langtag only specifies a language code. The second specifies a language code, followed by a country code.

第一个lang标签只指定一个语言代码。第二个指定语言代码,后跟国家代码。

What other values can follow the dash? According to w3.org "Any two-letter subcode is understood to be a [ISO3166] country code."so does that mean any value listed under the alpha-2 code is an accepted value?

破折号后面还有哪些其他值?根据 w3.org,“任何两个字母的子代码都被理解为 [ISO3166] 国家/地区代码。” 那么这是否意味着 alpha-2 代码下列出的任何值都是可接受的值?

Yes, however the value may or may not have any real meaning.

是的,但是该值可能有也可能没有任何实际意义。

<html lang="en-US">essentially means "this page is in the US style of English." In a similar way, <html lang="en-GB">would mean "this page is in the United Kingdom style of English."

<html lang="en-US">本质上的意思是“这个页面是美式英语”。以类似的方式,<html lang="en-GB">将表示“此页面采用英国风格的英语”。

If you really wanted to specify an invalid combination, you could. It wouldn't mean much, but <html lang="en-ES">is valid according to the specification, as I understand it. However, that language/country combination won't do much since English isn't commonly spoken in Spain.

如果你真的想指定一个无效的组合,你可以。它没有多大意义,但<html lang="en-ES">根据我的理解,根据规范是有效的。但是,这种语言/国家/地区组合不会有太大作用,因为西班牙不常使用英语。

I mean does this somehow further help the browser to display the page?

我的意思是这是否以某种方式进一步帮助浏览器显示页面?

It doesn't help the browser to display the page, but it is useful for search engines, screen readers, and other things that might read and try to interpret the page, besides human beings.

它无助于浏览器显示页面,但它对搜索引擎、屏幕阅读器和其他可能阅读并尝试解释页面的事物(人类除外)很有用。

回答by woz

You can use any country code, yes, but that doesn't mean a browser or other software will recognize it or do anything differently because of it. For example, a screen reader might deal with "en-US" and "en-GB" the same if they only support an American accent in English. Another piece of software that has two distinct voices, though, could adjust according to the country code.

您可以使用任何国家/地区代码,是的,但这并不意味着浏览器或其他软件会识别它或因此做任何不同的事情。例如,如果“en-US”和“en-GB”仅支持英语的美国口音,则屏幕阅读器可能会处理相同的“en-US”和“en-GB”。不过,另一个具有两种不同声音的软件可以根据国家/地区代码进行调整。

回答by Alfred D'Souza

This should help : http://www.w3.org/International/articles/language-tags/

这应该有帮助:http: //www.w3.org/International/articles/language-tags/

The golden rule when creating language tags is to keep the tag as short as possible. Avoid region, script or other subtags except where they add useful distinguishing information. For instance, use ja for Japanese and not ja-JP, unless there is a particular reason that you need to say that this is Japanese as spoken in Japan, rather than elsewhere.

The list below shows the various types of subtag that are available. We will work our way through these and how they are used in the sections that follow.

language-extlang-script-region-variant-extension-privateuse

创建语言标签时的黄金法则是保持标签尽可能短。避免使用区域、脚本或其他子标签,除非它们添加了有用的区分信息。例如,使用 ja 表示日语而不是 ja-JP,除非有特殊原因您需要说这是在日本使用的日语,而不是在其他地方使用。

下面的列表显示了可用的各种类型的子标签。我们将逐步了解这些以及如何在接下来的部分中使用它们。

语言-extlang-script-region-variant-extension-privateuse

回答by James Allardice

RFC 3066gives the details of the allowed values (emphasis and links added):

RFC 3066提供了允许值的详细信息(添加了重点和链接):

All 2-letter subtags are interpreted as ISO 3166 alpha-2 country codes from [ISO 3166], or subsequently assigned by the ISO 3166 maintenance agency or governing standardization bodies, denoting the area to which this language variant relates.

所有 2 个字母的子标签都被解释为[ISO 3166] 中的ISO 3166 alpha-2 国家代码,或随后由 ISO 3166 维护机构或管理标准化机构分配,表示与此语言变体相关的区域。

I interpret that as meaning any valid (according to ISO 3166) 2-letter code is valid as a subtag. The RFC goes on to state:

我将其解释为任何有效的(根据 ISO 3166)2 字母代码作为子标签是有效的。RFC 继续指出:

Tags with second subtags of 3 to 8 letters may be registered with IANA, according to the rules in chapter 5 of this document.

根据本文档第 5 章中的规则,可以向 IANA 注册带有 3 到 8 个字母的第二个子标签的标签。

By the way, that looks like a typo, since chapter 3 seems to relate to the the registration process, not chapter 5.

顺便说一句,这看起来像是一个错字,因为第 3 章似乎与注册过程有关,而不是第 5 章。

A quick search for the IANA registry reveals a verylong list, of all the available language subtags. Here's one example from the list (which would be used as en-scouse):

快速搜索 IANA 注册中心会发现一个非常长的列表,其中包含所有可用的语言子标签。这是列表中的一个示例(将用作en-scouse):

Type: variant

Subtag: scouse

Description: Scouse

Added: 2006-09-18

Prefix: en

Comments: English Liverpudlian dialect known as 'Scouse'

类型:变体

子标签:scouse

描述:斯科斯

补充:2006-09-18

前缀:en

评论:英语利物浦方言被称为“Scouse”

There are all sortsof subtags available; a quick scroll has already revealed fr-1694acad(17th century French).

各种可用的子标签;一个快速卷轴已经显露出来fr-1694acad(17 世纪的法语)。



The usefulness of some of these (I would say the vast majority of these) tags, when it comes to documents designed for display in the browser, is limited. The W3C Internationalization specificationsimply states:

当涉及设计用于在浏览器中显示的文档时,其中一些(我会说其中的绝大多数)标签的用处是有限的。在W3C国际规范只是说:

Browsers and other applications can use information about the language of content to deliver to users the most appropriate information, or to present information to users in the most appropriate way. The more content is tagged and tagged correctly, the more useful and pervasive such applications will become.

浏览器和其他应用程序可以使用有关内容语言的信息向用户提供最合适的信息,或以最合适的方式向用户呈现信息。标记和正确标记的内容越多,此类应用程序就越有用和普及。

I'm struggling to find detailed information on how browsers behave when encountering different language tags, but they are most likely going to offer some benefit to those users who use a screen reader, which can use the tag to determine the language/dialect/accent in which to present the content.

我正在努力寻找有关浏览器在遇到不同语言标签时的行为方式的详细信息,但它们很可能会给使用屏幕阅读器的用户带来一些好处,屏幕阅读器可以使用标签来确定语言/方言/口音在其中呈现内容。

回答by hellosi

XML Schema requires that the xml namespace be declared and imported before using xml:lang (and other xml namespace values) RELAX NG predeclares the xml namespace, as in XML, so no additional declaration is needed.

XML 模式要求在使用 xml:lang(和其他 xml 名称空间值)之前声明和导入 xml 名称空间。RELAX NG 预先声明了 xml 名称空间,就像在 XML 中一样,因此不需要额外的声明。

回答by Wes Miller

Well, the first question is easy. There are many ens (Englishes) but (mostly) only one US English. One would guess there are en-CN, en-GB, en-AU. Guess there might even be Austrian English but that's more yes you can than yes there is.

嗯,第一个问题很简单。有很多ens(英语),但(大部分)只有一种美国英语。人们会猜测有en-CN, en-GB, en-AU。猜猜甚至可能有奥地利英语,但这比是的要多。