Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 17 - Pages: 2   [ 1 2 | Next ]
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Awesome Translator API!

URL: google-api-translate-java

At 2:17 AM on Nov 20, 2007, Geertjan wrote:

I've just discovered Google's "simple, unofficial, Java client API for using Google Translate ". Here's all you need to do:

And then you'll find that "hello world" is written to System.out. Cool, right? And there's a long list of supported languages.

However, the error message that is returned when a translation fails is revealing:

java.io.IOException: Server returned HTTP response code: 
    400 for URL: http://translate.google.com/translate_t?langpair=fr|it&text=Salut+le+monde
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
        at com.google.api.translate.Translate.translate(Translate.java:42)
        at translator.Main.main(Main.java:18)

In other words, under the hood you're connecting to the actual on-line Google translation service. What this means is that one needs to be on-line to use this service. I.e., as indicated, this is a client on top of the Google translation service, affording you easy access from within your Java desktop application, among others (imagine, for example, how cool this could be on a mobile device). Hurray for this development and long may it continue and improve!

I wonder if/when (and how) this API will change its status from "unofficial" to "official", though.

1 . At 10:43 AM on Nov 20, 2007, Alexander Shvets wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

Geertjan,

if you are using Intellij IDEA, I have the following plugin:

http://code.google.com/p/google-translate-idea-plugin

It helps you to do translation in the editor.

Alexander Shvets.
2 . At 10:57 AM on Nov 20, 2007, Geertjan wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

That's a pretty cool plugin, Alexander. How long have you had it?
3 . At 3:44 PM on Nov 20, 2007, Alexander Hristov DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

I just can't wait for
Translate.translate("Hola Mundo",Language.SPANISH, Language.ENGLISH);
 
-->
 
"Hello (ad:read 'News of The World', your 100% truthful newspaper) World". 


or maybe even


Translate.translate("Camiseta de Osama Bin Laden",Language.SPANISH, Language.ENGLISH);
 
-->
 
"(This is a NSA message. Stay where you are and do not move)"  (+ MIB agents knocking on your door)


or, even better

Translate.translate("The democracy movement in China after the Tiananmen events",Language.ENGLISH, Language.CHINESE);
 
-->
 
""



:-) :-) :-)
Planetalia - Cursos de Java
4 . At 3:59 PM on Nov 20, 2007, Alexander Hristov DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

And while I'm in the mood....

Google:
String txt = Translator.translate("Hello World",Language.FRENCH, Language.ENGLISH);


JCP Process:
Translate.java:
TranslatorFactory tf = TranslatorFactory.newInstance();
LanguageInstanceFactory lif = LanguageInstanceFactory.newInstance();
Language spanish = lif.createNewLanguage( new Locale("es"));
Language english = lif.createNewLanguage( Locale.ENGLISH );
ByteArrayOutputStream bos= new ByteArrayOutputStream();
Translator trans = tf.buildTranslatorFor(spanish);
trans.configureTargetLanguage( spanish );
trans.translate( new StreamSource ( new ByteArrayInputStream( "Hello World".getBytes())), new StreamResult( bos ));
String txt = bos.toString("UTF-8");
 
Translate.xml
<translator-deployment>
  <default-translator-factory>
    com.sum.translation.TransaltorFactory
  </default-translator-factory>
  <default-charset>
   UTF-8
  <default-charset>
  <parental-control> 
     <replace>
       <from>f*ck</from>
       <to>love your neigbours</to>
     </replace>
  </parental-control>
</translator-deployment>
Planetalia - Cursos de Java
5 . At 5:52 PM on Nov 20, 2007, Jason Holbrook wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

It doesn't seem to get around Google blocking requests if you use it to process a properties file. It starts blocking after about a hundred entries. You get blacklisted for about a week from using the translator.
6 . At 6:21 PM on Nov 20, 2007, Pete Cox wrote:
  Click to reply to this thread Reply

Swing client

Someone's written a swing client, hosted on the same server:

http://code.google.com/p/language-translate/
7 . At 8:41 AM on Nov 21, 2007, Geertjan wrote:
  Click to reply to this thread Reply

Re: Swing client

Thanks for the tip! Also, thanks Alexander for the imaginative code rewrites. :-) Glad that Google has simplified all this for us.
8 . At 5:41 PM on Nov 22, 2007, PJ Murray DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

> Geertjan,
>
> if you are using Intellij IDEA, I have the following
> plugin:
>
> http://code.google.com/p/google-translate-idea-plugin
>
> It helps you to do translation in the editor.
>
> Alexander Shvets.

Looks like it is not "unofficial" ....
PJ Murray, CodeFutures Software

Java Code Generation for Java Persistence

Data Access Objects and Service Data Objects

9 . At 6:07 AM on Nov 23, 2007, graham o'regan wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

rofl - classic!
10 . At 6:10 AM on Nov 23, 2007, graham o'regan wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

Alexander: classic!
11 . At 9:45 AM on Nov 23, 2007, Walter Laan wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

The 'api' actually requests the web page http://translate.google.com/translate_t?langpair=en|nl&text=hello and parses the returned web page to get the translation out. The swing application does the same, except uses additional libraries for html parsing.

Anyway, to let it translate stuff which falls outside the standard char-set change line 52 to
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
or it won't even translate to Spanish or Chinese without garbling the output ;).
12 . At 3:16 AM on Nov 25, 2007, Richard Midwinter wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

Should work fine if your default encoding is UTF-8.
13 . At 11:39 AM on Nov 26, 2007, Carl Dea wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

Cool, this can be used with the Java Speech API to speak in the language of choice...

Hear my RSS feeds in a different language in the morning while brushing my teeth.



-Carl
14 . At 11:46 AM on Nov 26, 2007, Geertjan wrote:
  Click to reply to this thread Reply

Re: Awesome Translator API!

Or hear your Java code recited in Japanese... :-)

thread.rss_message