tags:

views:

230

answers:

1

I'm trying to write a dropdown form with a submit button that uses Google translation to translate the current page that I'm on. Here's what I currently have (someone helped me with this):

<form action="http://www.google.com/translate_c" method="get">
  <input type="hidden" name="hl" value="en" />
  <input type="hidden" name="u" value="<?php echo curPageURL(); ?>" />
  <select name="langpair">
    <option value="en%7Cafr">English to Afrikaans</option>
    <option value="en%7Calb">English to Albanian</option>
    ...
  </select>
  <input type="submit" value="Submit" />
</form>

(Echo calls the URL of the current page:)

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>

Why does Google think I'm trying to translate from English to English with this code?

+2  A: 

I modified your code to the following and it works fine:

<form action="http://www.google.com/translate_c" method="get">
  <input type="hidden" name="hl" value="en" />
  <input type="hidden" name="sl" value="en" />
  <input type="hidden" name="u" value="http://www.stackoverflow.com/" />
  <select name="tl">
    <option value="af">English to Afrikaans</option>
    <option value="sq">English to Albanian</option>
  </select>
  <input type="submit" value="Submit" />
</form>

I would recheck the curPageURL function and put in the right values for each of the select box items.

Druid
Terrific! Thank you!
7777