如何使用google translate api更改整个应用程序中textview的文本?
答案 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)