@@ -127,9 +127,7 @@ |
||
127 | 127 | |
128 | 128 | if ($this->translator == 'apertium') { |
129 | 129 | return $this->apertiumTrans(); |
130 | - } |
|
131 | - |
|
132 | - elseif ($this->translator == 'mymemory') { |
|
130 | + } elseif ($this->translator == 'mymemory') { |
|
133 | 131 | return $this->mymemoryTrans(); |
134 | 132 | } |
135 | 133 |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | |
34 | 34 | // Checking whether from_lang or to_lang are set as app_locale. |
35 | 35 | |
36 | - if ($this->from == 'app_locale') {$this->from = App::getLocale();} |
|
36 | + if ($this->from == 'app_locale') {$this->from = App::getLocale(); } |
|
37 | 37 | |
38 | - if ($this->to == 'app_locale') {$this->to = App::getLocale();} |
|
38 | + if ($this->to == 'app_locale') {$this->to = App::getLocale(); } |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | - $available_transoltors = ['apertium', 'mymemory']; |
|
116 | + $available_transoltors = [ 'apertium', 'mymemory' ]; |
|
117 | 117 | |
118 | 118 | // Checks available translators. |
119 | 119 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | // Check if it can be translated from online sources. |
144 | 144 | |
145 | 145 | $host = 'api.mymemory.translated.net'; |
146 | - if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) { |
|
146 | + if ($socket = @ fsockopen($host, 80, $errno, $errstr, 30)) { |
|
147 | 147 | |
148 | 148 | // Host online |
149 | 149 | $urlString = urlencode($this->string); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | if ($this->debug == true) { |
158 | 158 | $details = $data->responseDetails; |
159 | 159 | if ($data->responseStatus == 403) { |
160 | - $details =($data->responseDetails); |
|
160 | + $details = ($data->responseDetails); |
|
161 | 161 | } |
162 | 162 | $this->translation = "<font style='color:red;'>Error ".$data->responseStatus.": ".$details."</font>"; |
163 | 163 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | // Check if it can be translated from online sources. |
198 | 198 | |
199 | 199 | $host = 'api.apertium.org'; |
200 | - if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) { |
|
200 | + if ($socket = @ fsockopen($host, 80, $errno, $errstr, 30)) { |
|
201 | 201 | |
202 | 202 | // Host online |
203 | 203 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $words = explode(' ', $transObtained); |
230 | 230 | foreach ($words as $word) { |
231 | 231 | if ($word != '') { |
232 | - if ($word[0] == '*') { |
|
232 | + if ($word[ 0 ] == '*') { |
|
233 | 233 | $errors = $errors.substr($word, 1).', '; |
234 | 234 | } |
235 | 235 | } |
@@ -138,53 +138,53 @@ |
||
138 | 138 | /** |
139 | 139 | * Get translation from mymemory API. |
140 | 140 | */ |
141 | - private function mymemoryTrans() |
|
142 | - { |
|
143 | - // Check if it can be translated from online sources. |
|
144 | - |
|
145 | - $host = 'api.mymemory.translated.net'; |
|
146 | - if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) { |
|
147 | - |
|
148 | - // Host online |
|
149 | - $urlString = urlencode($this->string); |
|
150 | - $url = "http://$host/get?q=$urlString&langpair=$this->from%7C$this->to"; |
|
151 | - $json = file_get_contents($url); |
|
152 | - $data = json_decode($json); |
|
153 | - |
|
154 | - // Checking response status |
|
155 | - |
|
156 | - if ($data->responseStatus != 200) { |
|
157 | - if ($this->debug == true) { |
|
158 | - $details = $data->responseDetails; |
|
159 | - if ($data->responseStatus == 403) { |
|
160 | - $details =($data->responseDetails); |
|
161 | - } |
|
162 | - $this->translation = "<font style='color:red;'>Error ".$data->responseStatus.": ".$details."</font>"; |
|
163 | - } |
|
141 | + private function mymemoryTrans() |
|
142 | + { |
|
143 | + // Check if it can be translated from online sources. |
|
144 | + |
|
145 | + $host = 'api.mymemory.translated.net'; |
|
146 | + if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) { |
|
147 | + |
|
148 | + // Host online |
|
149 | + $urlString = urlencode($this->string); |
|
150 | + $url = "http://$host/get?q=$urlString&langpair=$this->from%7C$this->to"; |
|
151 | + $json = file_get_contents($url); |
|
152 | + $data = json_decode($json); |
|
153 | + |
|
154 | + // Checking response status |
|
155 | + |
|
156 | + if ($data->responseStatus != 200) { |
|
157 | + if ($this->debug == true) { |
|
158 | + $details = $data->responseDetails; |
|
159 | + if ($data->responseStatus == 403) { |
|
160 | + $details =($data->responseDetails); |
|
161 | + } |
|
162 | + $this->translation = "<font style='color:red;'>Error ".$data->responseStatus.": ".$details."</font>"; |
|
163 | + } |
|
164 | 164 | |
165 | - return; |
|
166 | - } |
|
165 | + return; |
|
166 | + } |
|
167 | 167 | |
168 | - $transObtained = $data->responseData->translatedText; |
|
168 | + $transObtained = $data->responseData->translatedText; |
|
169 | 169 | |
170 | - $this->translation = ucfirst(strtolower(trim($transObtained))); |
|
170 | + $this->translation = ucfirst(strtolower(trim($transObtained))); |
|
171 | 171 | |
172 | 172 | |
173 | - // Checking debug setting to determinate how to output translation |
|
173 | + // Checking debug setting to determinate how to output translation |
|
174 | 174 | |
175 | - if ($this->debug === true) { |
|
176 | - $this->translation = "<font style='color:#00CC00;'>".$this->translation."</font>"; |
|
175 | + if ($this->debug === true) { |
|
176 | + $this->translation = "<font style='color:#00CC00;'>".$this->translation."</font>"; |
|
177 | 177 | } |
178 | 178 | |
179 | - fclose($socket); |
|
180 | - return; |
|
179 | + fclose($socket); |
|
180 | + return; |
|
181 | 181 | |
182 | - } else { |
|
182 | + } else { |
|
183 | 183 | |
184 | - //host offline |
|
185 | - $this->hostDown(); |
|
186 | - } |
|
187 | - } |
|
184 | + //host offline |
|
185 | + $this->hostDown(); |
|
186 | + } |
|
187 | + } |
|
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Get translation from apertium API. |