aspose file tools*
The moose likes JSP and the fly likes Making site in different languages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Making site in different languages" Watch "Making site in different languages" New topic
Author

Making site in different languages

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
Hi, i have been assigned a project in which i have to translate the site in diff languages (spanish, turkish, etc) depending on user choice. I have no idea how to do it. can you guide me?


The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Arafat Nalkhande
Ranch Hand

Joined: Jul 20, 2006
Posts: 51
You will have to use internationalization (I18n).
At the bare minimum level it would mean that the text is translated but going further issues like currency format, number format, date format and such similar things come into picture.

For the basic text, you will need to have placeholders in your jsp and then have the translated text inside the properties file or you can use database as well. Then based on the user language you can select the corresponding properties file and populate all the placeholders with the corresponding text from the properties file.

Hope it helps...


I want to be myself, but a better myself.<br />~ SCJP 1.4 (91%), SCWCD 1.4 (86%) ~
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
emm, for the time being we are only looking for language.

can you point me towards any tutorial or a bit detail of what you have said.

I can't get what do you mean by placeholder? do you mean for EVER WORD i have to get it from the DATABASE or any other Dictionay file and then make it on JSP?
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
see http://www.richardbrenner.com/wiki/index.php/JSF:internationalization


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Arafat Nalkhande
Ranch Hand

Joined: Jul 20, 2006
Posts: 51
Here is an example of the JSP login Page which ask UserName and Passowrd

Please Enter your User Name : ______________
Please Enter your Password : ______________

Now this will change to

<%=request_username_text%> : ______________
<%=request_password_text%> : ______________

where the request_username_text & request_password_text are simply place holders and they get their value on the fly depending on the language.
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
thanks Arafat!

just one more question. What you prefer, to make a database agains language or we should make dictionary file which on startup loaded by a servlet (depending upon local language) and we use servlet getters to put the values in JSP?
Arafat Nalkhande
Ranch Hand

Joined: Jul 20, 2006
Posts: 51
DB is much much easier to handle and maintain.

Reason for that is whenever you add a keyword then you dont need to go to each and every property file and add that as is the case with the properties file. (This can often lead to human error)

Format for DB can be as follows.
Column 1 : keyword
Column 2 : english
Column 3 : german
Column 4 : french
and so on.

One drawback that DB can have is it gets tricky with the databases to handle characters/words from languages like chinese.
Arafat Nalkhande
Ranch Hand

Joined: Jul 20, 2006
Posts: 51
One more suggestion is that you can have all the keywords defined and initialized in a file called multilingual.jsp.

Then include this file in all the jsp files and then you can directly use the keywords without using the getters.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Here is the free eBook. Its a kind of old discussing Servlet 2.4 and JSP 2.0. I dont know any latest book for free. This could help you in internationalization.
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
hey, thanks adeel . I am already half way with the help of arafat, this book will definitely help me rest
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
>What you prefer, to make a database agains language or we should make
>dictionary file which on startup loaded by a servlet (depending upon local
>language)

Neither.
You should use standard resource bundles - properties files.
The Java tutorial i18n trail explains it reasonably well.

Also note that the JSTL provides tags that can help you with this:
<fmt:message key="login.text.username "/>
<fmt:message key="login.text.password "/>

I would recommend the use of these custom tags in the page rather than java scriptlets.

I disagree with Arafat that a DB is much easier to handle and maintain.
There is more than one program around which can help you maintain your resource bundles consistently. Adding a new language can be as simple as adding a new file to your web app, as opposed to adding a new column to the database.

Regards,
evnafets
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Take heed of Stefan's suggestions as he speaks wisely.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Arafat Nalkhande
Ranch Hand

Joined: Jul 20, 2006
Posts: 51
Hi Stefan,
you said "There is more than one program around which can help you maintain your resource bundles consistently". Well I didnt knew this.

Can you throw some light on this. Probably a URL or two from where I can get these programs or atleast the names of programs.
Babu Subbu
Greenhorn

Joined: Sep 24, 2003
Posts: 9
You can play around with properties files with this class:

http://java.sun.com/j2se/1.3/docs/api/java/util/PropertyResourceBundle.html

Happy localizing.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
There is an Eclipse plugin that does it http://sourceforge.net/projects/eclipse-rbe/

IBM had an article and an app you can use:
http://www-128.ibm.com/developerworks/library/j-rbmgr/index.html?article=xr

I found both of those with a quick google.
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
hey guys, thanks for the suggestion. but uptill now i am unable to start it ... probably have to give look at the tutorials you listed. propertyresourcebundle seems to be another nice approach. thanks
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
I was reading the IBM tutorial for i18n and came accross the following line

The good news/bad news is that, once loaded, ResourceBundle instances are cached under the covers as a performance optimization; this cache is never
refreshed and there is no official way to manipulate the cache.


Does this mean that if once loaded the ResourceBundle the application will remain in that language ??

I have to make my JSP pages in different languages and have made a design to store the user Language preference in Cookie, which will make the server load the Appropriate ResourceBundle on the server to compile the file for that CLIENT. What will happen to if there is another client with different language? Will this resourcebundle reloaded or it will remain in the cache?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Making site in different languages