Example #1
0
<?php

require "GTranslate.php";
/**
* Example using RequestHTTP
*/
$translate_string = "Das ist wunderschön";
try {
    $gt = new Gtranslate();
    echo "[HTTP] Translating [{$translate_string}] German to English => " . $gt->german_to_english($translate_string) . "<br/>";
    /**
     * Lets switch the request type to CURL
     */
    $gt->setRequestType('curl');
    echo "[CURL] Translating [{$translate_string}] German to English => " . $gt->german_to_english($translate_string) . "<br/>";
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
/**
 * Calls google to get longitude and latitude for location
 * This could be changed to use other mapping servcies. The file "map.js" would also have to be changed.
 * @param object $data Information get added to object
 * @return bool Whether call was successful
 */
function map_get_latlong(&$data, $map)
{
    global $CFG;
    // Your Google Maps API key
    // Desired address
    $provider = map_get_map_provider($map);
    //$address = "$data->city,+$data->state,+$data->country";
    // Translate Hebrew City name to English. will not work 100% of the time (nadavkav)
    try {
        $gt = new Gtranslate();
        $heCityName = $gt->hebrew_to_english($data->city);
    } catch (GTranslateException $ge) {
        echo $ge->getMessage();
    }
    $address = urlencode($heCityName) . "&country={$data->country}";
    // Encode Hebrew translated to "Englished" city name (nadavkav)
    if (isset($data->address)) {
        $address = str_replace(" ", "+", ",{$data->address}+" . $address);
    }
    if ($provider == "google") {
        $address = urlencode($address);
        return map_get_latlong_google($data, $address);
    } else {
        return map_get_latlong_geonames($data, $address);
    }
}
Example #3
0
 /**
  * Translate the content of a file with Google Translate API.
  *
  * @return The automatic translation.
  */
 public function translate()
 {
     // We must check if the file exist.
     // For example, when we start a translation, save it, and then open it from work in progress module, the path don't exist and we must use the fallback path for translation
     $originalContent = is_file($this->full_path) ? file_get_contents($this->full_path) : file_get_contents($this->full_path_fallback);
     // We search for new line caracters and mark it ! (Google API delete new line)
     $originalContent = str_replace("\n", "[@]", $originalContent);
     $lang = AccountManager::getInstance()->vcsLang;
     $translation = false;
     $gt = new Gtranslate();
     $gt->setRequestType('curl');
     $translation = $gt->translate('en', $lang, $originalContent);
     // Replace new line mark
     $translation = str_replace("[@]", "\n", $translation);
     // Few substitutions
     $translation = str_replace("&amp;", "&", $translation);
     $translation = str_replace("&amp;  ", "&", $translation);
     $translation = str_replace("&#39;", "'", $translation);
     $translation = str_replace("&quot;", '"', $translation);
     $translation = str_replace("&lt;", '<', $translation);
     $translation = str_replace("&gt;", '>', $translation);
     // CLeanUp entities. Google return it like this : & Reftitle.parameters;. We convert it like this : &reftitle.parameters;
     $translation = preg_replace_callback("/(&)\\s(.)(.[^;]*?)(;)/s", create_function('$matches', 'return $matches[1].strtolower($matches[2]).$matches[3].$matches[4];'), $translation);
     // We remove extra space after :: operator
     $translation = preg_replace("/(\\w+)(::)(\\s)(\\w+)/s", "\$1\$2\$4", $translation);
     // We delete space into tab like this </ b>
     $translation = preg_replace("/(<\\/\\s(\\w+[^>]*)>)/s", "</\$2>", $translation);
     // We delete space just after an open tag, and just before a close tag, like this <b> foo </b>
     $translation = preg_replace("/(<(\\w+[^>]*)>)(\\s?)(.[^>]*?)(\\s?)(<\\/(\\2)>)/s", "<\$2>\$4</\$7>", $translation);
     return $translation;
 }
 /**
  * Get the translation from a given string using Google Translate API
  */
 public function getGGTranslation()
 {
     if (!AccountManager::getInstance()->isLogged()) {
         return JsonResponseBuilder::failure();
     }
     $str = $this->getRequestVariable('str');
     $lang = AccountManager::getInstance()->vcsLang;
     $translation = false;
     $str = str_replace("\n", "[@]", $str);
     $gt = new Gtranslate();
     $gt->setRequestType('curl');
     $translation = $gt->translate('en', $lang, $str);
     // Replace new line mark
     $translation = str_replace("[@]", "<br>", $translation);
     // Few substitutions
     $translation = str_replace("&amp;", "&", $translation);
     $translation = str_replace("&amp;  ", "&", $translation);
     $translation = str_replace("&#39;", "'", $translation);
     $translation = str_replace("&quot;", '"', $translation);
     $translation = str_replace("&lt;", '<', $translation);
     $translation = str_replace("&gt;", '>', $translation);
     return JsonResponseBuilder::success(array('translation' => $translation));
 }
Example #5
0
 protected function traduction_google_v1($mot_a_traduire)
 {
     $translate_string = "Das ist wunderschön";
     try {
         $gt = new Gtranslate();
         $gt->setRequestType('curl');
         $function = "en_to_" . substr($this->language->getSelectedValue(), -2, 2);
         return $gt->{$function}($mot_a_traduire);
     } catch (GTranslateException $ge) {
         return "";
     }
 }
Example #6
0
 function google_translage($code1, $code2, $content)
 {
     require_once dirname(__FILE__) . '/../includes/lib/GTranslate/GTranslate.php';
     try {
         $code1 = strtolower($code1);
         $code2 = strtolower($code2);
         if ($code1 == 'cn') {
             $code1 = 'zh-cn';
         }
         if ($code2 == 'cn') {
             $code2 = 'zh-cn';
         }
         $language_list = parse_ini_file(dirname(__FILE__) . '/../includes/lib/GTranslate/languages.ini');
         $language_list = array_map("strtolower", $language_list);
         $language_list2 = array_map("strtolower", array_flip($language_list));
         //
         $language_list_v = array_map("strtolower", array_values($language_list));
         $language_list_k = array_map("strtolower", array_keys($language_list));
         if (!isset($language_list2[$code1])) {
             return 'Error language code:' . $code1;
         }
         if (!isset($language_list2[$code2])) {
             return 'Error language code:' . $code2;
         }
         $fromlanguage = $language_list2[$code1];
         $targetlanguage = $language_list2[$code2];
         //print_r($targetlanguage);
         $gt = new Gtranslate();
         $gt->setRequestType('curl');
         $function = $fromlanguage . '_to_' . $targetlanguage;
         $text = $gt->{$function}($content);
         echo $function . "\r\n";
         $text = iconv('UTF-8', 'GBK', $text);
         return $text;
     } catch (GTranslateException $ge) {
         return $ge->getMessage();
     }
 }
Example #7
0
<?php 
echo "test";
require "GTranslate.php";
/**
* Example using RequestHTTP
*/
$translate_string = "Das ist wundersch?n";
$test = "우리";
try {
    $gt = new Gtranslate();
    echo "[HTTP] Translating Korean to English => " . $gt->ko_to_en($test) . "\n";
    echo $gt->it_to_en("Ciao mondo");
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
Example #8
0
<?php

require "GTranslate.php";
$translate_string = "<strong>Das</strong> ist <font color=\"red\">wunderschön</font>";
try {
    $gt = new Gtranslate();
    $gt->setRequestType('curl');
    echo "Translating [{$translate_string}] German to English => " . $gt->german_to_english($translate_string) . "<br/>";
    echo "Translating [{$translate_string}] German to English => " . $gt->german_to_chinese($translate_string) . "<br/>";
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
<?php

require "GTranslate.php";
error_reporting(E_ALL);
ini_set('display_error', 1);
/**
* Example using RequestHTTP
*/
$translate_string = "Das ist wunderschön";
try {
    $gt = new Gtranslate();
    echo "[HTTP] Translating [{$translate_string}] German to English => " . $gt->german_to_english($translate_string) . "\n";
    /**
     * Lets switch the request type to CURL
     */
    $gt->setRequestType('curl');
    echo "[CURL] Translating [{$translate_string}] German to English => " . $gt->german_to_english($translate_string) . "\n";
    $translate_string = 'hello';
    echo "[CURL] Translating [{$translate_string}] English to German=> " . $gt->english_to_german($translate_string) . "\n";
    echo "[CURL] Translating [{$translate_string}] English to Portuguese=> " . $gt->english_to_portuguese($translate_string) . "\n";
    echo "[CURL] Translating [{$translate_string}] English to Italian=> " . $gt->english_to_italian($translate_string) . "\n";
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
Example #10
0
 * @link		http://azhari.harahap.us/2011/04/howto-turn-kalkun-into-awesome-mobile-dictionary-app/
 */
// ------------------------------------------------------------------------
define('GTranslate_path', "/path/to/gtranslate-api-php/GTranslate.php");
define('Kalkun_API_path', "/path/to/kalkun/scripts/cURL/Kalkun_API.php");
$arg_list = $_SERVER['argv'];
$arg_count = count($arg_list);
if ($arg_count > 2) {
    $phone_number = $arg_list[1];
    unset($arg_list[0]);
    unset($arg_list[1]);
    // build the text
    $translate_string = implode(' ', $arg_list);
    require GTranslate_path;
    try {
        $gt = new Gtranslate();
        $gt->setRequestType('curl');
        $gt->setLanguageFile('languages.ini');
        $translated_string = $gt->indonesian_to_english($translate_string);
        // Send translated text by SMS
        include_once Kalkun_API_path;
        $config['base_url'] = "http://localhost/kalkun/index.php/";
        $config['session_file'] = "/tmp/cookies.txt";
        $config['username'] = "******";
        $config['password'] = "******";
        $config['phone_number'] = $phone_number;
        $config['message'] = $translated_string;
        $sms = new Kalkun_API($config);
        $sms->run();
    } catch (GTranslateException $ge) {
        echo $ge->getMessage();
Example #11
0
<?php

require "googletranslate/GTranslate.php";
try {
    $gt = new Gtranslate();
    echo "Translating [Hello World] from English to German => " . $gt->english_to_german("hello world") . "<br/>";
    echo "Translating [Ciao mondo] Italian to English => " . $gt->it_to_en("Ciao mondo") . "<br/>";
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
Example #12
0
<?php

echo "test";
require "GTranslate.php";
/**
* Example using RequestHTTP
*/
$translate_string = "Das ist wundersch?n";
$test = "³ª";
try {
    $gt = new Gtranslate();
    echo "[HTTP] Translating [{$translate_string}] German to English => " . $gt->german_to_english($translate_string) . "\n";
    $gt = new Gtranslate();
    echo "[HTTP] Translating Korean to English => " . $gt->ko_to_eng("³ª") . "\n";
    echo "zz";
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
<?php

include_once '../init.php';
include_once LIB_ROOT . 'third/GTranslate/GTranslate.php';
error_reporting(E_ALL);
ini_set('display_error', 1);
/**
 * Example using RequestHTTP
 */
$translate_string = "在這不自然的世界上,你應得躲避她像你躲避青草裡一條美麗的花蛇!";
try {
    $gt = new Gtranslate();
    $gt->setApiKey("ABQIAAAAqSHtOYfZQAu5HgvVgxccORQFkJYm3b4tkuBKzPIo19dX7oqslBRx_e7WnsquFW-YWXmMt_DSzyJnmw");
    echo "[HTTP] Translating [{$translate_string}] German to English => " . $gt->CHINESE_TRADITIONAL_to_english($translate_string) . "\n";
    /**
     * Lets switch the request type to CURL
     */
    $gt->setRequestType('curl');
    echo "[CURL] Translating [{$translate_string}] German to English => " . $gt->CHINESE_TRADITIONAL_to_CHINESE_SIMPLIFIED($translate_string) . "\n";
    $translate_string = 'hello';
    echo "[CURL] Translating [{$translate_string}] English to German=> " . $gt->english_to_german($translate_string) . "\n";
    echo "[CURL] Translating [{$translate_string}] English to Portuguese=> " . $gt->english_to_portuguese($translate_string) . "\n";
    echo "[CURL] Translating [{$translate_string}] English to Italian=> " . $gt->english_to_CHINESE_SIMPLIFIED($translate_string) . "\n";
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
function gtranslate_text_translate($text, $lang_from = 'en', $lang_to = 'ru')
{
    global $gt, $l_func, $settings, $seftranslate_error;
    //DBQuery
    $database =& JFactory::getDBO();
    $ret_value = $text;
    if (isset($GLOBALS['gt'])) {
        try {
            $ret_value = $gt->{$l_func}($text);
            $ret_value = html_entity_decode($ret_value[0]->translatedText, ENT_NOQUOTES, 'UTF-8');
        } catch (Exception $e) {
            if ($settings['debug']) {
                throw $e;
                exit;
            } else {
                $seftranslate_error = true;
                return $ret_value;
            }
        }
    } else {
        $gt = new Gtranslate();
        if (!empty($settings['api_google_translate_key'])) {
            //$gt->setApiKey('ABQIAAAARBki4JWk0Cwz-v6GlQ90wBRTxlZd-7gfuqQumodWhI9M82S_fRQ5OJFZp4v4oNXri4eZjoah2n4--w');
            $gt->setApiKey($settings['api_google_translate_key']);
        }
        if ($settings['userip']) {
            $gt->setUserIp($_SERVER['REMOTE_ADDR']);
        }
        $gt->setRequestType('curl');
        $gt->setApiVersion(2);
        $gt->setUrl('https://www.googleapis.com/language/translate/v2');
        $lang_list = parse_ini_file(JPATH_SITE . '/components/com_seftranslate/languages.ini');
        $lang_from2 = array_search($lang_from, $lang_list);
        $lang_to2 = array_search($lang_to, $lang_list);
        $l_func = $lang_from2 . "_to_" . $lang_to2;
        $GLOBALS['gt'] = $gt;
        $GLOBALS['l_func'] = $l_func;
        try {
            $ret_value = $gt->{$l_func}($text);
            $ret_value = html_entity_decode($ret_value[0]->translatedText, ENT_NOQUOTES, 'UTF-8');
        } catch (Exception $e) {
            if ($settings['debug']) {
                throw $e;
                exit;
            } else {
                $seftranslate_error = true;
                return $ret_value;
            }
        }
    }
    if (trim($ret_value) == "") {
        return $ret_value;
    }
    //save to database
    $efentity = new mosSefentity($database);
    $efentity->hash = md5($text);
    $efentity->entity_text = $ret_value;
    $efentity->lang_from = $lang_from;
    $efentity->lang_to = $lang_to;
    $efentity->hits = 1;
    $efentity->date = date("Y-m-d H:i:s");
    $efentity->checkin();
    $efentity->store();
    return $ret_value;
}
Example #15
0
	public function PrintMovie()
	{
		//google translate
		$gt = new Gtranslate;

		foreach($this->result as $value)
		{
			echo '<item>';
			if($value->title != '')
			{
				echo '<title>'.$gt->ko_to_en($value->title).'</title>';
			}
			else
			{
				echo '<title></title>';
			}

			echo '<thumbnail>'.$value->thumbnail.'</thumbnail>';

			if($value->director != '')
			{
				echo '<director>'.$gt->ko_to_en($value->director).'</director>';
			}
			else
			{
				echo '<director></director>';
			}

			if($value->year != '')
			{
				echo '<year>'.$gt->ko_to_en($value->year).'</year>';
			}
			else
			{
				echo '<year></year>';
			}

			echo '<actor>'.$gt->ko_to_en($value->actor).'</actor>';
			echo '<nation>'.$gt->ko_to_en($value->nation).'</nation>';
			echo '<genre>'.$gt->ko_to_en($value->genre).'</genre>';
			echo '<open>'.$gt->ko_to_en($value->open).'</open>';
			echo '<grade>'.$gt->ko_to_en($value->grade).'</grade>';
			echo '<story></story>';

//			echo '<grade1></grade1>';
//			echo '<grade2></grade2>';
//			echo '<grade3></grade3>';
			echo '<story>'.$gt->ko_to_en($value->story).'</story>';

			echo '<grade1>'.$gt->ko_to_en($value->grade1).'</grade1>';
			echo '<grade2>'.$value->grade2.'</grade2>';
			echo '<grade3>'.$value->grade3.'</grade3>';
			echo '<homepage>'.$value->homepage.'</homepage>';
			echo '</item>';
		}
	}
Example #16
0
<?
//
require("GTranslate.php");
//google translate
$gt = new Gtranslate;


//Daum Movie
//set request address
$userkey = '0a9768d760b4efd11e5a9cad51c22f48bffba360';
$search = $_GET['search'];

$request = 'http://apis.daum.net/contents/movie?output=rss&apikey='.$userkey.'&q='.urlencode($search);


//get response(get source)
$response = file_get_contents($request);
$phpobject = simplexml_load_string($response);
if ($phpobject === false) {
	die('Parsing failed');
}

// Output the data
// SimpleXML returns the data as a SimpleXML object
//get channel -> item

$channel = $phpobject->channel;

if(count($channel->item) == 0)
{
	die('<item><title>검색 결과가 없습니다.</title><thumbnail></thumbnail><director></director><homepage></homepage></item>');