内容语言的 HTML 元标记

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4417923/
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 05:41:03  来源:igfitidea点击:

HTML meta tag for content language

htmlinternationalizationmeta-tags

提问by byneri

What is the difference between the following two HTML meta tags, for specifying spanish web page content:

以下两个 HTML 元标记之间的区别是什么,用于指定西班牙语网页内容:

<meta name="language" content="Spanish">

and

<meta http-equiv="content-language" content="es">

回答by Quentin

<meta name="language" content="Spanish">

<meta name="language" content="Spanish">

This isn't defined in any specification (including the HTML5 draft)

这在任何规范中都没有定义(包括HTML5 草案

<meta http-equiv="content-language" content="es">

<meta http-equiv="content-language" content="es">

This is a poor man's version of a real HTTP header and should really be expressed in the headers. For example:

这是一个真正的 HTTP 标头的穷人版本,应该在标头中真正表达出来。例如:

Content-language: es
Content-type: text/html;charset=UTF-8

It says that the document is intended for Spanish language speakers (it doesn't, however mean the document is written in Spanish; it could, for example, be written in English as part of a language course for Spanish speakers).

它说该文件是为讲西班牙语的人准备的(但这并不意味着该文件是用西班牙语编写的;例如,它可以用英语编写,作为讲西班牙语的人的语言课程的一部分)。

From the spec:

从规范

The Content-Language entity-header field describes the natural language(s) of the intended audience for the enclosed entity. Note that this might not be equivalent to all the languages used within the entity-body.

Content-Language 实体标题字段描述了封闭实体的预期受众的自然语言。请注意,这可能并不等同于实体正文中使用的所有语言。

If you want to state that a document is written in Spanish then use:

如果您想说明文档是用西班牙语编写的,请使用:

<html lang="es">

回答by dakab

You asked for differences, but you can't quite compare those two.

你要求差异,但你不能完全比较这两者。

Note that <meta http-equiv="content-language" content="es">is obsolete and removed in HTML5. It was used to specify “a document-wide default language”, with its http-equivattribute making it a pragma directive(which simulates an HTTP response header like Content-Languagethat hasn't been sent from the server, since it cannot override a real one).

请注意,<meta http-equiv="content-language" content="es">它已过时并已在 HTML5 中删除。它用于指定“文档范围的默认语言”,其http-equiv属性使其成为pragma 指令(模拟Content-Language尚未从服务器发送的 HTTP 响应标头,因为它无法覆盖真正的响应标头)。

Regarding <meta name="language" content="Spanish">, you hardly find any reliable information. It's non-standard and was probably invented as a SEO makeshift.

关于<meta name="language" content="Spanish">,你几乎找不到任何可靠的信息。它是非标准的,可能是作为SEO 临时发明的。

However, the HTML5 W3C Recommendationencourages authors to use the langattribute on htmlroot elements (attribute values must be valid BCP 47 language tags):

但是,HTML5 W3C 建议鼓励作者langhtml根元素上使用属性(属性值必须是有效的BCP 47 语言标签):

<!DOCTYPE html>
<html lang="es-ES">
    <head>
        …

Anyway, if you want to specify the content language to instruct search engine robots, you should consider this quote from Google Search Console Help on multilingual sites:

无论如何,如果您想指定内容语言来指示搜索引擎机器人,您应该考虑多语言网站上来自Google Search Console Help 的引用:

Google uses only the visible content of your page to determine its language. We don't use any code-level language information such as langattributes.

Google 仅使用您网页的可见内容来确定其语言。我们不使用任何代码级语言信息,例如lang属性。

回答by gojeg

Google recommends to use hreflang, read more info

谷歌推荐使用hreflang,阅读更多信息

Examples:

例子:

<link rel="alternate" href="http://example.com/en-ie" hreflang="en-ie" />
<link rel="alternate" href="http://example.com/en-ca" hreflang="en-ca" />
<link rel="alternate" href="http://example.com/en-au" hreflang="en-au" />
<link rel="alternate" href="http://example.com/en" hreflang="en" />

回答by zoladp

Html5 also recommend to use <html lang="es-ES">The small letter lang tag only specifies: language code The large letter specifies: country code

Html5也推荐使用<html lang="es-ES">小写字母lang标签只指定:语言代码 大写字母指定:国家代码

This is really useful for ie.Chrome, when the browser is proposing to translate web content(ie google translate)

这对于 ie.Chrome 非常有用,当浏览器建议翻译网页内容时(即谷歌翻译)