Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define multiple languages in html root element's lang attribute?

I want to determine more than one language for a document, because it's available in more than one language. If I use:

<meta http-equiv="content-language" content="en,de,fr" /> 

this is not W3C valid and the validator says I should define it in the root's lang attribute, but this attribute only supports one language:

<html lang="en"> 

works, but not

<html lang="de,en,fr"> 

So where should I define it?

like image 431
swd_fs Avatar asked Aug 27 '12 22:08

swd_fs


People also ask

How do you use the lang attribute with more than one language?

If your intended audience speaks more than one language, the HTTP header allows you to use a comma-separated list of languages. Please Note: since you should always use a language attribute on the html tag, and the language attribute always overrides the HTTP header information, this really becomes a fine point.

What is the lang attribute in HTML?

The lang (or sometimes the xml:lang ) attribute specifies the natural language of the content of a web page. An attribute on the html tag sets the language for all the text on the page.

How can I create multiple languages in HTML?

The lang attribute in HTML allows you to set content for languages other than English. You can try to run the following code to implement lang attribute.

What is lang attribute of HTML tag explain with example?

HTML lang Attribute The lang attribute specifies the language of the element's content. Common examples are "en" for English, "es" for Spanish, "fr" for French, and so on.


1 Answers

All attributes support only one language, so I believe you should define only one language; the most important language should be set. This can't be done if you have multiple languages on a single document, so here is the info to solve your problem:

The lang and xml:lang attributes do not allow you to assign multiple languages to a single document. So if you're writing a Web page with multiple languages you have two options:

  1. Define a primary language with the lang attribute, and then call out the secondary language(s) with lang attributes on elements in the document
  2. Define lang in the specific sections of the document as needed:

    <div lang="fr-CA" xml:lang="fr-CA"> Canadian French content... </div> <div lang="en-CA" xml:lang="en-CA"> Canadian English content... </div> <div lang="nl-NL" xml:lang="nl-NL"> Netherlands, Dutch content... </div> 

I have some multiple-language pages and I do use the 2nd option.

You might want to read http://www.w3.org/TR/2007/NOTE-i18n-html-tech-lang-20070412/#ri20060630.133619987

like image 100
jagb Avatar answered Oct 08 '22 17:10

jagb