Пример #1
0
 /**
  * Add missing translations to the source table and 
  * If we are using a different translation then the original one
  * Then add the same message to the translation table.
  */
 public static function load($event)
 {
     // Load the messages
     $objSource = Stringsource::model()->find('message=:message AND category=:category', array(':message' => $event->message, ':category' => $event->category));
     // If we didn't find one then add it
     if (!$objSource) {
         // Add it
         $objSource = new Stringsource();
         $objSource->category = $event->category;
         $objSource->message = $event->message;
         $objSource->save();
         $lastID = Yii::app()->db->lastInsertID;
     }
     if ($event->language != Yii::app()->sourceLanguage) {
         // Do the same thing with the messages
         $objTranslate = Stringtranslate::model()->find('language=:language AND id=:id', array(':language' => $event->language, ':id' => $objSource->id));
         // If we didn't find one then add it
         if (!$objTranslate) {
             // Add it
             $objTranslate = new Stringtranslate();
             $objTranslate->id = $objSource->id;
             $objTranslate->language = $event->language;
             $objTranslate->translation = $event->message;
             $objTranslate->save();
         }
     }
 }
Пример #2
0
 public function getTranslated($dest, $id)
 {
     $model = Stringtranslate::model()->findByAttributes(array('id' => $id, 'language' => $dest));
     if ($model) {
         return $model->translation;
     } else {
         return "";
     }
 }
 /**
  * Customer lookup and edit
  */
 public function actionTranslate()
 {
     //What language are we translating
     $strDestLang = Yii::app()->getRequest()->getQuery('dest');
     $strCategory = Yii::app()->getRequest()->getQuery('category');
     if (empty($strCategory)) {
         $strCategory = "checkout";
     }
     if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) {
         $pk = Yii::app()->getRequest()->getPost('pk');
         $name = Yii::app()->getRequest()->getPost('name');
         $value = Yii::app()->getRequest()->getPost('value');
         $string = Stringtranslate::model()->findByAttributes(array('language' => $strDestLang, 'id' => $pk));
         if (!$string) {
             $string = new Stringtranslate();
             $string->id = $pk;
             $string->language = $strDestLang;
         }
         $string->translation = $value;
         $string->save();
         echo "success";
     } else {
         $model = new Stringsource();
         if (isset($_GET['q'])) {
             $model->string = $_GET['q'];
         }
         //we actually use this variable to search in several fields
         $model->dest = $strDestLang;
         $model->category = $strCategory;
         $this->render("translate", array('model' => $model));
     }
 }