Files
car_info/app/service/TranslatorService.php
T
2025-05-13 15:29:56 +08:00

42 lines
1.2 KiB
PHP

<?php
namespace app\service;
use app\util\Xunfei;
class TranslatorService
{
private Xunfei $xunfei;
private $lang = ['zh'=>'cn', 'en'=>'en','ru'=>'ru','ar'=>'ar'];
public function __construct() {
$this->xunfei = new Xunfei();
}
public function vehicle($vehicle, string $targetLang = 'en', string $fromLang = 'cn') {
$fields = ['brand', 'model', 'purchase_location', 'procedure_location', 'fbo_destination'];
foreach ($vehicle as $k => $var) {
if (in_array($k, $fields)) {
$rst_dst = $this->xunfei->fanyi($var, $fromLang, $targetLang);
if ($rst_dst) {
$vehicle[$k] = $rst_dst["trans_result"]["dst"];
}
}
}
return $vehicle;
}
public function location($location, string $targetLang = 'en', string $fromLang = 'cn') {
$fields = ['name'];
foreach ($location as $k => $var) {
if (in_array($k, $fields)) {
$rst_dst = $this->xunfei->fanyi($var, $fromLang, $targetLang);
if ($rst_dst) {
$location[$k] = $rst_dst["trans_result"]["dst"];
}
}
}
return $location;
}
}