timga / php-translo
此软件包最新版本(0.0.1)没有提供许可证信息。
Translo API 的 PHP 库
0.0.1
2022-09-23 11:35 UTC
Requires
- guzzlehttp/guzzle: ^7.0
README
Translo API 的 PHP 客户端
安装
composer require timga/php-translo
翻译
use Translo\Translo; require 'vendor/autoload.php'; $apiKey = 'YOUR-RAPIDAPI-KEY'; $translo = new Translo($apiKey); $textToTranslate = "Что хочешь помнить, то всегда помнишь."; $fromLang = "ru"; $toLang = "en"; $result = $translo->translate($textToTranslate, $fromLang, $toLang); var_dump($result);
输出
array(3) {
'ok' =>
bool(true)
'text_lang' =>
string(2) "ru"
'translated_text' =>
string(47) "What you want to remember, you always remember."
}
批量翻译
use Translo\Translo; require 'vendor/autoload.php'; $apiKey = 'YOUR-RAPIDAPI-KEY'; $translo = new Translo($apiKey); $result = $translo->batchTranslate([ [ "from" => "en", "to" => "ru", "text" => "банан" ], [ "from" => "en", "to" => "es", "text" => "Ma-ia hii\nMa-ia huu" ], [ "from" => "auto", "to" => "bn", "text" => "bonjour" ] ]); var_dump($result);
输出
array(2) {
'ok' =>
bool(true)
'batch_translations' =>
array(3) {
[0] =>
array(3) {
'from' =>
string(2) "en"
'to' =>
string(2) "ru"
'text' =>
string(10) "банан"
}
[1] =>
array(3) {
'from' =>
string(2) "en"
'to' =>
string(2) "es"
'text' =>
string(20) "Ma-ia hola
Ma-ia huu"
}
[2] =>
array(3) {
'from' =>
string(2) "fr"
'to' =>
string(2) "bn"
'text' =>
string(18) "হ্যালো"
}
}
}
检测
use Translo\Translo; require 'vendor/autoload.php'; $apiKey = 'YOUR-RAPIDAPI-KEY'; $translo = new Translo($apiKey); $result = $translo->detect("Translo is the best translator in Telegram"); var_dump($result);
输出
array(2) {
'ok' =>
bool(true)
'lang' =>
string(2) "en"
}