如何使用谷歌翻译获得所有语言中单词的含义?

时间:2012-04-10 18:09:54

标签: php google-translate

如何使用谷歌翻译获得用英语表示的所有语言中单词的含义?例如,如果输入狮子(英文),那么输出应该是,

leon(Spanish)
lion(French)
singam(Tamil)
simhah(Hindi)

等等。

1 个答案:

答案 0 :(得分:1)

使用here中的示例:

<?php
require_once '../../src/apiClient.php';
require_once '../../src/contrib/apiTranslateService.php';

$client = new apiClient();
$client->setApplicationName('Google Translate PHP Starter Application');

// Visit https://code.google.com/apis/console?api=translate to generate your
// client id, client secret, and to register your redirect uri.
// $client->setDeveloperKey('insert_your_developer_key');
$service = new apiTranslateService($client);

$langs = $service->languages->listLanguages();
print "<h1>Languages</h1><pre>" . print_r($langs, true) . "</pre>";

$translations = $service->translations->listTranslations('Hello', 'hi');
print "<h1>Translations</h1><pre>" . print_r($translations, true) . "</pre>";

listTranslations为您提供所需的信息。

我还建议阅读文档,因为它简短:code.google.com/apis/language/translate/v2/using_rest.html