如何从一种语言到另一种语言的Android翻译文本? [英] How to translate text from one language to another language android?
问题描述
我有我的JSON解析和显示结果的响应。是否有可能转换为其他语言如法语,印地文,德文?
I have a response which I parse from json and displayed the result. Is it possible to convert to other language like French, Hindi, German?
当我浏览,我才知道谷歌停止了对2011年定为免费版本,并开始定价。有没有免费的版本,以响应文本转换成其他语言?
When I browsed, I came to know google stopped on 2011 as free version and started pricing. Is there any free version to convert the response text to other language?
code这块如下:
TextView text; // created an id.
JSONObject jsono=new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("posts");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
String name= object.getString("name");
text.setText(name);// how to convert this to other language.
说的如:响应什么,我得到的是早上好。我需要翻译并在TextView中为卓悦这是在法国的显示。
Say for eg: response what I get is Good morning. which I need to translate and display in textview as Bonjour which is in French.
推荐答案
下面是详细的博客文章上一个Android应用程序使用不同的翻译服务。该人士$ C $ c是在 GitHub的使用的样本<一个href=\"https://github.com/dzlab/DroidTranslator/blob/master/src/org/soufy/translator/TranslationActivity.java#L155-L172\"相对=nofollow>翻译存储器我服务。
Here is a detailed blog post on using different translation services on an Android app. The source code is on github with a sample of using MyMemory service for translation.
/** Translate a given text between a source and a destination language */
public String translate(String text) {
String translated = null;
try {
String query = URLEncoder.encode(text, "UTF-8");
String langpair = URLEncoder.encode(srcLanguage.getLanguage()+"|"+dstLanguage.getLanguage(), "UTF-8");
String url = "http://mymemory.translated.net/api/get?q="+query+"&langpair="+langpair;
HttpClient hc = new DefaultHttpClient();
HttpGet hg = new HttpGet(url);
HttpResponse hr = hc.execute(hg);
if(hr.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
JSONObject response = new JSONObject(EntityUtils.toString(hr.getEntity()));
translated = response.getJSONObject("responseData").getString("translatedText");
}
} catch (Exception e) {
e.printStackTrace();
}
return translated;
}
这篇关于如何从一种语言到另一种语言的Android翻译文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!