HTML:多语言元描述?

时间:2015-03-31 08:21:41

标签: html meta-tags

如何为我的网站设置两种语言元描述?

此代码是否有效?

<meta name="description" lang="en" content="english blablabla" />
<meta name="description" lang="hu" content="hungary blablabla" />

2 个答案:

答案 0 :(得分:6)

从Google网站站长中心博客查看此帖子:http://googlewebmastercentral.blogspot.com.es/2010/03/working-with-multilingual-websites.html

&#34; Google会尝试确定每个网页的主要语言。如果您每页只使用一种语言并避免并排翻译,则可以帮助简化语言识别。虽然Google可以将页面识别为多种语言,但我们建议对页面的所有元素使用相同的语言:标题,侧边栏,菜单等。 请注意,Google会忽略所有代码级语言信息,从“lang”属性到文档类型定义(DTD)。某些Web编辑程序会自动创建这些属性,因此在尝试确定网页语言时它们不是很可靠。&#34;

有关多语言网站的一些信息:

自html&#34; lang&#34;属性不允许定义多种语言,指定语言的元属性已过时,根据W3建议,最好在HTTP标头中指定语言。

HTTP/1.1·200·OK
Date:·Sat,·23·Jul·2011·07:28:50·GMT
Server:·Apache/2
Content-Location:·qa-http-and-lang.en.php
Vary:·negotiate,accept-language,Accept-Encoding
TCN:·choice
P3P:·policyref="http://www.w3.org/2001/05/P3P/p3p.xml"
Connection:·close
Transfer-Encoding:·chunked
Content-Type:·text/html; charset=utf-8
Content-Language:·en

与http-equiv属性设置为Content-Language的元素一样,HTTP标头的值可以是逗号分隔的语言标签列表

请参阅: http://tools.ietf.org/html/rfc2616#section-14.12

正如RFC2616所说:

Multiple languages MAY be listed for content that is intended for
   multiple audiences. For example, a rendition of the "Treaty of
   Waitangi," presented simultaneously in the original Maori and English
   versions, would call for

       Content-Language: mi, en

如果您转到http://validator.w3.org/check并尝试验证:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Language" content="en,hu">
<meta charset="UTF-8">
</head>
<body>
<p>Test</p>
</body>
</html>

W3验证工具说:

Line 5, Column 52: Using the meta element to specify the document-wide default language is obsolete. Consider specifying the language on the root element instead.

然后,如果html标签上的lang属性不允许使用多种语言,我认为您最好的尝试将在HTTP标头中指定

答案 1 :(得分:2)

lang属性可以放在任何元素上,而不仅仅是根html元素或meta name="description"。因此,您可以编写<html lang="en"><body>The Chinese translation of Stack Overflow is <span lang="zh-Hans">堆叠溢位</span></body></html>并将这些lang属性放入其中,因为它有助于可视化浏览器选择正确的字体和音频浏览器,供盲人选择正确的语音。

一些非Google搜索引擎仍然希望过时的<meta http-equiv="content-language">标记(特别是Bing和百度据说仍然需要这些标记),但我不知道它们的实现是否符合标准,足以应对两种或更多语言在http-equiv="content-language"中列出(试一试)。

至于搜索引擎是否会尊重多种语言meta name="description"的多个实例(具有适当的lang属性),这取决于搜索引擎。谷歌表示他们不喜欢并排翻译,这对我们这些讨论外语的人来说很可惜。

相关问题