google-translate - 如何用罗马字母翻译成日文?
问题描述
我正在尝试用 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 对象包含大量文本,但不是所需的翻译。
解决方案
推荐阅读
- database - 是否直接查询交互历史表以进行 pega 决策
- javascript - 谷歌函数:TypeError:无法读取未定义的属性“名称”
- javascript - 在javascript中过滤对象数组
- c# - 我想运行 if 语句几秒钟。我该怎么做?
- angular - 如何在Angular 7中将mat-checkbox标记为选中
- multithreading - kotlin 中协程调度器的明确定义
- python - 如何解决“路径”问题?
- android - 理想的 Gradle 配置为每个源集创建单独的模块做什么?他会改变他的依赖关系吗?
- r - 使用 grepl 查找数据中的相似性
- php - 无论我做什么,调用 VirusTotal API 2.0 总是返回“请求的资源不在完成的、排队的或挂起的扫描中”