chengkun
2025-09-13 36fcee83fd60816d65f7c06840f5b8f92c01484a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
 
namespace app\admin\controller;
 
use think\Exception;
use think\facade\Request;
 
class Translation extends Common {
    /*
     * 翻译语言包
     */
    public function trans() {
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $data = Request::post();
            if (!isset($data['qArray']) || !is_array($data['qArray'])) {
                throw new Exception('翻译内容错误');
            }
            if (!isset($data['from']) || empty($data['from'])) {
                throw new Exception('源语言错误');
            }
            if (!isset($data['to']) || empty($data['to'])) {
                throw new Exception('目标语言错误');
            }
            
            $YDObj = new  \app\common\service\YouDaoTrans();
            $ret = $YDObj->do_translate($data['qArray'], $data['from'], $data['to']);
            $ret = json_decode($ret, TRUE);
            if ($ret['errorCode'] != 0) {
                throw new Exception('错误代码:' . $ret['errorCode'] . ',请核对错误代码列表');
            }
            $result = $ret['translateResults'];
            
            return $this->successResponse($result);
        } catch (Exception $exc) {
            return $this->errorResponse($exc->getMessage());
        }
    }
    
 
    
    
}