This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hello all,
I'm working on a web application which supports multiple languages, which means alert messages to the user should be shown in the user language. This is putting me in a scenario where i cannot separate the JavaScript functions from the JSP file.
On the server, i had to do something like this when the HTML output is built
And what I tried was to add the translation string as parameters to the function, but sometimes a function may contains 2 or 3 messages and the parameter list gets too big and it is not very intuitive . Is there a better way to handle this?
Thanks,
Srikkanth
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
The way most people do it is you have a JS file for each language and include the one that you need.
That file can also be created programmatically; I've done it both at compile time and runtime.
Srikkanth Mohanasundaram
Ranch Hand
Joined: Feb 07, 2007
Posts: 185
posted
0
Thanks Eric. But the property files are supplied by someone else and copying the messages can be error-prone.(Since i don't know brazilian portuguese :P ). Isn't it?
Hello David,
Can you please elaborate on how to programatically create the file? Do you mean by reading the property files and creating the word
list as suggested by Eric in a JS file?
David Newton wrote: JS file can be run through JSP.
I'm sorry,but i don't get you.
Thanks,
Srikkanth
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
Srikkanth Mohanasundaram wrote:Thanks Eric. But the property files are supplied by someone else and copying the messages can be error-prone.(Since i don't know brazilian portuguese :P ). Isn't it?
I did this with Portugese, Spanish, German, English, and a few other languages. I am not sure what is hard about it since you are already doing it with the jsp example you shown.
I would make it a part of your build process to build the language files from your db, text files or wherever you are holding this data. Have your build script build the js files and they can do the validation on the 3rd party generated content to make sure that it has correct syntax [not translation!]
Eric
Srikkanth Mohanasundaram
Ranch Hand
Joined: Feb 07, 2007
Posts: 185
posted
0
Eric Pascarello wrote:
Have your build script build the js files and they can do the validation on the 3rd party generated content to make sure that it has correct syntax [not translation!]
Okay I get it . I'm planning to do a simple file read/write operation (which would replace the translation) and create the JS files for each language.
Lesson learnt
Thanks for your help.
Srikkanth
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
I would do it only once at build, I would not do it on demand every time since that is a waste of server resources and user time.
Eric Pascarello wrote:I would do it only once at build, I would not do it on demand every time since that is a waste of server resources and user time.
Eric
Yup what i meant was exactly that. Next time you make a release, run that java code which will update the JS files.
Thanks,
Srikkanth
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.