collab / module-google-translate-service
Magento 2 模块,提供使用 Google Translate API 的服务。
1.0.0
2024-07-13 12:51 UTC
Requires
- google/cloud-translate: *
- magento/framework: ^103.0.6
README
Collab_GoogleTranslateService 模块允许您使用其服务通过 Google Translate API 进行文本翻译。
基本用法
<?php ... use Collab\GoogleTranslateService\Service\CloudTranslate; ... public function __construct( protected CloudTranslate $cloudTranslate ) { } ... $text = 'Hello, world!'; $targetLanguage = 'fr'; $output = $this->cloudTranslate->translate($text, $targetLanguage); // $output = 'Bonjour, le monde!' ...
服务的 translate
方法接受两个字符串参数
$text
- 要翻译的文本$targetLanguage
- 目标语言代码
安装详情
composer collab/module-google-translate-service bin/magento setup:upgrade
配置
为了使用此服务,您需要在 商店 -> 配置 -> Collab 扩展 -> Google 翻译服务
中配置以下字段
Google 云翻译 API 需要您启用计费,请记住可能会产生一些额外费用(根据:Google Cloud Translation 价格)。