wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "On The Fly Internationalization" Watch "On The Fly Internationalization" New topic
Author

On The Fly Internationalization

Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140
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.


Vikas Aggarwal

Founder @
Leads and Deals Limited

www.LeadsAndDeals.com
chanoch wiggers
Author
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 */
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


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hope this helps...
http://servlet.java.sun.com/javaone/conf/bofs/1336/0-sf2001.jsp


SCJP, SCWCD
 
wood burning stoves
 
subject: On The Fly Internationalization
 
Similar Threads
dollar sign question
Internationlization using JSTL
Does form:options support internationalization in 2.5.6
best way to display multiple pages with almost similar fields on them??
struts - internationalization in Action class