如何在Android应用程序中放入Yandex翻译API? [英] How to put in Yandex translation API in an android application?

查看:450
本文介绍了如何在Android应用程序中放入Yandex翻译API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Yandex转换器将我的android应用程序从英语翻译成印地语? Java API和JSON文件. 我已经有了API密钥,而且我不知道要编写什么代码才能包含API并使其正常工作. 如果发布整个代码,这将非常有帮助:D 谢谢.

How do I make my android application translate from English to Hindi using Yandex translator? Java API and JSON file. I have got the API key and I've no idea what codes are to be written to include the API and make it work. It will be really helpful if you post the entire code :D Thanks.

推荐答案

您可以检查以下API: https://github.com/DoguD/Yandex-Translate-Android-API

You can check this API: https://github.com/DoguD/Yandex-Translate-Android-API

只需将TranslatorBackgroundTask.java文件导入到您的应用程序中,然后如下所示执行:

Just import TranslatorBackgroundTask.java file to your application and then execute as shown below:

import co.oriens.yandex_translate_android_api.TranslatorBackgroundTask;
import android.util.Log;

public class MainActivity extends Activity{
//Set context
Context context=this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Default variables for translation
    String textToBeTranslated = "Hello world, yeah I know it is stereotye.";
    String languagePair = "en-fr"; //English to French ("<source_language>-<target_language>")
    //Executing the translation function
    Translate(textToBeTranslated,languagePair);
}

//Function for calling executing the Translator Background Task
void Translate(String textToBeTranslated,String languagePair){
    TranslatorBackgroundTask translatorBackgroundTask= new TranslatorBackgroundTask(context);
    String translationResult = translatorBackgroundTask.execute(textToBeTranslated,languagePair).get(); // Returns the translated text as a String
    Log.d("Translation Result",translationResult); // Logs the result in Android Monitor
}
}

有关详细说明,您可以阅读github中的自述文件.

For more detailed explanation you can read the README in github.

这篇关于如何在Android应用程序中放入Yandex翻译API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆