Google 翻译 & PHP - 获取替代翻译

Google Translate & PHP - Getting alternative translations

我有一个非常简单的翻译脚本,使用 Google 翻译如下:

use Google\Cloud\Translate\TranslateClient;
$translate = new TranslateClient([
    'key' => 'xxmyxsuperxsecretxapixkeyxx'
]);

$result = $translate->translate($string, [
    'target' => $lang
]);

$translation = $result['text'];

这给了我一组很好的数据,如下所示:

array(4) { 
    ["source"]=> string(2) "en" 
    ["input"]=> string(10) "dummy text" 
    ["text"]=> string(11) "dummer Text" 
    ["model"]=> NULL 
}

所以第一个问题是这个回复中的 $result['model'] 是什么?

第二个问题是,如果我想在实际 Google 翻译页面上获得其他建议,我该怎么办:

what is $result['model'] in this response?

来自 php 客户端库 docs:

The model to use for the translation request.

关于您的第二个问题:translate client sends requests over the REST API and the latter's docs do not show any support for getting the additional suggestions you see in the translate web UI. One alternative suggestion would be to attempt to scrape the results but, honestly, I have no idea how you could do that using php. you can see an answer to an older question regarding doing so with python and BeautifulSoup and here 使用 node.js 的问题,也许这些会有所帮助。