Skip to content

Instantly share code, notes, and snippets.

@phyous
Last active February 18, 2018 22:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save phyous/5078980 to your computer and use it in GitHub Desktop.
Save phyous/5078980 to your computer and use it in GitHub Desktop.
Example call to bing translation api in java.
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
public class ExampleTranslation {
public static void main(String[] args) throws Exception {
//Replace client_id and client_secret with your own.
Translate.setClientId("CLIENT_ID_HERE");
Translate.setClientSecret("CLIENT_SECRET_HERE");
// Translate an english string to spanish
String englishString = "Hello World!";
String spanishTranslation = Translate.execute(englishString, Language.SPANISH);
System.out.println("Original english phrase: " + englishString);
System.out.println("Translated spanish phrase: " + spanishTranslation);
/*
OUTPUT:
Original english phrase: Hello World!
Translated spanish phrase: ¡Hola mundo!
*/
}
}
/*
NOTE:
A) Add the following maven dependency to your code for this to work:
<dependency>
<groupId>com.memetix</groupId>
<artifactId>microsoft-translator-java-api</artifactId>
<version>0.6.1</version>
<type>jar</type>
</dependency>
Or
B) If you don't use maven, add the following jar to your class path:
https://code.google.com/p/microsoft-translator-java-api/downloads/list
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment