微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何用罗马字母翻译成日语?

如何解决如何用罗马字母翻译成日语?

我想用 PHP 翻译成日语,结果总是用日语字符。 但我需要罗马字母的结果(就像在 https://translate.google.com 上是可能的)

我可以用 Google\Cloud\Translate\V3\TranslationServiceClient(高级) 和 Google\Cloud\Translate\V2\TranslationServiceClient(基础)

我也尝试过 REST API。

但它们都没有提供罗马(拉丁)字符。

有人知道怎么做吗?

以下是一些示例代码,展示了我如何进行翻译:

require_once ('vendor/autoload.PHP');
use Google\Cloud\Translate\V3\TranslationServiceClient;

$translationClient = new TranslationServiceClient(['credentials' => $xxx]);
//$xxx contains my authentication JSON
$content = ['This is some text to tranlate'];
$targetLanguage = 'ja';

$response = $translationClient->translateText(
    $content,$targetLanguage,TranslationServiceClient::locationName('my Google cloud project ID','global')
);
foreach ($response->getTranslations() as $key => $translation) {
    $separator = $key === 2
        ? '!'
        : ',';
    echo $translation->getTranslatedText() . $separator;
}

结果: これは翻訳するテキストです,

想要的结果: Kore wa hon'yaku suru tekisutodesu

$response 对象包含大量文本,但不包含所需的翻译。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。