How to make an efficient use of the xml:lang attribue?

156 Views Asked by At

While reading XML specs I saw that XML has two builtin attributes, one of them being xml:lang.

I understood that let user define the language of the current block but how can it be used by XML consumer's programs ?

Can internet browser map the system local and the xml:lang attribute value ? What will be the difference of using xml:lang="en" instead of lang="en" ?

I don't know if I could make myself clear, but if someone has an example of use of the xml:lang atribute, please share.

2

There are 2 best solutions below

0
On

xml:lang has the same purpose as lang - it defines the language a document or fragment is written in. Two different attributes are necessary because not all HTML is XML, and not all XML is (X)HTML.

Use cases:

  • If the XML describes a text document, a word processor could select the appropriate dictionary . te in English meant probably the, but it's a French word.
  • A browser (web, help, or similar) could offer to automatically translate the content if it's not in the list of the languages the user understands (in fact, that's what Chrome does).
  • The attribute could also prevent a code-heavy site from mistakenly being classified as English by search engines.
0
On

I understood that let user define the language of the current block but how can it be used by XML consumer's programs ?

The prime examples are for search engines to promote content in the searcher's known languages higher than other content and for screen readers to switch to a pronunciation library for the language the content is in.

Can internet browser map the system local and the xml:lang attribute value ?

Most browsers don't care. Screen readers do, but if they use the system local language then it is generally as a default of the document doesn't override it.

What will be the difference of using xml:lang="en" instead of lang="en" ?

The former is a generic XML way of specifying the language. The later is an HTML specific way.

In HTML documents, the lang attribute has much better support.