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; }