1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to translate Rss feeds?

Discussion in 'Blogging' started by gialappas, Feb 22, 2011.

  1. gialappas

    gialappas Regular Member

    Joined:
    Jan 25, 2010
    Messages:
    263
    Likes Received:
    180
    Hi!

    I need a free service that translate rss feeds from english to italian.

    I know yahoo pipes but the translation is bad.
    I know feedtranslate-com but now this service is offline.

    There are some similar service?

    Thanks
     
  2. wickedguy

    wickedguy Supreme Member

    Joined:
    Jul 22, 2009
    Messages:
    1,402
    Likes Received:
    1,379
    Location:
    BHW--> South Africa
    Home Page:
    Ok, here we go using good ol google :D

    PHP:
    <?

    $myRSSfeed='this is the feed';

    $mytranslatedRSSfeedtranslate($myRSSfeed,'en','it');

    function 
    translate($msg,$sl,$tl){

    $url="http://translate.google.com/";
    $header[] = "Content-type: application/x-www-form-urlencoded;charset=UTF-8";

    $msg=utf8_encode($msg);


    $agents[] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; Media Center PC 5.0)";
     
    $agents[] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
     
    $agents[] = "Opera/9.63 (Windows NT 6.0; U; ru) Presto/2.1.1";
     
    $agents[] = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
     
    $agents[] = "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.18) Gecko/20081203 Firefox/2.0.0.18";
     
    $agents[] = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16";
     
    $agents[] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1";
    $ch curl_init();
    curl_setopt ($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_HTTPHEADER$header); 
    curl_setopt ($chCURLOPT_POST1);
    $postString1="js=n&prev=_t&hl=en&ie=UTF-8&text=".urlencode($msg)."&sl=".$sl."&tl=".$tl."&history_state0=&submit=Translate";

    curl_setopt ($chCURLOPT_POSTFIELDS$postString1);
    curl_setopt ($chCURLOPT_COOKIEJAR'cookie.txt');
     
    curl_setopt($chCURLOPT_HEADERfalse);
     
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
     
    curl_setopt($chCURLOPT_USERAGENT$agents[rand(0,(count($agents)-1))]);
    curl_setopt($chCURLOPT_CONNECTTIMEOUT10);
    curl_setopt($chCURLOPT_TIMEOUT10);
    $data curl_exec ($ch);
    flush();
    preg_match('/<\/object><\/div><span id=result\_box class=\"(.*?)\_text\">(.*?)<\/span><\/span><\/div><\/div><div id=gt-res-tools class=g-section/si',$data,$match);



    if(!isset(
    $match[0])){
    return 
    $msg;
    }

    $data$match[2];
    $data=strip_tags($data);
    //echo $data;exit;
    $s=array("<",">","lt;","gt;","#39;","quot;");$r=array("<",">","<",">","'",'"');
    $data=str_replace($s,$r,$data);

    $pattern='/\\\x3d/si';
    $data=preg_replace($pattern,'=',$data);
    $pattern='/\\\r/si';
    $data=preg_replace($pattern,'',$data);
    $data=str_replace('</ ','</',$data);
    $pattern='/\\\x([a-z0-9A-Z]{2,4})/si';
    $data=preg_replace($pattern,'',$data);

    return 
    $data;
    //return $match[1];
    }
    ?>
     
  3. gialappas

    gialappas Regular Member

    Joined:
    Jan 25, 2010
    Messages:
    263
    Likes Received:
    180
    thanks for your reply.

    I need to create a .php file with this code?
     
  4. wickedguy

    wickedguy Supreme Member

    Joined:
    Jul 22, 2009
    Messages:
    1,402
    Likes Received:
    1,379
    Location:
    BHW--> South Africa
    Home Page:

    Of course! :D
     
  5. gialappas

    gialappas Regular Member

    Joined:
    Jan 25, 2010
    Messages:
    263
    Likes Received:
    180
    I found this error:
    Fatal error: Call to undefined function: curl_init() in /home/mhd-01/www.********.it/htdocs/test.php on line 22
     
  6. wickedguy

    wickedguy Supreme Member

    Joined:
    Jul 22, 2009
    Messages:
    1,402
    Likes Received:
    1,379
    Location:
    BHW--> South Africa
    Home Page:
    cURL should be enabled. Ask your host to enable it
     
    • Thanks Thanks x 1
  7. gialappas

    gialappas Regular Member

    Joined:
    Jan 25, 2010
    Messages:
    263
    Likes Received:
    180
    I can't use Curl on my host, there are other solutions?
     
  8. gialappas

    gialappas Regular Member

    Joined:
    Jan 25, 2010
    Messages:
    263
    Likes Received:
    180
    Update: Now I can use CURL in my host.

    But there are a problem:
    I found a blank page!
    There are a error in this script?
     
  9. wickedguy

    wickedguy Supreme Member

    Joined:
    Jul 22, 2009
    Messages:
    1,402
    Likes Received:
    1,379
    Location:
    BHW--> South Africa
    Home Page:
    Where do you get your RSS feed from? I can guess what the problem is. Give me any one of your RSS feeds and I will adapt the script for you
     
  10. gialappas

    gialappas Regular Member

    Joined:
    Jan 25, 2010
    Messages:
    263
    Likes Received:
    180
    Pm sent, thanks for your help
     
  11. caktakim

    caktakim Newbie

    Joined:
    Jan 12, 2010
    Messages:
    3
    Likes Received:
    0
    can you tell me where this script added ?
    thanks
     
  12. quinnsoft

    quinnsoft Newbie

    Joined:
    Apr 1, 2011
    Messages:
    2
    Likes Received:
    0
    I just created a .php file and replace $myRSSfeed='this is the feed'; with my feed. However I just got a blank page. Can you give me a help?
     
  13. quinnsoft

    quinnsoft Newbie

    Joined:
    Apr 1, 2011
    Messages:
    2
    Likes Received:
    0
    Have you fixed the feed translate problem. I have the same problem. Can you help? thanks.