the-botman Posted May 15, 2010 Share Posted May 15, 2010 is there any way of using google to make a translation box so a user can translate text Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/ Share on other sites More sharing options...
Daniel0 Posted May 15, 2010 Share Posted May 15, 2010 Yes, Google provides an API for their translation services. See this post for an example. Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1058746 Share on other sites More sharing options...
the-botman Posted May 15, 2010 Author Share Posted May 15, 2010 ok thank you Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1058761 Share on other sites More sharing options...
the-botman Posted May 18, 2010 Author Share Posted May 18, 2010 i just can`t seem to get any of them to work i was told it can be made into a simple code for a translation box is there anyone who has a code expl? or link to a working code? Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1060055 Share on other sites More sharing options...
Daniel0 Posted May 18, 2010 Share Posted May 18, 2010 Link to working code? Are you serious? I just provided you with that... Here you go again: <?php function translate($textSource, $langSource, $langTarget) { $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource) . '&langpair=' . urlencode($langSource . '|' . $langTarget), CURLOPT_RETURNTRANSFER => true )); $ret = json_decode(curl_exec($ch), true); curl_close($ch); if ($ret['responseStatus'] != '200') { throw Exception('Translation failed.'); } return $ret['responseData']['translatedText']; } echo translate('hola', 'es', 'en'); ?> If that doesn't work then you'll have to elaborate on how it "doesn't work". Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1060082 Share on other sites More sharing options...
salathe Posted May 18, 2010 Share Posted May 18, 2010 http://translate.google.com/translate_tools Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1060089 Share on other sites More sharing options...
the-botman Posted May 18, 2010 Author Share Posted May 18, 2010 i am looking for something like this http://translate.google.com/# Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1060126 Share on other sites More sharing options...
the-botman Posted May 18, 2010 Author Share Posted May 18, 2010 ok what am i doing wrong here <? if($_POST['langpair'] == True) { $textSource = $_GET['text_form']; $langSource = $_GET['langpair']; translate(); } function translate($textSource, $langSource, $langTarget) { $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource) . '&langpair=' . urlencode($langSource . '|' . $langTarget), CURLOPT_RETURNTRANSFER => true )); $ret = json_decode(curl_exec($ch), true); curl_close($ch); if ($ret['responseStatus'] != '200') { throw Exception('Translation failed.'); } return $ret['responseData']['translatedText']; } echo translate('$textSource', 'en', 'ar'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" href="css/style.css" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="icon" href="favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> </head> <body> <hr noshade size="1" style="color:#999" /> <h2>Google Translation API</h2> Enter the text to translate below: <form action='index.php' method=post id="text_form"> <input type=hidden name=hl value="en"> <input type=hidden name=ie value="iso-8859-1"> <?if (!empty($tranlation)) {?> <div class="highlight"> <h2>Translation</h2> <div class="translation"> <?=nl2br(utf8_decode($tranlation))?> </div> </div> <? } ?> <div class="highlight"> <textarea style="width:100%;" name=text rows="5" cols="100" wrap=PHYSICAL dir=ltr id=source><?=stripslashes($textToTranslate)?></textarea> <br/> <select name=langpair> <option value="ar|en">Arabic to English</option> <option value="zh|en">Chinese to English</option> <option value="zh-CN|zh-TW" class="line-above">Chinese (Simplified to Traditional)</option> <option value="zh-TW|zh-CN">Chinese (Traditional to Simplified) BETA</option> <option value="en|ar" class="line-above">English to Arabic</option> <option value="en|zh-CN">English to Chinese (Simplified)</option> <option value="en|zh-TW">English to Chinese (Traditional</option> <option value="en|fr" selected>English to French</option> <option value="en|de">English to German</option> <option value="en|it">English to Italian</option> <option value="en|ja">English to Japanese</option> <option value="en|ko">English to Korean</option> <option value="en|pt">English to Portuguese</option> <option value="en|ru">English to Russian</option> <option value="en|es">English to Spanish</option> <option value="fr|en" class="line-above">French to English</option> <option value="fr|de">French to German</option> <option value="de|en" class="line-above">German to English</option> <option value="de|fr">German to French</option> <option value="it|en" class="line-above">Italian to English</option> <option value="ja|en">Japanese to English BETA</option> <option value="ko|en">Korean to English BETA</option> <option value="pt|en">Portuguese to English</option> <option value="ru|en">Russian to English BETA</option> <option value="es|en">Spanish to English</option> </select> <input type=submit value="Translate" class="submit"> </form> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1060200 Share on other sites More sharing options...
the-botman Posted May 18, 2010 Author Share Posted May 18, 2010 even this dont work <? if($_POST['langpair'] == True) { $textSource = $_POST['text_form']; $langSource = $_GET['langpair']; translate(); } function translate($textSource, $langSource) { $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource) . '&langpair=' . urlencode($langSource) ., CURLOPT_RETURNTRANSFER => true )); $ret = json_decode(curl_exec($ch), true); curl_close($ch); if ($ret['responseStatus'] != '200') { throw Exception('Translation failed.'); } return $ret['responseData']['translatedText']; } echo translate('$textSource', 'en', 'ar'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" href="css/style.css" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="icon" href="favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> </head> <body> <hr noshade size="1" style="color:#999" /> <h2>Translation page</h2> Enter the text to translate below: <form action='index.php' method=post id="text_form"> <input type=hidden name=hl value="en"> <input type=hidden name=ie value="iso-8859-1"> <?if (!empty($tranlation)) {?> <div class="highlight"> <h2>Translation</h2> <div class="translation"> <?=nl2br(utf8_decode($tranlation))?> </div> </div> <? } ?> <div class="highlight"> <textarea style="width:100%;" name=text rows="5" cols="100" wrap=PHYSICAL dir=ltr id=source><?=stripslashes($textToTranslate)?></textarea> <br/> <select name=langpair> <option value="ar|en">Arabic to English</option> <option value="zh|en">Chinese to English</option> <option value="zh-CN|zh-TW" class="line-above">Chinese (Simplified to Traditional)</option> <option value="zh-TW|zh-CN">Chinese (Traditional to Simplified) BETA</option> <option value="en|ar" class="line-above">English to Arabic</option> <option value="en|zh-CN">English to Chinese (Simplified)</option> <option value="en|zh-TW">English to Chinese (Traditional</option> <option value="en|fr" selected>English to French</option> <option value="en|de">English to German</option> <option value="en|it">English to Italian</option> <option value="en|ja">English to Japanese</option> <option value="en|ko">English to Korean</option> <option value="en|pt">English to Portuguese</option> <option value="en|ru">English to Russian</option> <option value="en|es">English to Spanish</option> <option value="fr|en" class="line-above">French to English</option> <option value="fr|de">French to German</option> <option value="de|en" class="line-above">German to English</option> <option value="de|fr">German to French</option> <option value="it|en" class="line-above">Italian to English</option> <option value="ja|en">Japanese to English BETA</option> <option value="ko|en">Korean to English BETA</option> <option value="pt|en">Portuguese to English</option> <option value="ru|en">Russian to English BETA</option> <option value="es|en">Spanish to English</option> </select> <input type=submit value="Translate" class="submit"> </form> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/201865-google-related-translation/#findComment-1060221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.