Sample of Microsoft Bing translation API usage.
in
Share your Work
•
1 year ago
Following is a simple code explaining how to do translation via Bing api.
A valid app id must be applied before use bing translation service.
But you can use my appId as provided...
String bingTranslate(String query, String langFrom, String langTo)
{ //first encoding to url style try { query = URLEncoder.encode(query, "UTF-8"); } catch (Exception e) { } String appId = "78280AF4DFA1CE1676AFE86340C690023A5AC139"; String url = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId="+ appId+"&from=" + langFrom + "&to=" + langTo + "&text=" + query; return loadStrings(url)[0]; } //Chinese -> English String translateChinese(String query) { return bingTranslate(query, "zh-cn", "en"); } //
English -> Chinese
String translateEnglish(String query) { return bingTranslate(query, "en", "zh-cn"); }
void setup() { println(translateChinese("今天星期几啊")); println(translateEnglish("Every dog has its day!")); }