Geertjan's Blog

  • January 2, 2014

Google Translate in NetBeans IDE 7.4

Geertjan Wielenga
Product Manager

Google Translate API is a paid service from the Google Cloud. Once you've set up your API key and billing information, you can use it in NetBeans IDE, too, of course.

Notice the from/to toolbar, where I've selected English/German: 

Then, above I right-click over a selection and choose "Translate", which I get back in German: 

The code is more or less the same as it was in my 2007 article on this topic:


However, in the meantime there's a REST API that can be used instead. I'm not using the REST API, still the same code as the above, though slightly changed because of changes in the Google Translate API:

public void actionPerformed(ActionEvent ev) {
Language from = TranslatorPanel.from();
Language to = TranslatorPanel.to();
try {
JTextComponent comp = EditorRegistry.lastFocusedComponent();
String toChange = comp.getSelectedText();
String text = TranslateV2.DEFAULT.execute(toChange, from, to);
} catch (java.lang.NullPointerException ex1) {
} catch (GoogleAPIException ex) {

All the source code of the above is here:


Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.