public function run($args) { $col = 50; $n = 0; // $listCatalog = array("CatalogContent"); //"CatalogTours", "CatalogInfoCategory", "CatalogToursCategory", "CatalogInfo", "CatalogCity", "CatalogFirms", "CatalogHotels", "CatalogKurorts", "CatalogUmor", "CatalogCountry", "CatalogItems", "CatalogItemsCategory", "CatalogContent", "CatalogFirmsItems", "CatalogFirmsService", "CatalogWork" ); for ($i = 0; $i < sizeof($listCatalog); $i++) { $class = $listCatalog[$i]; $list = $class::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("translate=0")->setLimit($col)->setCache(0)); echo $class . " - " . $n . "( " . sizeof($list) . " )<br/>"; foreach ($list as $model) { $model->translate = 1; if (!$model->save()) { print_r($model->getErrors()); } else { echo $model->id . "<br/>"; $n++; $transModel = TranslateHelper::getTranslateModel($class, $model->id, "en"); // ja en if (!$transModel->id) { @TranslateHelper::setTranslate($model, $transModel, "en"); } } } if (sizeof($list) == $col || $n >= $col) { break; } } }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { Yii::app()->page->title = "Перевод"; if (!empty($_POST["text"])) { $text = trim($_POST["text"]); $lang = trim($_POST["lang"]); $arr = explode("\n", $text); for ($i = 0; $i < sizeof($arr); $i++) { $arr2 = explode("=>", $arr[$i]); $arr2[1] = substr($arr2[1], 0, strlen($arr2[1]) - 2); $value = trim(str_replace('"', "", $arr2[1])); if (!empty($value)) { $value2 = TranslateHelper::translate($value, $lang); //echo $value."<br/>"; $text = str_replace('"' . $value . '",', '"' . $value2 . '",', $text); } } } $this->render("index", array("text" => $text)); }
public static function translate($textIn, $lang = 'en') { $step = 0; $cout = ""; for ($n = 0; $n < strlen($textIn); $n += 800) { $text = TranslateHelper::getLimitText($textIn, 600, $n); $text = str_replace(array("\n", "\r"), "", $text); $file = file_get_contents("http://translate.google.ru/translate_a/t?client=x&text=" . urlencode($text) . "&hl=ru&sl=ru&tl=" . $lang . "&ie=UTF-8&oe=UTF-8"); $res = json_decode($file); if (json_last_error() > 0) { echo "Error: " . json_last_error() . "<br/>"; } $text = ""; for ($i = 0; $i < sizeof($res->sentences); $i++) { $text .= $res->sentences[$i]->trans; } $text = str_replace("< /", "</", $text); $text = str_replace("</ ", "</", $text); $cout .= $text; } return $cout; }
/** * * @param int $iEmailTemplateID * @param array $aSubject * @param array $aBody * @param string $sTo * @author bb <*****@*****.**> * @copyright (c) 2013, bb */ public static function sendmailTranslate($iEmailTemplateID, $aSubject, $aBody, $sTo) { $modelEmailTemplate = new TranslateHelper('EmailTemplates', $iEmailTemplateID); $sSubject = $modelEmailTemplate->get('email_subject'); if (is_array($aSubject)) { foreach ($aSubject as $key => $value) { $sSubject = str_replace($key, $value, $sSubject); } } $sBody = $modelEmailTemplate->get('email_body'); if (is_array($aBody)) { foreach ($aBody as $key => $value) { $sBody = str_replace($key, $value, $sBody); } } $data = array('subject' => $sSubject, 'params' => array('message' => $sBody), 'view' => 'message', 'to' => $sTo, 'from' => Yii::app()->params['autoEmail']); return CmsEmail::mail($data); }