This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

On The Fly Internationalization  RSS feed

Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 {
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this helps...
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!