コード例 #1
0
 /**
  * Implements PoWriterInterface::writeItem().
  */
 public function writeItem(PoItem $item) {
   if (is_array($item->getSource())) {
     $item->setSource(implode(L10N_UPDATE_PLURAL_DELIMITER, $item->getSource()));
     $item->setTranslation(implode(L10N_UPDATE_PLURAL_DELIMITER, $item->getTranslation()));
   }
   $context = $item->getContext();
   $this->_items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
 }
コード例 #2
0
ファイル: PoStreamReader.php プロジェクト: biaogebusy/mi
 /**
  * Store the parsed values as a PoItem object.
  */
 public function setItemFromArray($value)
 {
     $plural = FALSE;
     $comments = '';
     $textgroup = 'default';
     if (isset($value['#'])) {
         $comments = $this->shortenComments($value['#']);
         $textgroup = $this->fetchGroupFromComment($comments);
     }
     if (is_array($value['msgstr'])) {
         // Sort plural variants by their form index.
         ksort($value['msgstr']);
         $plural = TRUE;
     }
     $item = new PoItem();
     $item->setContext(isset($value['msgctxt']) ? $value['msgctxt'] : '');
     $item->setSource($value['msgid']);
     $item->setTranslation($value['msgstr']);
     $item->setPlural($plural);
     $item->setComment($comments);
     $item->setLangcode($this->_langcode);
     $item->setTextgroup($textgroup);
     $this->_last_item = $item;
     $this->_context = 'COMMENT';
 }
コード例 #3
0
 /**
  * Implements PoReaderInterface::readItem().
  */
 function readItem() {
   if ($string = $this->readString()) {
     $values = (array)$string;
     $poItem = new PoItem();
     $poItem->setFromArray($values);
     return $poItem;
   }
 }
コード例 #4
0
 /**
  * Imports one string into the database.
  *
  * @param PoItem $item
  *   The item being imported.
  *
  * @return int
  *   The string ID of the existing string modified or the new string added.
  */
 private function importString(PoItem $item)
 {
     // Initialize overwrite options if not set.
     $this->_options['overwrite_options'] += array('not_customized' => FALSE, 'customized' => FALSE);
     $overwrite_options = $this->_options['overwrite_options'];
     $customized = $this->_options['customized'];
     $context = $item->getContext();
     $source = $item->getSource();
     $translation = $item->getTranslation();
     // Look up the source string and any existing translation.
     $strings = $this->storage->getTranslations(array('language' => $this->_langcode, 'source' => $source, 'context' => $context));
     $string = reset($strings);
     if (!empty($translation)) {
         // Skip this string unless it passes a check for dangerous code.
         if (!locale_string_is_safe($translation)) {
             watchdog('l10n_update', 'Import of string "%string" was skipped because of disallowed or malformed HTML.', array('%string' => $translation), WATCHDOG_ERROR);
             $this->_report['skips']++;
             return 0;
         } elseif ($string) {
             $string->setString($translation);
             if ($string->isNew()) {
                 // No translation in this language.
                 $string->setValues(array('language' => $this->_langcode, 'customized' => $customized));
                 $string->save();
                 $this->_report['additions']++;
             } elseif ($overwrite_options[$string->customized ? 'customized' : 'not_customized']) {
                 // Translation exists, only overwrite if instructed.
                 $string->customized = $customized;
                 $string->save();
                 $this->_report['updates']++;
             }
             $this->_report['strings'][] = $string->getId();
             return $string->lid;
         } else {
             // No such source string in the database yet.
             $string = $this->storage->createString(array('source' => $source, 'context' => $context))->save();
             $target = $this->storage->createTranslation(array('lid' => $string->getId(), 'language' => $this->_langcode, 'translation' => $translation, 'customized' => $customized))->save();
             $this->_report['additions']++;
             $this->_report['strings'][] = $string->getId();
             return $string->lid;
         }
     } elseif ($string && !$string->isNew() && $overwrite_options[$string->customized ? 'customized' : 'not_customized']) {
         // Empty translation, remove existing if instructed.
         $string->delete();
         $this->_report['deletes']++;
         $this->_report['strings'][] = $string->lid;
         return $string->lid;
     }
 }
コード例 #5
0
ファイル: Po.php プロジェクト: sydorenkovd/yiiadv
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPoItems()
 {
     return $this->hasMany(PoItem::className(), ['po_id' => 'id']);
 }