473,545 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying Javascript alerts in multiple languages

Hello

I have a Java-based web application whose interface can be in multiple
languages. My requirement is that the javascript alerts that I display
should be displayed in the language in which the interface has been
generated. The interface language is dynamically loaded and the text is
displayed using Java's <fmttags.

How can I make the Javascript alerts, etc. also change their display
language dynamically? Is it possible in Javascript or do I have to use
another technology to do the same?

Regards
Swetha

Sep 12 '06 #1
7 8312
sw***********@g mail.com wrote:
Hello

I have a Java-based web application whose interface can be in multiple
languages. My requirement is that the javascript alerts that I display
should be displayed in the language in which the interface has been
generated. The interface language is dynamically loaded and the text is
displayed using Java's <fmttags.

How can I make the Javascript alerts, etc. also change their display
language dynamically? Is it possible in Javascript or do I have to use
another technology to do the same?
I imagine you need to set a variable in JavaScript that holds the
current language and set up a JavaScript object that contains the
different messages. Something like...

var lang = "en";

var message1 = {en: "English alert", fr:"French alert"};

alert(message1[lang]);

Peter

Sep 12 '06 #2
Hi Peter

Does this mean that whenever I add a new language to the application, I
will have to manually add error messages in the new language wherever I
have alerts? Is there some way where this can be done without actually
having to change the code? Something similar to properties files in
Java?

Thanks
Swetha

petermich...@gm ail.com wrote:
sw***********@g mail.com wrote:
Hello

I have a Java-based web application whose interface can be in multiple
languages. My requirement is that the javascript alerts that I display
should be displayed in the language in which the interface has been
generated. The interface language is dynamically loaded and the text is
displayed using Java's <fmttags.

How can I make the Javascript alerts, etc. also change their display
language dynamically? Is it possible in Javascript or do I have to use
another technology to do the same?

I imagine you need to set a variable in JavaScript that holds the
current language and set up a JavaScript object that contains the
different messages. Something like...

var lang = "en";

var message1 = {en: "English alert", fr:"French alert"};

alert(message1[lang]);

Peter
Sep 12 '06 #3
sw***********@g mail.com wrote:
petermich...@gm ail.com wrote:
sw***********@g mail.com wrote:
>
I have a Java-based web application whose interface can be in multiple
languages. My requirement is that the javascript alerts that I display
should be displayed in the language in which the interface has been
generated. The interface language is dynamically loaded and the text is
displayed using Java's <fmttags.
>
How can I make the Javascript alerts, etc. also change their display
language dynamically? Is it possible in Javascript or do I have to use
another technology to do the same?
I imagine you need to set a variable in JavaScript that holds the
current language and set up a JavaScript object that contains the
different messages. Something like...

var lang = "en";

var message1 = {en: "English alert", fr:"French alert"};

alert(message1[lang]);

Does this mean that whenever I add a new language to the application, I
will have to manually add error messages in the new language wherever I
have alerts? Is there some way where this can be done without actually
having to change the code? Something similar to properties files in
Java?
You could do something like this in the head element of the document so
you only load one language.

<script type="text/javascript">
var lang = "en";
document.write( "<scr"+"ipt type='text/javascript'
src='lang/"+lang+"/messages.js'></scr"+"ipt>");
</script>

Where you have files like

lang/en/messages.js

message1="engli sh message";

lang/fr/messages.js

message1="frenc h message";

I can't remember the trick about "script" in the document write
statement. i think you only have to break up the second one so that the
script element doesn't close.

Peter

Sep 12 '06 #4
pe**********@gm ail.com wrote:
<snip>
<script type="text/javascript">
var lang = "en";
document.write( "<scr"+"ipt type='text/javascript'
src='lang/"+lang+"/messages.js'></scr"+"ipt>");
</script>
<snip>
I can't remember the trick about "script" in the document
write statement. i think you only have to break up the
second one so that the script element doesn't close.
Being in a - document.write - call is irrelevant. And HTML parser
reading a script element (as CDATA) has to decide where it is going to
stop passing text to the javascript engine and return to treating text
as mark-up. The HTML spec says that it should do this when it encounters
the first instance of the character sequence '</', which would be
regardless of whether it is in a javascript string (became an HTML
parser known nothing about javascript strings). The SGML spec says that
CDATA will be scanned for '</', but only terminated it when the '</'
turns out to be the start of closing tag for the element, and this is
what browsers do in practice.

However, both the HTML prose and the action of browsers can be satisfied
by avoiding the character sequence '</' inside script elements in an
HTML page. This can be most easily done by escaping the forward slash to
'<\/', which avoids the overheads of superfluous string concatenation
operations.

Opening HTML tags in javascript strings are not an issue at all, and the
HTML spec suggests that the '</' in all closing tags would need to
handled in some way (which the W3C HTML validator used to enforce).

Javascript in external JS files has no issues as no HTML parser ever
examines their text.

Richard.
Sep 12 '06 #5
What I have in the head part of the document is this:

<script language="text/javascript">
function validateForm()
{
var lang = <%= (String)session .getAttribute(" locale")%>;
var check = 0;
<!-- do some checks -->
if(check == 1)
{
var conf =confirm(docume nt.write("<scri pt
type='text/javascript' src='lang/" + lang +
"messages.js'>" mesg1"<\/script>"););
return conf;
}
}
</script>

And the lang/en/messages.js contains
mesg1 = "This is message 1";
And the lang/ar/messags.js contains
mesg1 = "This is Arabic message 1";

However when I run this, it gives me a syntax error at the line which
has document.write( );

What am I doing wrong here?

Swetha

pe**********@gm ail.com wrote:
sw***********@g mail.com wrote:
petermich...@gm ail.com wrote:
sw***********@g mail.com wrote:

I have a Java-based web application whose interface can be in multiple
languages. My requirement is that the javascript alerts that I display
should be displayed in the language in which the interface has been
generated. The interface language is dynamically loaded and the text is
displayed using Java's <fmttags.

How can I make the Javascript alerts, etc. also change their display
language dynamically? Is it possible in Javascript or do I have to use
another technology to do the same?
>
I imagine you need to set a variable in JavaScript that holds the
current language and set up a JavaScript object that contains the
different messages. Something like...
>
var lang = "en";
>
var message1 = {en: "English alert", fr:"French alert"};
>
alert(message1[lang]);
>
Does this mean that whenever I add a new language to the application, I
will have to manually add error messages in the new language wherever I
have alerts? Is there some way where this can be done without actually
having to change the code? Something similar to properties files in
Java?

You could do something like this in the head element of the document so
you only load one language.

<script type="text/javascript">
var lang = "en";
document.write( "<scr"+"ipt type='text/javascript'
src='lang/"+lang+"/messages.js'></scr"+"ipt>");
</script>

Where you have files like

lang/en/messages.js

message1="engli sh message";

lang/fr/messages.js

message1="frenc h message";

I can't remember the trick about "script" in the document write
statement. i think you only have to break up the second one so that the
script element doesn't close.

Peter
Sep 12 '06 #6
Ok, it seems to be working now...

what I've done is simply:

<head>
<script type="text/language"
src="lang/<%=(String)sess ion.getAttribut e("locale")%>/messages.js">
</script>
</head>

And in the body I access the messages for display.

Thanks
Swetha

sw***********@g mail.com wrote:
What I have in the head part of the document is this:

<script language="text/javascript">
function validateForm()
{
var lang = <%= (String)session .getAttribute(" locale")%>;
var check = 0;
<!-- do some checks -->
if(check == 1)
{
var conf =confirm(docume nt.write("<scri pt
type='text/javascript' src='lang/" + lang +
"messages.js'>" mesg1"<\/script>"););
return conf;
}
}
</script>

And the lang/en/messages.js contains
mesg1 = "This is message 1";
And the lang/ar/messags.js contains
mesg1 = "This is Arabic message 1";

However when I run this, it gives me a syntax error at the line which
has document.write( );

What am I doing wrong here?

Swetha

pe**********@gm ail.com wrote:
sw***********@g mail.com wrote:
petermich...@gm ail.com wrote:
sw***********@g mail.com wrote:
>
I have a Java-based web application whose interface can be in multiple
languages. My requirement is that the javascript alerts that I display
should be displayed in the language in which the interface has been
generated. The interface language is dynamically loaded and the text is
displayed using Java's <fmttags.
>
How can I make the Javascript alerts, etc. also change their display
language dynamically? Is it possible in Javascript or do I have to use
another technology to do the same?

I imagine you need to set a variable in JavaScript that holds the
current language and set up a JavaScript object that contains the
different messages. Something like...

var lang = "en";

var message1 = {en: "English alert", fr:"French alert"};

alert(message1[lang]);

>
Does this mean that whenever I add a new language to the application, I
will have to manually add error messages in the new language wherever I
have alerts? Is there some way where this can be done without actually
having to change the code? Something similar to properties files in
Java?
You could do something like this in the head element of the document so
you only load one language.

<script type="text/javascript">
var lang = "en";
document.write( "<scr"+"ipt type='text/javascript'
src='lang/"+lang+"/messages.js'></scr"+"ipt>");
</script>

Where you have files like

lang/en/messages.js

message1="engli sh message";

lang/fr/messages.js

message1="frenc h message";

I can't remember the trick about "script" in the document write
statement. i think you only have to break up the second one so that the
script element doesn't close.

Peter
Sep 12 '06 #7
ASM
sw***********@g mail.com a écrit :
What I have in the head part of the document is this:

<script language="text/javascript">
function validateForm()
{
var lang = <%= (String)session .getAttribute(" locale")%>;
var check = 0;
<!-- do some checks -->
if(check == 1)
{
var conf =confirm(docume nt.write("<scri pt
type='text/javascript' src='lang/" + lang +
don't you forget the slash between lang and file?
lang/en/messages.js
"messages.js'>" mesg1"<\/script>"););
return conf;
}
if(check == 1) {
document.write( '<script type="text/javascript" '+
'src="lang/'+lang+'/messages.js"><\/script>";
var conf = confirm(mesg1);
if(conf) alert('good');
else alert('bad');
}
}
</script>

And the lang/en/messages.js contains
mesg1 = "This is message 1";
And the lang/ar/messags.js contains
mesg1 = "This is Arabic message 1";

However when I run this, it gives me a syntax error at the line which
has document.write( );

What am I doing wrong here?
slash missing ?

--
Stephane Moriaux et son [moins] vieux Mac
Sep 12 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1974
by: Greg Swindle | last post by:
Hello, I have a question about how prototyping relates to variables and their scope. Given the following code: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var ParentObject = function() { var objectName = "ParentObject";
14
5430
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I...
12
2320
by: korund | last post by:
How to make javascript alert with non-english text displaying correctly on computers where english only is default system & language settings? For web page the solution is just use meta tags: <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> Will this work for javascript alerts also?
2
2013
by: Severus Snape | last post by:
I can display and hide 1 object at a time, but haven't seen it done on multiple objects simultaneously. I have four (or more) tables on a page that start off hidden, and I want to toggle their visibility -- but have only one table visible at any time. If I click button #1, table #1 should toggle visibility and all other tables should remain...
5
19061
by: cbs7 | last post by:
Hi all I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation script gen_validatorv2.js which I downloaded from the zip file referenced on http://www.javascript-coder.com/html-form/javascript-form-validation.phtml I managed to get everything working and was...
1
25629
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that...
12
8904
by: pantagruel | last post by:
Hi, I'm thinking of making a WScript based JavaScript library, I can think of some specific non-browser specific scripting examples that should probably make it in, like Crockford's little JavaScripter, can anyone think of anything else. Is anyone familiar with anything similar already done. Things that I am thinking that to provide are:
3
3420
by: tshad | last post by:
Using asp.net 2.0, I am finding that at times, the old javascript will still be there. I was working with it for a couple of hours and the changes seem to happen. But at the end of the day, I found that my last changes weren't taking affect. I was trying to delete my "alerts" before doing a final build but even after taking out all my...
20
2263
by: shapper | last post by:
Hello, How to create a namespace in Javascript containing two methods? And how to access those methods? Thanks, Miguel
0
7496
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7428
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7941
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5354
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3485
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.