File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Alert message translations - design question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Alert message translations - design question" Watch "Alert message translations - design question" New topic
Author

Alert message translations - design question

Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
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: 15376
    
    6
The way most people do it is you have a JS file for each language and include the one that you need.



Than in your JavaScript code you would just do



Eric
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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?

Thanks,
Srikkanth
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yes, or a JS file can be run through JSP.
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
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: 15376
    
    6
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
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: 15376
    
    6
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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It's cached.
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
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
 
 
subject: Alert message translations - design question