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.
The moose likes HTML, CSS and JavaScript and the fly likes Changing Javascript prompts according to Locale Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Changing Javascript prompts according to Locale" Watch "Changing Javascript prompts according to Locale" New topic
Author

Changing Javascript prompts according to Locale

Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 163

Hello,

In an application, the user selects language in the login page itself, so the interface is loaded in selected language using ResourceBundle. But the Javascript file is consistent, and manually changing seems impossible. The JS prompts messages in English language and I want it to show message in user-selected language. How can I accomplish this? Is there any way, I can do a check before alerting when a particular JS function is called?
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 163

I think I can take field labels from the page itself For example "comment can not be null". "comment" is field label, it will be translated, but what about "can not be null"?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Wouldn't it be easier to have one Javascript file for each language you support, and just have the page download the Javascript version for the language which the user selected?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

Or better yet, have a JS file for each language that only contains a translation table for the text. That way, no code need be repeated.

(Or use Ajax to load such a table.)


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 163

Hi,
For JS, there is only one file, and I can get the language from some class and then display proper prompts after checking the language, because having different JS files, I think will build up the work.
Now I do not know how to call the java method from the JS file, and determine the language. Please help me.

Update: I have specified seperate file name in a JSP thats included with every other JSP, and there I can get the language simply there.

But please explain me this:
Bear wrote: Or better yet, have a JS file for each language that only contains a translation table for the text
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing Javascript prompts according to Locale
 
Similar Threads
woohoo im now brainbench certified in jasvascript
Empty and Distinct SQL query returned in a servlet...
Including .js files into certain pages
calling js file from jsp.
calling functions in .js file