1 | <?php |
||
11 | class Translation |
||
12 | { |
||
13 | /** |
||
14 | * Youdao new API url. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $api = 'https://openapi.youdao.com/api?from=zh-CHS&to=EN&'; |
||
19 | /** |
||
20 | * @var Client |
||
21 | */ |
||
22 | protected $http; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $config = []; |
||
28 | |||
29 | /** |
||
30 | * Translation constructor. |
||
31 | * |
||
32 | * @param Client $http |
||
33 | * @param array $config |
||
34 | */ |
||
35 | public function __construct(Client $http, array $config = []) |
||
40 | |||
41 | /** |
||
42 | * @param $text |
||
43 | * |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function translate($text) |
||
50 | |||
51 | /** |
||
52 | * @param $text |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | public function translug($text) |
||
60 | |||
61 | /** |
||
62 | * @param $text |
||
63 | * |
||
64 | * @return mixed |
||
65 | */ |
||
66 | private function getTranslatedText($text) |
||
77 | |||
78 | /** |
||
79 | * @param array $translateResponse |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | private function getTranslation(array $translateResponse) |
||
91 | |||
92 | /** |
||
93 | * @param array $translateResponse |
||
94 | * |
||
95 | * @return mixed |
||
96 | */ |
||
97 | private function getTranslatedTextFromResponse(array $translateResponse) |
||
101 | |||
102 | /** |
||
103 | * @param $text |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | private function getTranslateUrl($text) |
||
118 | |||
119 | /** |
||
120 | * @param $text |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | private function isEnglish($text) |
||
132 | |||
133 | /** |
||
134 | * Remove segment #. |
||
135 | * |
||
136 | * @param $text |
||
137 | * |
||
138 | * @return mixed |
||
139 | */ |
||
140 | private function removeSegment($text) |
||
144 | } |
||
145 |