This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Internationalization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Internationalization" Watch "Internationalization" New topic
Author

Internationalization

James Edkins
Greenhorn

Joined: Apr 24, 2001
Posts: 2
Does anybody know the best way to have multiple languages on a site, using JSP's, without having to have multiple JSP's for each language?
David Freels
Ranch Hand

Joined: Feb 01, 2001
Posts: 102
Use the java.util.ResourceBundle class.
David
Sun Certified Programmer for the Java2 Platform
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Just to elaborate a bit, you can put all the text you wish to localize into a properties file, where each line has the format
key=value
where value is the string to be displayed and key is a unique string that you'll use in your program to refer to the entry. Then have that properties file translated (just the values, not the keys - you need to keep the keys the same so that you can refer to them in your program) into each language you wish to support. The base file names of all the properties files must be the same except for a suffix describing the locale. See java.util.ResourceBundle for details.
For example, in a JSP that needs to count from 1 to 3, you need a properties file like this:

and one in French, say

The tricky part is where to put the files. They need to be treated like .class files from the standpoint of the JSP container's class loader. So, for example, you could put them in the web application's /WEB-INF/classes file or a subdirectory from there, if you want to use a package structure:

In the example above, I'm using a subdirectory named "sample".
Then in your JSP:

The resource bundle structure works well in that it automatically allows you to distinguish between Swiss French and Canadian French, for example, and that it looks through the hierarchy of resources for default values.
------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
James Edkins
Greenhorn

Joined: Apr 24, 2001
Posts: 2
Thank you, I will look into that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Internationalization
 
Similar Threads
requirements
web application directory structure
Deploytool
Jsp to Jsp Communication in one page
sending session object from servlt-multiple jsp's