This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

On The Fly Internationalization

 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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 :
http://www.freetranslation.com/web.htm
This provides the "On The Fly Internationalization". I am open to any ideas in PERL/PHP/Java.
Thanks.
 
chanoch wiggers
Author
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 */
myConn.setDoOutput(true);
myConn.setDoInput(true);
/* i assume its a post request */
myConn.setRequestMethod("POST");
/* 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();
out.write(bytes);
out.flush();
/* Read the output of the translation */
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
while (true) {
String line = in.readLine();
if (line == null) break;
System.out.println(line);
}
in.close();
out.close();
con.disconnect();
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") {
getResourceAsStream("mypage.en");
} else if {
etc
chanoch
 
L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this helps...
http://servlet.java.sun.com/javaone/conf/bofs/1336/0-sf2001.jsp
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic