创建时翻译

This commit is contained in:
2025-05-09 16:04:16 +08:00
parent 868c81b595
commit b786210ea7
13 changed files with 194 additions and 23 deletions
+42
View File
@@ -0,0 +1,42 @@
<?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') {
$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, 'cn', $targetLang);
if ($rst_dst) {
$vehicle[$k] = $rst_dst["trans_result"]["dst"];
}
}
}
return $vehicle;
}
public function location($location, string $targetLang = 'en') {
$fields = ['name'];
foreach ($location as $k => $var) {
if (in_array($k, $fields)) {
$rst_dst = $this->xunfei->fanyi($var, 'cn', $targetLang);
if ($rst_dst) {
$location[$k] = $rst_dst["trans_result"]["dst"];
}
}
}
return $location;
}
}