xhtml document - Lang options question

2019-05-07 05:42发布

What is the difference between the 2 lines shown below?:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">

<meta http-equiv="content-language" content="en-GB" />

If i didn't have the meta tag, what would be the consequence?

Does the meta one affect screen readers and the top one not? I'm a bit confused as to what exactly they do.

Thanks in advance for any help

Best regards

Skip.

5条回答
戒情不戒烟
2楼-- · 2019-05-07 06:16

Dive Into Accessibility's Identifying your language page recommends adding as much as possible to handle as many screen readers as you can, depending on your doctype:

If you're using any variant of HTML 4, change your tag to this (use your own language code if not English):

<html lang="en">

If you're using any variant of XHTML 1.0, change your tag to this (use your language code in both places):

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

If you're using XHTML 1.1, change your tag to this (again, insert your own language code):

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

The same article also references ISO 639.2 to determine what the value of xml:lang should be, although the XML specification references a separate document, RFC4646 Best Current Practice - Tags For Identifying Languages, which seems to indicate your value of "en-GB" is valid.

Google's Web Authoring Statistics (2005) have the following to say about it:

Next is the Content-Language value (used on the http-equiv attribute). Almost as many people use this as specify the lang attribute on the html element. In the HTML5 spec currently the http-equiv attribute is only allowed for the one case of setting the character encoding, which can't really be dropped, as the graph above demonstrates. However, http-equiv="Content-Language" is supported by at least one browser, and as we see here, it is widely used — maybe http-equiv should not be removed after all.

Further, a thread on webproworld talks about the difference between using http-equiv=content-language and name=language to describe the language of the document and implies that both are necessary.

Finally, refer to the HTML Techniques for Web Content Accessibility Guidelines 1.0 document at W3C for some more recommendations, specifically Identifying the Primary Language.

In conclusion it looks like screen readers are looking at lang attributes more than content-language meta information, but most recommendations I've seen advise using meta data anyway. Especially the Google statistics seem pertinent, so perhaps you should leave both in.

查看更多
倾城 Initia
3楼-- · 2019-05-07 06:20

Content-Language is non-conforming in XHTML5.

While it does allow you to specify more than one language, you shouldn't do that (it doesn't help anybody). You should use xml:lang attributes on specific elements instead, e.g.

<p xml:lang="en">Hello <span xml:lang="de">Welt!</span></p>

W3C I18N FAQ is also clearly against <meta>:

The HTTP header or meta element information are not relevant here. By extension, you should specify the text-processing language of the content as a whole by using the lang and/or xml:lang attributes in the html tag.

查看更多
疯言疯语
4楼-- · 2019-05-07 06:28

I believe one advantage of the <meta> version is that you can specify multiple languages, as in <meta http-equiv="Content-Language" content="en-GB, fr" />, for example. Have a look at this for a more in-depth examination of the subject.

查看更多
Rolldiameter
5楼-- · 2019-05-07 06:33

As far as I know, meta http-equiv is only required (if at all) for HTML documents (not XHTML), because XHTML allows to specify the language using xml:lang.

So, no difference, the second line is just redundant.

查看更多
乱世女痞
6楼-- · 2019-05-07 06:34

The HTTP/1.0 RFC 1945 says the Content-Language header field represents "the languages of the intended audience".

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

HTML4 and XHTML1.x treat the meta http-equiv tag as the same information embedded in the html document rather than the HTTP header.

On the other hand, xml:lang and the html lang attribute identify the language of the document, or the fragment contained within the element on which the attribute appears.

So, suppose you had a document that was primarily in French for the purpose of teaching French to English speakers, the content-language would be en-GB, en-US (say), while the xml:lang attribute would be fr-FR.

However, HTML 5 changes this, and the meta http-equiv="content-language" is considered non-conforming HTML which nevertheless defines the document-wide default language, and only supports a single language so is effectively identical to xml:lang on the html element. I can't say I understand the reasoning behind this change but Daniel Glazman and Ian Hickson discuss it at the thread starting at http://lists.w3.org/Archives/Public/public-html/2008Nov/0083.html

查看更多
登录 后发表回答