Use the lang
or xml:lang
attribute to identify the natural language used in a document.
If you use a number of different languages on a page, make sure that any changes in language are clearly
identified by using the lang
or xml:lang
attribute according to the HTML or XHTML
version you use.
Note that HTML only offers the use of the lang
attribute, while XHTML (transitionally) allows both
attributes or only xml:lang
, respectively, since lang
was removed in XHTML 1.1.
Identifying changes in language are important for a number of reasons:
It will allow braille translation software to follow changes in language, e.g., substitute control codes for accented characters, and insert control codes necessary to prevent erroneus creation of Grade 2 braille contractions.
Editorial Note: We may want to put a glossary at the end of the document defining things like "Grade 2 braille contractions".
Similarly, speech synthesizers that "support" multiple languages will be able to speak the text in the appropriate accent with proper pronunciation. If changes are not marked, the synthesizer will try its best to speak the words in the primary language it works in. Thus, the French word for car, "voiture" would be pronounced "voter" by a speech synthesizer that uses English as its primary language.
Marking changes in language can benefit future developements in technology, for example users who are unable to translate between languages themselves will be able to use machines to translate unfamiliar languages.
This example uses the lang
attribute of the span
element to define one phrase
as French and another as Italian.
<p> And with a certain <span lang="fr">je ne sais quoi</span>, she entered both the room, and his life, forever. "My name is Natasha," she said. "<span lang="it">Piacere,</span>" he replied in impeccable Italian, locking the door. </p>
This example demonstrates the use of the xml:lang
attribute defining a quote written in German.
This snippet could be included by an XHTML 1.1 document where lang
is not allowed.
<blockquote xml:lang="de"> <p>Da dachte der Herr daran, ihn aus dem Futter zu schaffen, aber der Esel merkte, daß kein guter Wind wehte, lief fort und machte sich auf den Weg nach Bremen: dort, meinte er, könnte er ja Stadtmusikant werden.</p> </blockquote>