-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslateExample.java
More file actions
44 lines (37 loc) · 1.41 KB
/
Copy pathTranslateExample.java
File metadata and controls
44 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//package com.memetix.mst.examples;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
/**
* TranslateExample
*
* A short, sweet demo on how to translate a String using microsoft-translator-java-api
*
* @author griggs.jonathan
* @date Jun 1, 2011
* @since 0.3 June 1, 2011
*/
public class TranslateExample
{
static String translateTextData(String language1, String clientId, String clientSecret, String translateFrom, String translateTo){
Translate.setClientId(clientId);
Translate.setClientSecret(clientSecret);
String translatedText = "";
Language tf = Language.fromString(translateFrom);
Language tt = Language.fromString(translateTo);
try{
translatedText = Translate.execute(language1, tf, tt);
}
catch (Exception e){
System.err.println("ERROR : " + e.getMessage());
}
return translatedText;
}
void getLanguageNames(){
//Get the all the values in the enum and print the non-localized name (i.e. the literal name of the Enum constant)
// this is the default way of dealing with lists of enums, but not the most user friendly way to construct a list
System.out.println("\nLanguage Names as Enum Constants\n");
for(Language lang : Language.values()) {
System.out.println(lang.name() + " : " + lang.toString());
}
}
}