flagflag  If you want to see English page, please click "English" Button at Left.
2: 2015-12-14 (月) 12:16:39 iseki ソース 現: 2015-12-16 (水) 00:06:16 iseki ソース
Line 3: Line 3:
 $api = '....';  $api = '....';
 $ggl = 'https://www.googleapis.com/language/tra​nslate/v2';  $ggl = 'https://www.googleapis.com/language/tra​nslate/v2';
 + 
 $txt = '';  $txt = '';
 $src = '';  $src = '';
 $dst = '';  $dst = '';
 + 
 if (isset($_GET['text'])) $txt = htmlentities($_GET['text'], ENT_QUOTES, 'utf-8');  if (isset($_GET['text'])) $txt = htmlentities($_GET['text'], ENT_QUOTES, 'utf-8');
 if (isset($_GET['fr']))  $src = $_GET['fr'];  if (isset($_GET['fr']))  $src = $_GET['fr'];
 if (isset($_GET['to']))  $dst = $_GET['to'];  if (isset($_GET['to']))  $dst = $_GET['to'];
 $osrc = $src;  $osrc = $src;
 + 
 //  //
 if ($src==='auto' || empty($src)) {  if ($src==='auto' || empty($src)) {
-       $langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); +       if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])​) { 
-        $langs = array_reverse($langs); +               $langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); 
-        foreach($langs as $lang) { +                $langs = array_reverse($langs); 
-                $ctr = substr($lang, 0, 2); +                foreach($langs as $lang) { 
-                if ($ctr!=$dst) { +                        $ctr = substr($lang, 0, 2); 
-                        $src = $ctr; +                        if ($ctr!=$dst) { 
-                        break;+                                $src = $ctr; 
 +                                break; 
 +                       }
               }                }
       }        }
Line 29: Line 31:
       }        }
 }  }
 + 
 //  //
 if (!empty($txt) && !empty($src) && !empty($dst) && strlen($src)==2 && strlen($dst)==2 && $src!=$dst) {  if (!empty($txt) && !empty($src) && !empty($dst) && strlen($src)==2 && strlen($dst)==2 && $src!=$dst) {
       //        //
       $url = $ggl.'?key='.$api.'&q='.rawurlencode($tx​t).'&source='.$src.'&target='.$dst;        $url = $ggl.'?key='.$api.'&q='.rawurlencode($tx​t).'&source='.$src.'&target='.$dst;
 + 
       $hndl = curl_init($url);        $hndl = curl_init($url);
       curl_setopt($hndl, CURLOPT_RETURNTRANSFER, true);        curl_setopt($hndl, CURLOPT_RETURNTRANSFER, true);
       $resp = curl_exec($hndl);        $resp = curl_exec($hndl);
       curl_close($hndl);        curl_close($hndl);
 + 
       $decd = json_decode($resp, true);        $decd = json_decode($resp, true);
 + 
       if (array_key_exists('data', $decd)) {        if (array_key_exists('data', $decd)) {
               echo $decd['data']['translations'][0]['transl​atedText'];                echo $decd['data']['translations'][0]['transl​atedText'];
       }        }
       else {        else {
-               echo 'ERROR : Google Translator returns error!!';+               echo 'ERROR : Google Translate returns error!!';
               error_log('trans.php: osrc = '.$osrc.', src = '.$src.', dist = '.$dst.', text = '.$txt);                error_log('trans.php: osrc = '.$osrc.', src = '.$src.', dist = '.$dst.', text = '.$txt);
               error_log('trans.php: '.print_r($decd, true));                error_log('trans.php: '.print_r($decd, true));


トップ   新規 ページ一覧 単語検索 最終更新   ヘルプ   最終更新のRSS 1.0 最終更新のRSS 2.0 最終更新のRSS Atom

サイト内 検索

ログイン

ユーザー名:

パスワード:


パスワード紛失
新規登録

サブ メニュー

ミニカレンダー

前月2024年 5月翌月
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
<今日>

オンライン状況

102 人のユーザが現在オンラインです。 (19 人のユーザが xpwiki を参照しています。)

登録ユーザ: 0
ゲスト: 102

もっと...

アクセスカウンタ

今日 : 6506650665066506
昨日 : 1412914129141291412914129
総計 : 2345211623452116234521162345211623452116234521162345211623452116
Powered by XOOPS Cube 2.1© 2001-2006 XOOPS Cube Project
Design by XoopsDesign.com