Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

darobin (1316)

darobin
  (email not shown publicly)
http://berjon.com/

Journal of darobin (1316)

Sunday March 03, 2002
01:40 PM

xml:lang is my friend

[ #3267 ]

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 :)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • ...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 [cpan.org], 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.

    • You are entirely right [w3.org] :)

      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 :)

      --

      -- Robin Berjon [berjon.com]