aspose file tools*
The moose likes JSP and the fly likes How to Internationalize the JavaScript included in the JSP file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to Internationalize the JavaScript included in the JSP file?" Watch "How to Internationalize the JavaScript included in the JSP file?" New topic
Author

How to Internationalize the JavaScript included in the JSP file?

Siv. Pot
Greenhorn

Joined: Mar 18, 2009
Posts: 7
I have a JSP page with drop down which is populated with locales using getAvailableLocales API of the Locale class and a continue button. Once the locale is chosen and continue is clicked i am displaying another JSP. All the HTML text has been now replaced with the scriplets which would pick the data from the respective properties file based on the locale chosen. Now HTML part is internationalized. Now this JSP has a header.js file include which is used to display common content like logos, welcome messages etc. How do i make this JS to display the text, messages etc based on the current locale that is chosen by the user?
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
How do you create your JavaScript? Do you add it manually?

A solution could be create the JS through a tag so you are creating it in java, the problem has gone.

An other option (very dirty option, I think) if you have your JS in your JSP is to have a hidden field "locale" or something like that and generate the images adding the value of this field. I really think this is not a solution but, well, that's up to you...
Siv. Pot
Greenhorn

Joined: Mar 18, 2009
Posts: 7
Yes. The contents of the javascript are manually written. It has been seperated because it is easy to include the same content in various JSPs by simply including this js file.

Could you please clearly give me details on how to do it with the solution you have suggested to create JS through tag.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Hi there!

I don't know if you have knowledge of custom tags, you can read this about them: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags.html

You can create a tag such as <myTag:includeJS/> or something like that, then create the JS in the action class and attach the information that depends on the locale getting it from the properties or db or where ever you have it stored.

I think this is not a bad solution but if you have no idea of custom tags can be a mess. Also can be a good way of learning them

Good luck!!
Siv. Pot
Greenhorn

Joined: Mar 18, 2009
Posts: 7
Hi,

By the way, You have suggested this solution with struts framework in mind?
I have an existing jsp file which is not developed using the struts framework and i now have to internationalize it.

The soultion suggested by you would still apply for the above specified case.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Yes I was thinking in struts...

Without struts you can use the other solution I gave you, have different files and call them adding the value of a hidden locale var, then inside the JS you have the text in the languages you want and so on... I think that this is a bit dirtier but, between you and me, in my last company they did this way

for example:



And then in your path you have your includeENG, includeJA, includeES files (or the name you want to give them...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Internationalize the JavaScript included in the JSP file?