Exemplo n.º 1
0
 /**
  * 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));
 }
Exemplo n.º 2
0
 public static function setTranslate($model, $transModel, $lang = "en")
 {
     $lA = explode("-", $lang);
     $lang = $lA[0];
     $name = TranslateHelper::translate($model->name, $lang);
     if (property_exists($model, "description")) {
         if ($model->description) {
             $text = TranslateHelper::translate($model->description, $lang);
         } else {
             $text = "";
         }
     }
     $text = str_replace(array("< p", "< div"), array("<p", "<div"), $text);
     $requiredFields = $model->getSafeAtributes();
     for ($i = 0; $i < sizeof($requiredFields); $i++) {
         $field = trim($requiredFields[$i]);
         $transModel->{$field} = $model->{$field};
     }
     $transModel->id = $model->id;
     $transModel->name = $name;
     if (property_exists($transModel, "location")) {
         if ($model->location) {
             $transModel->location = TranslateHelper::translate($model->location, $lang);
         }
     }
     if (property_exists($transModel, "address")) {
         if ($model->address) {
             $transModel->address = TranslateHelper::translate($model->address, $lang);
         }
     }
     if (property_exists($model, "description")) {
         $transModel->description = $text;
     }
     if (!$transModel->save()) {
         print_r($transModel->getErrors());
     } elseif (property_exists($transModel, "slug")) {
         SiteHelper::getSlug($transModel);
     }
 }