Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Thanked 64 Times in 64 Posts

    google translate (no payed api)

    i was going trough googlt translator's client side code and came up with this:
    PHP Code:
    function google_translate($from$to$text){
    //fake user-agent
    ini_set('user_agent''Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv: Gecko/2008092417 Firefox/3.0.3');
    ini_set('default_charset''utf-8');//set encoding in case it's other than utf-8 (you might need to re-set it afterwords)
    $get_string 'hl=' $from '&tl=' $to '&q=' urlencode($text);
    $data file_get_contents('http://translate.google.com/?' $get_string);
    $DOM = new DOMDocument;
    $items $DOM->getElementById('result_box');

    it's very simple function. instead of using regular API, it takes html document served by google translator, extracts translated words and returns them
    google_translate($source_language, $target_language, $text);
    for example: if you want to translate 'some text' from english to italian, and print result, it would be
    PHP Code:
    echo google_translate('en''it''some text'); 
    i've been looking for decent free translator with api for very long time with no luck, so i've decided to spare you guys some time
    Last edited by patryk; 10-13-2012 at 05:32 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts