xml:lang is my friend

darobin on 2002-03-03T18:40:41

xml:lang is one of those small nuggets in the XML bundle which pretty much no one uses because they are so small and haven't been advertised much, but are truly useful.

It's a simple, standard, attribute that simply says that the content within the scope of the element on which it resides is in that language (expressed as an ISO code).

Naturally, XPath is equiped with the lang('lang') function that returns true if the current node is in the requested language (and it is smart enough to know that fr_CA is fr).

Thanks to this, publishing multilingual documents in XML+XSLT is a no-brainer. I'd used it before but in a different way (mostly to filter out content before it was processed) and while I knew it to be useful I hadn't realised just how simple it is to just tag part of a structure as being in another language and not render it. While translating my résumé it occured to me that I had just used xml:lang without even thinking about it, and that it had just worked :)


language tagging

TorgoX on 2002-03-03T21:05:42

...says that the content within the scope of the element on which it resides is in that language (expressed as an ISO code).
They can also be RFC3066 language tags, like fr-CA-joual or i-mingo (which are not ISO codes)

...and it is smart enough to know that fr_CA is fr
Doesn't it have to be "fr-CA" instead? "_" is for locales, "-" is for language tags.

Re:language tagging

darobin on 2002-03-04T00:52:05

You are entirely right :)

For the ISO code part, I was using loose terminology (ie I'd heard that it wasn't restricted to ISO but hadn't looked much further), the XPath spec defined matching patterns in the simplest way (that is, a code will match anything on - or end boundaries).

For the locale part, I got mixed up wanting to quote from the perllocale manpage (especially the part about dividing the world into nations instead of, say, "bankers, bikers, gamers, and so on") but forgot to :)

Thanks for being vigilant!