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. (sponsored)
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.
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.
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.
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.
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);
-->
""
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.
Awesome Translator API!
URL: google-api-translate-java
At 2:17 AM on Nov 20, 2007, Geertjan wrote:
Fresh Jobs for Developers Post a job opportunity
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.
17 replies so far (
Post your own)
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.
Re: Awesome Translator API!
That's a pretty cool plugin, Alexander. How long have you had it?Re: Awesome Translator API!
I just can't wait forTranslate.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); --> ""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>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.Swing client
Someone's written a swing client, hosted on the same server:http://code.google.com/p/language-translate/
Re: Swing client
Thanks for the tip! Also, thanks Alexander for the imaginative code rewrites.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" ....
Re: Awesome Translator API!
rofl - classic!Re: Awesome Translator API!
Alexander: classic!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 or it won't even translate to Spanish or Chinese without garbling the output
Re: Awesome Translator API!
Should work fine if your default encoding is UTF-8.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
Re: Awesome Translator API!
Or hear your Java code recited in Japanese...