Hola a todos.....
Reabro este tema porque a mi me sale el mismo error
Cita: In English: I am a multilingual guy !
In French: ** error : babelfish.class.php returned nothing
In Dutch: ** error : babelfish.class.php returned nothing
¿Alquien lo ha logrado resolver?
Por favor...
Aca esta el codigo de babelfisch.class.php
Código PHP:
<?php
if (!function_exists('')) {
function http_build_query($formdata, $numeric_prefix = "")
{
$arr = array();
foreach ($formdata as $key => $val)
$arr[] = urlencode($numeric_prefix.$key)."=".urlencode($val);
return implode($arr, "&");
}
}
/* translate text using altavista babelfish */
class babelfish{
/* array to store language names */
var $languages = NULL;
/* stores the altavista babelfish url*/
var $babel_url = NULL;
/* stores the search regex (see readme for details) */
var $search_regex = NULL;
/* stores the data to be posted in an array (see readme for details) */
var $post_data = NULL;
/* stores the supported translation combination(s) */
var $valid_translate = NULL;
/* class constructor */
function babelfish($url=NULL,$postdata=NULL,$regex=NULL){
/* Lista de lenguajes */
$this->languages = array(
'en' => 'english',
'zh' => 'chinese',
'zt' => 'chinese-traditional',
'nl' => 'dutch',
'fr' => 'french',
'de' => 'german',
'el' => 'greek',
'it' => 'italian',
'ja' => 'japanese',
'ko' => 'korean',
'pt' => 'portuguese',
'ru' => 'russian',
'es' => 'spanish'
);
/* lista de traducciones validas */
$this->valid_translate=array(
'zt_en','en_zh','en_zt','en_nl','en_fr',
'en_de','en_el','en_it','en_ja','en_ko',
'en_pt','en_ru','en_es','nl_en','nl_fr',
'fr_en','fr_de','fr_el','fr_it','fr_pt',
'fr_nl','fr_es','de_en','de_fr','el_en',
'el_fr','it_en','it_fr','ja_en','ko_en',
'pt_en','pt_fr','ru_en','es_en','es_fr'
);
/* babelfish service url */
if($url!=NULL)
$this->babel_url=$url;
else
$this->babel_url="babelfish.altavista.com/tr";
/* data that is posted to the babelfish site */
if($postdata!=NULL)
$this->post_data=$postdata;
else
$this->post_data=array(
'doit'=>'done',
'intl'=>'1',
'tt'=>'urltext',
'trtext'=>NULL,
'lp'=>NULL
);
/* search for the translated text using this regex */
if($regex!=NULL)
$this->search_regex=$regex;
else
#$this->search_regex='/<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>/';
$this->search_regex='/<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>/sm';
}
/* perform babelfish translation */
function translate($text,$from_language,$to_language){
$f=array_search(strtolower($from_language),$this->languages);
if(!$f){die("***error: source language not found");}
$t=array_search(strtolower($to_language),$this->languages);
if(!$t){die("***error: result language not found");}
$l=$f.'_'.$t;
if(!in_array($l,$this->valid_translate)){die("***error: cant translate with given combination ($l)");}
$this->post_data['trtext']=$text;
$this->post_data['lp']=$l;
$query=http_build_query($this->post_data);
$ch=curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $this->babel_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
$output = curl_exec($ch);
curl_close($ch);
$result=preg_match($this->search_regex,$output,$match);
// return
if($result == 1){
return htmlentities(strip_tags($match[0]));
}else{
return '** error : babelfish.class.php returned nothing';
}
// strip_tags($match[ 0]);
}
}
/* end of class */
?>
y aqui para el ejemplo donde sale el error
Código PHP:
<?php
include("babelfish.class.php");
$message="I am a multilingual guy !";
echo "In English: ".$message.'<br>';
$tr=new babelfish();
echo "In French: ".$tr->translate($message,'english','French').'<br>';
echo "In Dutch: ".$tr->translate($message,'english','dutch').'<br>';
?>
Espero puedan ayudarme
Saludos...