flagflag  If you want to see English page, please click "English" Button at Left.
1: 2015-12-14 (月) 12:15:42 iseki ソース
Line 1: Line 1:
 +*** PHP for Google Translator [#x18dcc38]
 + <?php
 + $api = '....';
 + $ggl = 'https://www.googleapis.com/language/tra​nslate/v2';
 + $txt = '';
 + $src = '';
 + $dst = '';
 +
 + if (isset($_GET['text'])) $txt = htmlentities($_GET['text'], ENT_QUOTES, 'utf-8');
 + if (isset($_GET['fr']))  $src = $_GET['fr'];
 + if (isset($_GET['to']))  $dst = $_GET['to'];
 + $osrc = $src;
 +
 + //
 + if ($src==='auto' || empty($src)) {
 +       $langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
 +       $langs = array_reverse($langs);
 +       foreach($langs as $lang) {
 +               $ctr = substr($lang, 0, 2);
 +               if ($ctr!=$dst) {
 +                       $src = $ctr;
 +                       break;
 +               }
 +       }
 +       if ($src==='auto' || empty($src)) {
 +               if      ($dst!=='ja') $src = 'ja';
 +               else if ($dst!=='en') $src = 'en';
 +       }
 + }
 +
 + //
 + 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;
 +
 +       $hndl = curl_init($url);
 +       curl_setopt($hndl, CURLOPT_RETURNTRANSFER, true);
 +       $resp = curl_exec($hndl);
 +       curl_close($hndl);
 +
 +       $decd = json_decode($resp, true);
 +
 +       if (array_key_exists('data', $decd)) {
 +               echo $decd['data']['translations'][0]['transl​atedText'];
 +       }
 +       else {
 +               echo 'ERROR : Google Translator returns error!!';
 +               error_log('trans.php: osrc = '.$osrc.', src = '.$src.', dist = '.$dst.', text = '.$txt);
 +               error_log('trans.php: '.print_r($decd, true));
 +       }
 + }
 + else {
 +       error_log('trans.php: osrc = '.$osrc.', src = '.$src.', dist = '.$dst.', text = '.$txt);
 + }


トップ   新規 ページ一覧 単語検索 最終更新   ヘルプ   最終更新の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
<今日>

オンライン状況

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

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

もっと...

アクセスカウンタ

今日 : 4419441944194419
昨日 : 1223912239122391223912239
総計 : 2354208923542089235420892354208923542089235420892354208923542089
Powered by XOOPS Cube 2.1© 2001-2006 XOOPS Cube Project
Design by XoopsDesign.com