<?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());
|
}
|
}
|
|
|
|
|
}
|