Esempio n. 1
0
 public static function addTranslation($event)
 {
     if ($event->category === null) {
         $event->category = '';
         if (Yii::app()->controller->module !== null) {
             $event->category .= Yii::app()->controller->module->id . '.';
         } else {
             $event->category .= 'root.';
         }
         $event->category .= Yii::app()->controller->id . '.' . Yii::app()->controller->action->id;
     }
     $source = SourceMessages::model()->findByAttributes(array('message' => $event->message, 'category' => $event->category));
     //var_dump($event->message,  $event->category);die;
     if ($source === NULL) {
         $source = new SourceMessages();
         $source->category = $event->category;
         $source->message = $event->message;
         $source->save();
     }
     $translation = TranslatedMessages::model()->findByPk(array('id' => $source->id, 'language' => $event->language));
     if ($translation === NULL) {
         $translation = new TranslatedMessages();
         $translation->id = $source->id;
         $translation->language = $event->language;
         $translation->translation = $event->message;
         $translation->save();
     }
 }
 public function actionSaveTranslate()
 {
     $ok = 0;
     $message = 'Your request is invalid';
     if (Yii::app()->request->isAjaxRequest) {
         if (isset($_POST['pk']) && isset($_POST['value']) && isset($_POST['name'])) {
             $model = TranslatedMessages::model()->findByPk(array('id' => intval($_POST['pk']), 'language' => $_POST['name']));
             if ($model) {
                 $model->translation = $_POST['value'];
                 if ($model->save()) {
                     $ok = 1;
                     $message = 'Translation saved';
                 } else {
                     $message = 'Translation NOT saved! Reload page and try again';
                 }
             } else {
                 $message = 'You can not translate source language messages';
             }
         }
     } else {
         $ok = 0;
     }
     echo json_encode(array('ok' => $ok, 'message' => $message));
     Yii::app()->end();
 }