@@ -5,31 +5,31 @@ |
||
| 5 | 5 | class GoogleTrans extends Translation |
| 6 | 6 | { |
| 7 | 7 | /** |
| 8 | - * Get translation from Google. |
|
| 9 | - */ |
|
| 10 | - public function main() |
|
| 11 | - { |
|
| 12 | - $host = 'translate.googleapis.com'; |
|
| 8 | + * Get translation from Google. |
|
| 9 | + */ |
|
| 10 | + public function main() |
|
| 11 | + { |
|
| 12 | + $host = 'translate.googleapis.com'; |
|
| 13 | 13 | |
| 14 | - // Check if host is online. |
|
| 15 | - if ($this->checkHost($host)) { |
|
| 14 | + // Check if host is online. |
|
| 15 | + if ($this->checkHost($host)) { |
|
| 16 | 16 | |
| 17 | - // Host online |
|
| 18 | - $urlString = urlencode($this->string); |
|
| 19 | - $urldata = file_get_contents("https://translate.googleapis.com/translate_a/single?client=gtx&sl=$this->from&tl=$this->to&dt=t&q=$urlString"); |
|
| 20 | - $tr = $urldata; |
|
| 21 | - $tr = substr($tr,3,-6); |
|
| 22 | - $tr = $tr.'["'; |
|
| 23 | - $tr = explode('],[', $tr); |
|
| 24 | - $trans = []; |
|
| 25 | - foreach ($tr as $tran) { |
|
| 26 | - $transl = explode('","',$tran); |
|
| 27 | - array_push($trans, str_replace('\"','"',ucfirst(substr($transl[0],1)))); |
|
| 28 | - } |
|
| 29 | - $this->translation = join(' ',$trans); |
|
| 30 | - $this->checkSave(); |
|
| 17 | + // Host online |
|
| 18 | + $urlString = urlencode($this->string); |
|
| 19 | + $urldata = file_get_contents("https://translate.googleapis.com/translate_a/single?client=gtx&sl=$this->from&tl=$this->to&dt=t&q=$urlString"); |
|
| 20 | + $tr = $urldata; |
|
| 21 | + $tr = substr($tr,3,-6); |
|
| 22 | + $tr = $tr.'["'; |
|
| 23 | + $tr = explode('],[', $tr); |
|
| 24 | + $trans = []; |
|
| 25 | + foreach ($tr as $tran) { |
|
| 26 | + $transl = explode('","',$tran); |
|
| 27 | + array_push($trans, str_replace('\"','"',ucfirst(substr($transl[0],1)))); |
|
| 28 | + } |
|
| 29 | + $this->translation = join(' ',$trans); |
|
| 30 | + $this->checkSave(); |
|
| 31 | 31 | |
| 32 | - return; |
|
| 33 | - } |
|
| 34 | - } |
|
| 32 | + return; |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -18,15 +18,15 @@ |
||
| 18 | 18 | $urlString = urlencode($this->string); |
| 19 | 19 | $urldata = file_get_contents("https://translate.googleapis.com/translate_a/single?client=gtx&sl=$this->from&tl=$this->to&dt=t&q=$urlString"); |
| 20 | 20 | $tr = $urldata; |
| 21 | - $tr = substr($tr,3,-6); |
|
| 21 | + $tr = substr($tr, 3, -6); |
|
| 22 | 22 | $tr = $tr.'["'; |
| 23 | 23 | $tr = explode('],[', $tr); |
| 24 | - $trans = []; |
|
| 24 | + $trans = [ ]; |
|
| 25 | 25 | foreach ($tr as $tran) { |
| 26 | - $transl = explode('","',$tran); |
|
| 27 | - array_push($trans, str_replace('\"','"',ucfirst(substr($transl[0],1)))); |
|
| 26 | + $transl = explode('","', $tran); |
|
| 27 | + array_push($trans, str_replace('\"', '"', ucfirst(substr($transl[ 0 ], 1)))); |
|
| 28 | 28 | } |
| 29 | - $this->translation = join(' ',$trans); |
|
| 29 | + $this->translation = join(' ', $trans); |
|
| 30 | 30 | $this->checkSave(); |
| 31 | 31 | |
| 32 | 32 | return; |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | public static function trans($string) |
| 20 | 20 | { |
| 21 | 21 | $translator = config('laralang.default.translator'); |
| 22 | - if (!in_array(config('laralang.default.translator'), ['apertium', 'mymemory', 'google'])) { |
|
| 22 | + if (!in_array(config('laralang.default.translator'), [ 'apertium', 'mymemory', 'google' ])) { |
|
| 23 | 23 | return "<font style='color:red;'>Laralang doesn't support $translator translator. Check config</font>"; |
| 24 | 24 | } else { |
| 25 | 25 | if (config('laralang.default.translator') == 'mymemory') { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public static function toLanguages() |
| 41 | 41 | { |
| 42 | - $locales = []; |
|
| 42 | + $locales = [ ]; |
|
| 43 | 43 | $translations = DB_Translation::distinct()->select('to_lang')->get(); |
| 44 | 44 | foreach ($translations as $object) { |
| 45 | 45 | array_push($locales, $object->to_lang); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public static function fromLanguages() |
| 57 | 57 | { |
| 58 | - $locales = []; |
|
| 58 | + $locales = [ ]; |
|
| 59 | 59 | $translations = DB_Translation::distinct()->select('from_lang')->get(); |
| 60 | 60 | foreach ($translations as $object) { |
| 61 | 61 | array_push($locales, $object->from_lang); |
@@ -71,6 +71,6 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public static function allLanguages() |
| 73 | 73 | { |
| 74 | - return ['English' => 'en', 'Spanish' => 'es', 'Catalan' => 'ca', 'Portuguese' => 'pt', 'Chinese' => 'zh', 'Japanese' => 'ja', 'German' => 'de', 'French' => 'fr']; |
|
| 74 | + return [ 'English' => 'en', 'Spanish' => 'es', 'Catalan' => 'ca', 'Portuguese' => 'pt', 'Chinese' => 'zh', 'Japanese' => 'ja', 'German' => 'de', 'French' => 'fr' ]; |
|
| 75 | 75 | } |
| 76 | 76 | } |