内容语言的 HTML 元标记

发布于 2024-10-07 11:14:43 字数 204 浏览 2 评论 0原文

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

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

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

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

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

and

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

り繁华旳梦境 2024-10-14 11:14:44

Google 建议使用 hreflang,请阅读更多信息

示例:

<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" />

Google recommends to use hreflang, read more info

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" />
甜警司 2024-10-14 11:14:44

Html5 也推荐使用
小写字母lang标签仅指定:语言代码
大字母指定:国家/地区代码

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

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

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

我恋#小黄人 2024-10-14 11:14:44

另一种语言元标记是 og:locale,您可以为社交媒体定义 og:locale 元标记,

<meta property="og:locale" content="en" />

您可以在以下位置阅读有关 og 标记的信息
https://ogp.me/

another language meta tag is og:locale and you can define og:locale meta tag for social media

<meta property="og:locale" content="en" />

you can read about og tags in
https://ogp.me/

梦途 2024-10-14 11:14:44

作为对其他答案的补充,请注意,您还可以将 lang 属性放在页面内的各种 HTML 标记上。
例如,向拼写检查器提示输入文本应为英文:

...

请参阅:https://developer .mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang

As a complement to other answers note that you can also put the lang attribute on various HTML tags inside a page.
For example to give a hint to the spellchecker that the input text should be in english:

<input ... spellcheck="true" lang="en"> ...

See: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang

温折酒 2024-10-14 11:14:43

这在任何规范中均未定义(包括 HTML5 草案)

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

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

它说该文档适用于西班牙语使用者(但这并不意味着该文档是用西班牙语编写的;例如,它可以用英语编写,作为西班牙语使用者语言课程的一部分)。

来自规范

内容语言实体标头字段描述了所包含实体的目标受众的自然语言。请注意,这可能并不等同于实体主体中使用的所有语言。

如果您想声明文档是用西班牙语编写的,则使用

<html lang="es">

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

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

<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:

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.

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

<html lang="es">
得不到的就毁灭 2024-10-14 11:14:43

您要求差异,但您无法完全比较这两者。

请注意 已过时并在 HTML5 中删除。它用于指定“文档范围内的默认语言”,其 http-equiv 属性使其成为pragma 指令(模拟 HTTP 响应标头,例如 Content-Language 尚未是从服务器发送的,因为它不能覆盖真实的)。

关于,你几乎找不到任何可靠的信息。它是非标准的,可能是作为 SEO 权宜之计而发明的< /a>.

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

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

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

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

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-equiv attribute making it a pragma directive (which simulates an HTTP response header like Content-Language that hasn’t been sent from the server, since it cannot override a real one).

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

However, the HTML5 W3C Recommendation encourages authors to use the lang attribute on html root elements (attribute values must be valid BCP 47 language tags):

<!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 uses only the visible content of your page to determine its language. We don’t use any code-level language information such as lang attributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文