How to translate text in Java

Using the WhatsMate Translation API



This article shows you how to translate textual natural languages in Java.

To translate text (e.g. from English to Spanish) in Java, do this:

  1. Copy the following source code to a Java file named Translator.java.
  2. Specify the language code of the original text on line 18.
  3. Specify the language code of your target language on line 19.
  4. Specify the text that needs to be translated on line 20.
  5. Compile the Java file: javac Translator.java
  6. Execute the class to see the translated text: java Translator

Looking for your language code? See the complete listing.

The trial account only allows you to call the translation API up to 10 times for learning purpose. Subscribe to a Premium plan to use the translation API seriously.

Want to translate text in another programming language? Check out the Translation API page.