By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,394 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,394 IT Pros & Developers. It's quick & easy.

can JS pick up LANG attrib's ..?

P: n/a
Hi,

I'm new and naive at JS, but use a lot of modified JS snippets in web
design. I'm working on a six-language site for a client right now that has
a small nav bar at the bottom of each template-based page.

I've had success in previous projects, writing out language-specific nav-bar
code nested in a document.write statement; a unique .js file for each
language.

An idea that I came up with that would allow me to create a function that
would cover all languages was this: if javascript could somehow detect the
"lang" attribute of the <html> tag, it could automatically choose which
"langage" js file to reference for my nav bar.

Example, if my german nav bar was in a file, "/scripts/de.js" the function
would pick up "de" from the "lang" attrib in the <html> tag, assign it to a
variable, say "navlang", and render a document.write statement that would
"write" out my script source reference as such:

<script>
document.write('<script src="/scripts/' + navlang +'.js"></script>');
</script>

my problem is I'm not adept enough at JS to write a function that would grab
the LANG attrib of the page ...

Can anyone help?

thanks for any assistance ...

Stuart
May 29 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Stuart McDougall wrote:
I'm working on a six-language site for a client right now that has
a small nav bar at the bottom of each template-based page.

I've had success in previous projects, writing out language-specific
nav-bar code nested in a document.write statement; a unique .js file for
each language.

An idea that I came up with that would allow me to create a function that
would cover all languages was this: if javascript could somehow detect the
"lang" attribute of the <html> tag, it could automatically choose which
"langage" js file to reference for my nav bar.


Stop right here. How to navigate if client-side script support is not
available?

Why don't you simply use the same server-side script that generated the
`lang' attribute value of the `html' element to generate the proper
navigation bar? (You don't use server-side scripting? I see.)

Yes, it is possible to determine the value of the `lang' attribute of
the `html' element:

var lang = document.documentElement.lang;

But this is part of the /wrong/ approach for i18n.
PointedEars
--
A man who works with his hands is a laborer; a man who works with his
hands and his brain is a craftsman; but a man who works with his hands
and his brain and his heart is an artist.
-- Louis Nizer, lawyer (1902-1994)
May 29 '06 #2

P: n/a

"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:29****************@PointedEars.de...
Stuart McDougall wrote:
I'm working on a six-language site for a client right now that has
a small nav bar at the bottom of each template-based page.

................
var lang = document.documentElement.lang;


Thanks Thomas, the var statement worked ok.

But I'm having trouble writing a statement that will "write" my nav-bar
reference into the page dynamically. I'm using this:

<script language="javascript">
document.write('<script type="text/JavaScript"
src="../javascripts/navbar/' + NavLang + '.js"></script>');
</script>

(I'm using "NavLang" for the variable name, just in case "lang" is a
reserved word...)

What this yeilds in my preview window is: " '); "
in other words, the last 3 trailing punctuation marks of my script.
but I can't see why it would not work; I've used this type of document.write
statement many times before, breaking up the html string into 3 parts due to
a variable in mid-statement.

can anyone advise?

thanks,

Stuart

May 30 '06 #3

P: n/a
MB

"> But I'm having trouble writing a statement that will "write" my nav-bar
reference into the page dynamically. I'm using this:

<script language="javascript">
document.write('<script type="text/JavaScript"
src="../javascripts/navbar/' + NavLang + '.js"></script>');
</script>


Split up the 'script' words in your document.write as those usually cause
trouble:
<script language="javascript">
document.write('<scr'+'ipt type="text/JavaScri'+'pt"
src="../javascri'+'pts/navbar/' + NavLang + '.js"></scr'+'ipt>');
</script>
May 30 '06 #4

P: n/a
MB wrote:
"> But I'm having trouble writing a statement that will "write" my nav-bar
reference into the page dynamically. I'm using this:

<script language="javascript">
The language attribute is deprecated, type is required:

<script type="text/javascript">

document.write('<script type="text/JavaScript"
src="../javascripts/navbar/' + NavLang + '.js"></script>');
</script>


Split up the 'script' words in your document.write as those usually cause
trouble:


No, don't. Quote the forward slash in the written script end tag, the
script engine will ignore it so document.write will write just the
forward slash '</', the HTML render engine will know not to end the
outer script tag there:

... + NavLang + '.js"><\/script>');
--
Rob
May 30 '06 #5

P: n/a
Stuart McDougall wrote:
"Thomas 'PointedEars' Lahn" [...] wrote [...]
Stuart McDougall wrote:
I'm working on a six-language site for a client right now that has
a small nav bar at the bottom of each template-based page. ................
var lang = document.documentElement.lang;


Thanks Thomas, the var statement worked ok.


You are welcome.
But I'm having trouble writing a statement that will "write" my nav-bar
reference into the page dynamically. I'm using this:

<script language="javascript">
document.write('<script type="text/JavaScript"
src="../javascripts/navbar/' + NavLang + '.js"></script>');
</script>
Search the archives for "ETAGO". But as I said already, this is the
/wrong/ approach (and it will also break in NN4 due to the NRLB).
(I'm using "NavLang" for the variable name, just in case "lang" is a
reserved word...)


It is not, and identifiers should not start uppercase unless they refer
to (intended-to-be) constructors.
PointedEars
--
Alcohol and Math don't mix. So please don't drink and derive!
May 30 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.