saviorlv / yii2-bd-translate
基于百度的翻译接口 SDK for Yii2
v1.0.1
2021-12-28 02:21 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ^6.5
- yiisoft/yii2: ^2.0.15
This package is auto-updated.
Last update: 2024-12-10 11:35:40 UTC
README
安装
$ composer require saviorlv/yii2-bd-translate
配置
在使用本扩展之前,你需要去 百度翻译开放平台 注册账号,然后创建应用,获取应用的 API Key。
使用
在 config/main.php 配置文件中定义 component 配置信息
'components' => [ ..... "bdTrans" => [ 'class' => 'Saviorlv\Baidu\Translate', 'app_id' => 'xxx', 'sec_key' => 'xxxxx' ], .... ]
获取
$response = Yii::$app->bdTrans->translate("基于百度的翻译接口", 'zh', 'en');;
返回示例:
[
"code"=> "58000",
"data"=> [ "client_ip"=> "58.38.220.180" ],
"msg"=> "客户端IP非法"
]
[
"code"=> "0",
"msg"=> "请求成功",
"data"=> [
"from"=> "zh",
"to"=> "en",
"trans_result"=> [
"src"=> "xxxxxxxwww",
"dst"=> "Xxxxxxxwww"
]
]
]
参数说明
array public function translate($query, $from, $to)
public $langue = ['zh', 'en', 'yue', 'wyw', 'jp', 'kor', 'fra', 'spa', 'th', 'ara', 'ru', 'pt', 'de', 'it', 'el', 'nl', 'pl', 'bul', 'est', 'dan', 'fin', 'cs', 'rom', 'slo', 'swe', 'hu', 'cht', 'vie'];
参考
感谢
非常感谢 Yii
License
MIT