Accesskey n skips to in-page navigation. Skip to the content start.

s_gotoW3cHome Internationalization
 

Test results: Document-level language declaration

This series of tests is aimed at discovering which approach to declaring the language of a page works in terms of setting the default text processing language.

In order to tell whether the language information is available for use, we test the effect that declaring the language in a given way has on features that make use of language information in a detectable way. Unfortunately, such features are not uniformly supported across current user agents, and so conclusions must be drawn with care.

There are two test cases below. If either one of them gives a positive result, then the language information has been detected. In some cases, one will be positive and the other not, because only one feature is supported by the user agent. If neither gives a negative result, it is necessary to decide whether the user agent supports the features tested before concluding that language information is unavailable. The conventions used in the results help to make that clear.

Summary & conclusions

See the results below for user agents tested. This section summarizes the results of those tests.

Declaring the language in the html tag works for all features we know to be supported.

A default language declared in the HTTP header is not recognized by any user agent for automatic font assignment. It is, however, recognized by Firefox for use of the :lang pseudo-class.

Where multiple languages are declared in the HTTP header, again only Firefox took advantage of that. What was surprising was that both the first and second values were recognized. This means that there is a lack of clarity about what the actual language of the text is at any given point.

IE7 and Opera did not recognize language declarations in the meta tag.

Firefox was able to detect language declared in the meta tag, although only for application of :lang (which is the same as Firefox behavior regarding the HTTP header). If multiple languages are declared in the meta tag, Firefox labels the document text with multiple languages. This leads to predictable problems. An small bit of extra testing showed that if you introduce a rule that matches one of the other languages declared, the rule affects the whole document, regardless of any other in-element language declarations in the document! (See this screen grab, that shows the effect of adding the rule :lang(zh) { background-color: #ff6633; color: white; font-weight: bold; }. Note that the elements containing English text have explicit markup saying lang="en", so they should not be changed by this rule. )

Safari and IE8beta also detected language from the meta tag, but again only for :lang application (which is a distinction that IE8 didn't make in the earlier test). Note that neither of these user agents recognized declarations in the HTTP header declaration. Significantly, also, if multiple values were supplied in the meta tag, neither of these user agents applied any changes to the document (unlike Firefox).

When language is declared differently in the html lang attribute and the meta tag, all browsers ignore the meta tag and use the lang attribute value. This seems consistent with the fact that in the HTML 4.01 spec Content-Language declared in the HTTP header has a lower priority than a language declaration using a language attribute on the html tag.

The lack of widespread recognition of language declarations in the HTTP header and the meta tag and the idiosyncratic results of using the meta tag contrast with the recognition in all tests of the lang attribute on the html element. This indicates that it is best for content authors and developers to use the attribute for declaring the default text processing language. The W3C I18n Activity proposes that the meta element and the HTTP header are better suited for declaring metadata about the intended audience of a document, which would also fit with these findings.

Latest results

These are results for the latest versions of each browser tested. Green (yes) means the user agent detected the language; Red (no) means it did not; White (hyphen) means that that feature is not supported on the user agent. To understand the tests better, see the test pages .

There are separate tests dealing with automatic assignment of CJK fonts and support of the :lang pseudo-class.

Basic declaration tests

UA IE Firefox Opera Safari IE
version 7 3.0.1 9.51 3.1.2 8 Beta
OS XP XP XP XP XP
date 20080814 20080814 20080814 20080814 20080814
  :lang CJK :lang CJK :lang CJK :lang CJK :lang CJK
1 html lang="..." - yes yes yes yes - yes - yes yes
2 HTTP header - no yes no no - no - no no
3 meta element - no yes no no - yes - yes no

Multiple values

UA IE Firefox Opera Safari IE
version 7 3.0.1 9.51 3.1.2 8 Beta
OS XP XP XP XP XP
date 20080814 20080814 20080814 20080814 20080814
  :lang CJK :lang CJK :lang CJK :lang CJK :lang CJK
4 1st of HTTP values - no yes no no - no - no no
5 2nd of HTTP values - no yes no no - no - no no
6 1st of meta values - no yes no no - no - no no
7 2nd of meta values - no yes no no - no - no no

Precedence

Green means that the lang attribute was used in preference to the meta tag to decide the language.

UA IE Firefox Opera Safari IE
version 7 3.0.1 9.51 3.1.2 8 Beta
OS XP XP XP XP XP
date 20080814 20080814 20080814 20080814 20080814
  :lang CJK :lang CJK :lang CJK :lang CJK :lang CJK
8 lang vs meta - yes yes yes yes - yes - yes yes

Tell us what you think (English).

Subscribe to an RSS feed.

New resources

Home page news

Further reading

Author: Richard Ishida, W3C.

Valid XHTML 1.0!
Valid CSS!
Encoded in UTF-8!

Content first published 2004-10-14. Last substantive update 2008-08-15 12:08 GMT. This version 2008-08-15 12:08 GMT

For the history of document changes, search for results-lang-declaration in the i18n blog.