如何使用Google Translate API?

时间:2011-04-28 06:20:11

标签: android

如何使用google translate api更改整个应用程序中textview的文本?

3 个答案:

答案 0 :(得分:3)

    Translate.setHttpReferrer("http://da.riidr.com/konto/signup/");

    String translatedText = null;
    try {
        translatedText = Translate.execute("Du skal skrive det samme kodeord hver gang.",
                Language.DANISH, Language.ENGLISH);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    System.out.println("Translated page...."+translatedText);

注意:添加google translate api jar 即google.api.translate-java-0.95.jar

答案 1 :(得分:0)

namespace Google\Cloud\Samples\Translate;

// [START translate_translate_text]
use Google\Cloud\Translate\TranslateClient;

// your text 
$text = 'The text to translate.';

// Which language to translate to? language code.
$targetLanguage = 'ja';  

$translate = new TranslateClient();
$result = $translate->translate($text, [
    'target' => $targetLanguage,
]);
print("Source language: $result[source]\n");
print("Translation: $result[text]\n");

答案 2 :(得分:0)

google翻译api for website!

选中此项并按照步骤进行操作 - https://translate.google.com/manager/website/

enter image description here