473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

can JS pick up LANG attrib's ..?

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
5 1613
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

"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alexander Födisch | last post by:
Can somebody help me? I want to pick-out the IP-address after my pc is connected with the internet. All this should work with an answering machine. When the connection exists, the answering...
2
by: Earl T | last post by:
Is it possible to have a web browser pick a color from an image on a web page? I am not interested in creating an image map but just reading the colors directly from the screen. Earl
3
by: Jules | last post by:
I've searched high and low for a 3 digit number generator that will pick at random a number between 000 and 999. The only things I have found were generators that pick numbers from 0 to 999. ...
5
by: Gary Mayor | last post by:
Hi, If I have the ' character within the javascript:pick command it doesn't work. Is there some sort of way of escaping these characters like in server side languages. function pick(symbol) {...
10
by: Mark Winter | last post by:
Hello, I am wondering if someone could point me in the right direction to figure out how to create a dynamic form. I have been developing programs in perl and oracle and have recently switched...
3
by: mcnewsxp | last post by:
is there a way to store all of a file's metadata in a text file like you can with DOS' ATTRIB function. specifically music files. tia, mcnewsxp
5
by: 703designs | last post by:
I'm writing an extension for some PHP forum software. $String is the post contents, and I want to do the following to it. Note that I'm not looking for someone to solve this for me, I'm just not...
36
by: Krustov | last post by:
What is wrong with this php code ? . (it works fine - but something that just works isnt good enough for this newsgroup is it) <?php $loopy=1; $kon="repo"; $spock=0;
3
by: Aleksander | last post by:
Which XML parser would be best for building an on-line RSS/Atom reader? I know for starters there's PHP's DOMDocument and SimpleXML, then there's XMLReader and PEAR's XML_Feed_Parser, and then...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.