W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: [DOM4] XML lang

From: Jonas Sicking <jonas@sicking.cc>
Date: Wed, 5 Oct 2011 14:07:44 -0700
Message-ID: <CA+c2ei_58jsUvqvNdTAW7BtBm=EUZkgZJ+yu1wPXR-ZEmvJVDA@mail.gmail.com>
To: Marcos Caceres <w3c@marcosc.com>
Cc: public-webapps <public-webapps@w3.org>
On Wed, Oct 5, 2011 at 1:14 AM, Marcos Caceres <w3c@marcosc.com> wrote:
> Would it be possible to add something to DOM4 to allow one to find out what language (xml:lang) was inherited from up the chain, if any?
> Use cases:
> 1. I need to find elements of a particular type/name that are in a particular language (in tree order), so that I can extract that information to display to a user.
> 2. I need to check what the language of an element is (if any), without walking up the tree to look for an xml:lang attribute. Walking the tree is expensive, specially when XML says that xml:lang value is inherited by default.
> (my motivation is making it simpler to implement Widget's i18n model, which relies on xml:lang's inheritance propagating through an XML document: having something to access the XML values above would make the implementation easier).
> Just of the top of my head:
> <foo>
> <bar xml:lang="en"/>
> <bar xml:lang="en-us">
> <baz xml:lang="">
> </bar>
> </foo>
> //using BCP 47 [lookup] algorithm
> var listOfElements = document.getElementsByLang("en-us");
> listOfElements[1].lang == "en";
> listOfElements[0].lang == "en-us";
> [lookup]
> http://tools.ietf.org/html/bcp47#page-2-12

It would make a lot of sense to me to expose an attribute on Node
which does this.

The main benefit I see is not performance. It's the fact that language
information is spread out over a number of sources and so correctly
determining the language of a Node is far from easy. You need to check
for both xml:lang attributes and for lang attributes on
HTML-namespaced elements. Then you should check for the
"Content-Language" header, or, if it's a HTMLDocument, check for a
<meta> equivalent.

As has been pointed out, you can use
Element.matchesSelector(":lang('en-us')") or XPath to test if a node
has a given language. However neither lets you actually *get* the
language of a node, just check if it matches a particular language.
Additionally, matchesSelector doesn't work on text nodes.

/ Jonas
Received on Wednesday, 5 October 2011 21:08:44 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:36 UTC