It's not a secret anymore!
The moose likes Servlets and the fly likes On The Fly Internationalization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "On The Fly Internationalization" Watch "On The Fly Internationalization" New topic

On The Fly Internationalization

Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140
I have some servlet generated pages and I want them to display in 3-4 more international languages like French, Spanish etc. The problem is the usual technique of using resource bundles can not be used in my case. So I am looking for any ideas on the "On The Fly Internationalization" of the pages. I have visited a site :
This provides the "On The Fly Internationalization". I am open to any ideas in PERL/PHP/Java.

Vikas Aggarwal

Founder @
Leads and Deals Limited
chanoch wiggers
Ranch Hand

Joined: May 24, 2001
Posts: 245
well, as long as you are sure that you are allowed to do this:
URL url = new URL("http://automatic_translation-service");
HttpURLConnection myConn = new HttpURLConnection(url);
/* set the connection to send and receive info */
/* i assume its a post request */
/* set whatever parameters are needed */
String parameters = "lang=" + lang + "content=" + content";
byte[] bytes = parameters.getBytes();
String contentLength = String.valueOf(bytes.length);
myConn.setRequestProperty("Content-length", contentLength);
/* write out the parameters
OutputStream out = con.getOutputStream();
/* Read the output of the translation */
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
while (true) {
String line = in.readLine();
if (line == null) break;
This is probably not the wya I would have gone about it though - automatic translation is good but not good enough to provide reliable and readable quality reading. Why dont you instead get the locale from the servlet context and then user maybe getResourceAsStream() for the resource you require - that will be a much better use of resources on your server since I assume that you content is reasonably static?
String lang = request.getLocale().getLanguage();
if(lang.equals("en") {
} else if {

chanoch<p><a href="" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hope this helps...

I agree. Here's the link:
subject: On The Fly Internationalization
It's not a secret anymore!