在使用PHP Google客户端库针对特定句子进行翻译后,我得到了额外的html标签。
这是我要翻译的句子:
<p>Envoie un <span style="color:#459fe5;"><strong>trait de givre</strong></span> sur l'ennemi infligeant des dégâts de froid et déclenchant l'effet "Ralenti" de la mort </p>
我得到这个:
<p> Sends a <span style="color:#459fe5;"><strong>frost line</strong></span> at the enemy that <span style="color:#459fe5;"><strong>deals</strong></span> cold damage and unleashes the "Slow motion" effect of death </p>
您注意到,“ deals”(法语中的“ infligeant”)一词有一个额外的跨度/强力环绕。
例如,如果我将“ trait de givre”替换为“ sort”(拼写),则这样:
<p>Envoie un <span style="color:#459fe5;"><strong>sort</strong></span> sur l'ennemi infligeant des dégâts de froid et déclenchant l'effet "Ralenti" de la mort</p>
我获得了正确的翻译(没有任何额外的html标签):
<p> Sends a <span style="color:#459fe5;"><strong>spell</strong></span> on the enemy that deals cold damage and unleashes the "Slow motion" effect of death </p>
看起来好像是缓存问题,但是我无法确定在Google Translate API上清除它的位置和方式。
$string = '<p>Envoie un <span style="color:#459fe5;"><strong>trait de givre</strong></span> sur l\'ennemi infligeant des dégâts de froid et déclenchant l\'effet "Ralenti" de la mort</p>';
$client = new TranslateClient(['keyFilePath' => config('translate.GoogleAccounts.en_us')]);
$translation = $client->translate($string, [
'source' => 'fr',
'target' => 'en',
'format' => 'html',
]);
print_r($translation);
给予:
Array
(
[source] => fr
[input] => <p>Envoie un <span style="color:#459fe5;"><strong>trait de givre</strong></span> sur l'ennemi infligeant des dégâts de froid et déclenchant l'effet "Ralenti" de la mort</p>
[text] => <p> Sends a <span style="color:#459fe5;"><strong>frost line</strong></span> at the enemy that <span style="color:#459fe5;"><strong>deals</strong></span> cold damage and unleashes the "Slow motion" effect of death </p>
[model] =>
)