This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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?
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...
Joined: Mar 18, 2009
Could you please clearly give me details on how to do it with the solution you have suggested to create JS through tag.
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
Joined: Mar 18, 2009
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.
Joined: Apr 08, 2009
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
And then in your path you have your includeENG, includeJA, includeES files (or the name you want to give them...