newbie: question on accessing lang attributes

C

ConCat

Hello,

I'm a web designer who is new at Javascript and don't yet fully understand
the potential of it. I manage a large site with 5 sectors that are foreign
language translations and therefore use the lang=xx attrib on the <html>
tag, as well as the "Content-Language" content="xx" attribute of the META
http-equiv tag.

I use javascript script implants on templates to "doc.write" a nav-bar
custom to the particular language I am dealing with. My scheming little
mind (always looking for short-cuts, aren't we? :) thought: If I could
"capture" the language attrib for the page in a string variable (ie, "fr"
for french), I could insert a much more universal JS nav snippet which would
automatically adjust for the language on the page by parsing the html head
for the language attribute.

is this a possibility, or am I dreaming too vividly?

thanks for any pointers or hints...

Gary
 
R

RobG

ConCat said:
Hello,
[...]
mind (always looking for short-cuts, aren't we? :) thought: If I could
"capture" the language attrib for the page in a string variable (ie, "fr"
for french), I could insert a much more universal JS nav snippet which would
automatically adjust for the language on the page by parsing the html head
for the language attribute.

is this a possibility, or am I dreaming too vividly?

To get the lang attribute of the HTML tag:

var eAtt = document.getElementsByTagName('html')[0].attributes;
var eLang = eAtt.lang.value;

However, I think when specifying the language of the actual page,
you should use a meta tag compliant with a meta data standard
(say Dublin Core) and the language should come from RFC 1766:

<URL:http://dublincore.org/documents/1998/09/dces/#>
<URL:http://www.ietf.org/rfc/rfc1766.txt>

<META NAME="Language" CONTENT="fr">

You can get the appropriate meta tag value similarly to the HTML
example and get its content property:

var langTag = document.getElementsByTagName('meta')['Language'];
var langAtt = langTag.content;
alert(langAtt);

Of course you should also feature test getElementsByTagName
before using it and offer a document.all method to suit users of
older IE browsers.
 
C

ConCat

Rob, thanks for the JS help - much appreciated.
I visited the links re the language stuff, but it seems extremely
convoluted.
Too bad they can't explain things in a simple fashion!
I'll have to stick to my two known meta-tags until I get some kind of
easy-to-understand rule about the new Dublin initiative.

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top