Exemplo n.º 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
     $source = SourceMessage::model()->find('message=:message AND category=:category', array(':message' => $event->message, ':category' => $event->category));
     // If we didn't find one then add it
     if (!$source) {
         // Add it
         $model = new SourceMessage();
         $model->category = $event->category;
         $model->message = $event->message;
         $model->save();
         $lastID = Yii::app()->db->lastInsertID;
     }
     /*if( $event->language != Yii::app()->sourceLanguage )
     		{
     			// Do the same thing with the messages	
     			$translation = Message::model()->find('language=:language AND translation=:translation', array(':language'=>$event->language, ':translation'=>$event->message));	
     		
     			// If we didn't find one then add it
     			if( !$translation )
     			{
     				$source = SourceMessage::model()->find('message=:message AND category=:category', array(':message'=>$event->message, ':category'=>$event->category));
     				
     				// Add it
     				$model = new Message;
     				
     				$model->id = $source->id;
     				$model->language = $event->language;
     				$model->translation = $event->message;
     				$model->save();
     			}
     		}*/
 }
Exemplo n.º 2
0
 /**
  * Check if the category-message combination exists
  */
 public function checkExisting()
 {
     $exists = SourceMessage::model()->find('category=LOWER(:category) AND message=LOWER(:message)', array(':category' => strtolower($this->category), ':message' => strtolower($this->message)));
     if ($exists) {
         $this->addError('message', at('That message already exists under that category.'));
     }
 }
 /**
  * Executes any command triggered on the admin page.
  */
 protected function processAdminCommand()
 {
     //print_r($_POST);die();
     if (isset($_POST['Save'])) {
         //check that ALL translations are in this translation..
         $sources = SourceMessage::model()->findAll();
         foreach ($sources as $source) {
             $existstest = Message::model()->find(array('condition' => 'language=\'' . $_POST['langcode'] . '\' AND id=' . $source->id));
             if ($existstest === null) {
                 $trans = new Message();
                 $trans->id = $source->id;
                 $trans->translation = '-dirty-' . $source->message;
                 $trans->language = $model->language;
                 $trans->save();
             } else {
                 if (isset($_POST['Message'][$source->id])) {
                 }
             }
         }
         //do the actual reading of data from the form
         $messages = Message::model()->findAll(array('condition' => 'language=\'' . $_POST['langcode'] . '\''));
         foreach ($messages as $message) {
             if (isset($_POST['Message'][$message->id])) {
                 $message->attributes = $_POST['Message'][$message->id];
                 $message->save();
             }
             //delete no longer used posts.
             if (!isset($message->source)) {
                 $message->delete();
             }
         }
     } elseif (isset($_POST['Delete'])) {
         SourceMessage::model()->dbConnection->createCommand("DELETE FROM Message WHERE language='" . $_POST['langcode'] . "'")->execute();
         $foundOption = Options::model()->find('name=:name AND userId=:id AND companyId=:compid', array(':name' => "Language.Version." . $_POST['langcode'], ':id' => 0, ':compid' => 0));
         if ($foundOption !== null) {
             $foundOption->delete();
         }
         unset($_POST['langcode']);
     } elseif (isset($_POST['Export'])) {
         $dom = new DomDocument();
         $dom->encoding = 'utf-8';
         $root = $dom->createElement("lazy8webportlang");
         $root->setAttribute("version", "1.00");
         $language = $dom->createElement("language");
         $language->setAttribute("langcode", $_POST['langcode']);
         $exportLang = Message::model()->with('source')->findAll(array('condition' => "language='" . $_POST['langcode'] . "'", 'together' => true, 'order' => "message"));
         foreach ($exportLang as $export) {
             if (isset($export->source)) {
                 $message = $dom->createElement("message");
                 $message->setAttribute("category", $export->source->category);
                 $message->setAttribute("key", html_entity_decode($export->source->message));
                 $this->appendTextNode($dom, $message, "translation", $export->translation);
                 $language->appendChild($message);
             }
         }
         $root->appendChild($language);
         $dom->appendChild($root);
         $dom->formatOutput = true;
         $thefile = $dom->saveXML();
         // set headers
         header("Pragma: no-cache");
         header("Expires: 0");
         header("Content-Description: File Transfer");
         header("Content-Type: text/xml");
         header("Content-Disposition: attachment; filename=\"lazy8webExport.Language." . $_POST['langcode'] . "." . date('Y-m-d_H.i.s') . ".xml\"");
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . strlen($thefile));
         //flush();
         print $thefile;
         return;
         //we may not send any more to the screen or it will mess up the file we just sent!
     } elseif (isset($_POST['langcode'])) {
         $this->editinglanguage = $_POST['langcode'];
     }
 }
Exemplo n.º 4
0
 /**
  * Revert a string to it's original form
  */
 public function actionRevert()
 {
     // Check Access
     checkAccessThrowException('op_language_translate');
     $id = getRParam('id', 0);
     $string = getRParam('string', 0);
     // Check if it exists
     $model = Language::model()->findByPk($id);
     if (!$model) {
         ferror(at('That language was not found.'));
         $this->redirect(array('index'));
     }
     // Grab the string and source
     $source = SourceMessage::model()->findByPk($string);
     $stringdata = Message::model()->find('language_id=:lang AND id=:id', array(':id' => $string, ':lang' => $id));
     if (!$source || !$stringdata) {
         ferror(at('That language string was not found.'));
         $this->redirect(array('index'));
     }
     // Update the stringdata based on the soruce
     Message::model()->updateAll(array('translation' => $source->message), 'language_id=:lang AND id=:id', array(':id' => $string, ':lang' => $id));
     fok(at('String Reverted.'));
     $this->redirect(array('language/view', 'id' => $id));
 }
Exemplo n.º 5
0
 /**
  * Get number of strings that were already translated
  */
 public function getStringTranslationDifference($id)
 {
     $origs = SourceMessage::model()->findAll();
     $translated = 0;
     if (count($origs)) {
         foreach ($origs as $orig) {
             // Grab the translation from the messages table
             $message = Message::model()->find('language_id=:lang AND id=:id', array(':lang' => $id, ':id' => $orig->id));
             if ($message) {
                 if ($message->translation != $orig->message) {
                     $translated++;
                 }
             }
         }
     }
     return $translated;
 }
 public function afterSave($event)
 {
     // do nothing if we have nothing to save
     if (empty($this->dirtyAttributes)) {
         return true;
     }
     // format into a structured array of translations to save
     $sourceMessages = array();
     foreach ($this->dirtyAttributes as $keyWithSuffix => $value) {
         $originalAttribute = $this->getOriginalAttribute($keyWithSuffix);
         $language = $this->getLanguageSuffix($keyWithSuffix);
         // Do not save translations in sourceLanguage
         if ($language == Yii::app()->sourceLanguage) {
             continue;
         }
         $sourceMessage = $this->getSourceMessage($originalAttribute);
         if (!isset($sourceMessages[md5($sourceMessage)])) {
             $sourceMessages[md5($sourceMessage)] = array('message' => $sourceMessage, 'category' => $this->getCategory($originalAttribute), 'translations' => array());
         }
         $sourceMessages[md5($sourceMessage)]['translations'][] = array('language' => $language, 'translation' => $value);
     }
     // do nothing if we have nothing to save
     if (empty($sourceMessages)) {
         return true;
     }
     // find a suitable method of saving
     $component = Yii::app()->{$this->messageSourceComponent};
     if (method_exists($component, 'saveTranslations')) {
         $component->saveTranslations($sourceMessages);
         return $this->afterSavingTranslations();
     }
     if ($component instanceof CPhpMessageSource) {
         throw new CException("Cannot save translations with CPhpMessageSource");
     }
     if ($component instanceof CDbMessageSource) {
         // save the translations
         foreach ($sourceMessages as $sourceMessage) {
             $attributes = array('category' => $sourceMessage['category'], 'message' => $sourceMessage['message']);
             if (($model = SourceMessage::model()->find('message=:message AND category=:category', $attributes)) === null) {
                 $model = new SourceMessage();
                 $model->attributes = $attributes;
                 if (!$model->save()) {
                     throw new CException('Attribute source message ' . $attributes['category'] . ' - ' . $attributes['message'] . ' could not be added to the SourceMessage table. Errors: ' . print_r($model->errors, true));
                 }
             }
             if ($model->id) {
                 foreach ($sourceMessage['translations'] as $translation) {
                     $attributes = array('id' => $model->id, 'language' => $translation['language']);
                     if (($messageModel = Message::model()->find('id=:id AND language=:language', $attributes)) === null) {
                         $messageModel = new Message();
                     }
                     $messageModel->id = $attributes['id'];
                     $messageModel->language = $attributes['language'];
                     $messageModel->translation = $translation['translation'];
                     if (!$messageModel->save()) {
                         throw new CException('Attribute message ' . $attributes['category'] . ' - ' . $attributes['message'] . ' - ' . $language . ' - ' . $value . ' could not be saved to the Message table. Errors: ' . print_r($messageModel->errors, true));
                     }
                 }
             }
         }
         return $this->afterSavingTranslations();
     }
     throw new CException("Cannot save translations with " . get_class(Yii::app()->messages));
 }
Exemplo n.º 7
0
?>
							<div class="clear"></div>
						</td>
					</tr>
				</tfoot>
				<tbody>
					
					<?php 
if (count($strings)) {
    ?>
						
						<?php 
    foreach ($strings as $string) {
        ?>
							<?php 
        $orig = SourceMessage::model()->findByPk($string->id);
        ?>
							<tr>
								<td><?php 
        echo $string->id;
        ?>
</td>
								<td style='vertical-align:top;'><?php 
        echo CHtml::encode($orig->message);
        ?>
 <br /><small>(<?php 
        echo $orig->category;
        ?>
)</small></td>
								<td><?php 
        echo CHtml::textArea("strings[{$string->id}]", $string->translation, array('rows' => 10, 'cols' => 50));