This is a test of translation in nodeapi

This is a test of the translation using google.

Another programmer outlined an approach:

what we need is just a module that translates the content of every node that needs content translation, when it is inserted and updated. Something as easy as translating the content in the update and insert stages of the nodeapi hook

Here is my first pass at a solution. Some random text:

I love you Alicia.

Introduction

This is an example web page. You can preview and test the website translator here. Try changing the above settings and click the "Preview and Try!" button to see the effect. For example, if you select specific translation languages, the languages in the dropdown menu will change. Enjoy. Add Google's website translator to your webpages, and offer instant access to automatic translation of the pages. Adding the website translator is quick and easy. The Introduction has h3 tags around it. Here is a missspelllling. I live at 963 W. El Roblar Drive, Ojai California 93023 How does it do with that address? Added the i love message, but not seeing it translated. This is definitely a proof of concept only and parsing will need to be better and handle errors appropriately.
function apperceive_tweaks_nodeapi(&$node, $op, $a3 = NULL, $a4 = NU)
{
  switch ($op)
  {
    case 'insert':
    case 'update':
    case 'view':
      if ($node->type == "xlate") 
      {
        $xlatetitle = apperceive_xlate($node->title);
        drupal_set_message('Title: '. $xlatetitle);
        $xlatebody = apperceive_xlate($node->body);
        drupal_set_message('Body: '. $xlatebody);
      }
      break;
  }  
}
where apperceive_xlate() is essentually just a curl and a grep like this:
curl -s -A 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.2.153.1 Safari/525.19' -d='hl=en&langpair=auto|de&tbb=1&ie=UTF-8&text=A+test+of+the+translation+from+google.+Test2' http://translate.google.com/ | grep -oE '([^<]*?)'
Here is a primitive implementation as a proof of concept:
function apperceive_xlate($text = "") 
{
  $text = urlencode($text);
  $xlateurl = 'http://translate.google.com/';
  $xlatedata = 'hl=en&langpair=auto|de&tbb=1&ie=UTF-8&text='. $text;
  $curloptions = array(       // curl options
    CURLOPT_RETURNTRANSFER => true,               // return web page 
    CURLOPT_HEADER         => false,              // don't return headers 
    CURLOPT_FOLLOWLOCATION => true,               // follow redirects 
    CURLOPT_ENCODING       => "",                 // handle all encodings 
    CURLOPT_USERAGENT      => USERAGENT_SAFARI,   // who am i 
    CURLOPT_AUTOREFERER    => true,               // set referer on redirect 
    CURLOPT_CONNECTTIMEOUT => 120,                // timeout on connect 
    CURLOPT_TIMEOUT        => 120,                // timeout on response 
    CURLOPT_MAXREDIRS      => 10,                 // stop after 10 redirects 
    CURLOPT_POST            => 1,                 // sending using post method 
    CURLOPT_POSTFIELDS     => $xlatedata,              // these are my post vars 
    // CURLOPT_SSL_VERIFYHOST => 0,               // don't verify ssl 
    // CURLOPT_SSL_VERIFYPEER => false,           // 
    // CURLOPT_VERBOSE        => 1,               // 
    CURLOPT_URL           => $xlateurl,            // address to fetch
  ); 
  watchdog('apperceive','Curling '. $xlateurl . '?' . $xlatedata);
  $ch = curl_init();
  curl_setopt_array($ch, $curloptions);
  $xlatetext = curl_exec($ch);
  $results = "";
  
  // inside of ...
  if (!ch)
  {
    watchdog('apperceive', 'curl error: '. curl_error($ch));
    return FALSE;
  }

  preg_match_all(REGEX, $xlatetext, $matches);
  if (is_array($matches) && array_key_exists(REGEX_NDX, $matches) && is_array($matches[REGEX_NDX]) && count($matches[REGEX_NDX]))
  {
    $matchesarr = $matches[REGEX_NDX];
    foreach ($matchesarr as $match)
    {
      if (strpos($match, 'Contribute a better translation') === FALSE) 
        $results .= strip_tags(html_entity_decode($match));
     }
    watchdog('apperceive', 'matches: '. var_export($matchesarr, 1) );
    
  }
  else
  {
    watchdog('apperceive', 'No translation match found.');
    drupal_set_message('No translation match found.');
  }
  curl_close($ch);
  return $results;
}