1 | <?php |
||
13 | class Translation |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * Youdao api url |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $api = 'http://fanyi.youdao.com/openapi.do?type=data&doctype=json&version=1.1&'; |
||
22 | /** |
||
23 | * @var Client |
||
24 | */ |
||
25 | protected $http; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $config = []; |
||
31 | |||
32 | /** |
||
33 | * Translation constructor. |
||
34 | * |
||
35 | * @param Client $http |
||
36 | * @param array $config |
||
37 | */ |
||
38 | 6 | public function __construct(Client $http, array $config = []) |
|
43 | |||
44 | /** |
||
45 | * @param array $config |
||
46 | */ |
||
47 | 1 | public function setConfig(array $config) |
|
51 | |||
52 | /** |
||
53 | * @return array |
||
54 | */ |
||
55 | 1 | public function getConfig() |
|
59 | |||
60 | /** |
||
61 | * @param $text |
||
62 | * @return mixed |
||
63 | */ |
||
64 | 3 | public function translate($text) |
|
68 | |||
69 | /** |
||
70 | * @param $text |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function translug($text) |
|
77 | |||
78 | /** |
||
79 | * @param $text |
||
80 | * @return mixed |
||
81 | */ |
||
82 | 4 | private function getTranslatedText($text) |
|
93 | |||
94 | /** |
||
95 | * @param array $translateResponse |
||
96 | * @return mixed |
||
97 | */ |
||
98 | private function getTranslation(array $translateResponse) |
||
106 | |||
107 | /** |
||
108 | * @param array $translateResponse |
||
109 | * @return mixed |
||
110 | */ |
||
111 | private function getTranslatedTextFromResponse(array $translateResponse) |
||
115 | |||
116 | /** |
||
117 | * @param $text |
||
118 | * @return string |
||
119 | */ |
||
120 | private function getTranslateUrl($text) |
||
128 | |||
129 | /** |
||
130 | * @param $text |
||
131 | * @return bool |
||
132 | */ |
||
133 | 4 | private function isEnglish($text) |
|
141 | |||
142 | /** |
||
143 | * Remove segment # |
||
144 | * |
||
145 | * @param $text |
||
146 | * @return mixed |
||
147 | */ |
||
148 | private function removeSegment($text) |
||
152 | |||
153 | } |