Esempio n. 1
0
 /**
  * Merge the extracted comments of two translations.
  * 
  * @param Translation $from
  * @param Translation $to
  * @param int         $options
  */
 public static function mergeExtractedComments(Translation $from, Translation $to, $options = self::DEFAULTS)
 {
     if ($options & self::EXTRACTED_COMMENTS_THEIRS) {
         $to->deleteExtractedComments();
     }
     if (!($options & self::EXTRACTED_COMMENTS_OURS)) {
         foreach ($from->getExtractedComments() as $comment) {
             $to->addExtractedComment($comment);
         }
     }
 }
Esempio n. 2
0
 /**
  * Merges this translation with other translation
  *
  * @param Translation  $translation The translation to merge with
  * @param integer|null $method      One or various Translations::MERGE_* constants to define how to merge the translations
  */
 public function mergeWith(Translation $translation, $method = null)
 {
     if ($method === null) {
         $method = Translations::$mergeDefault;
     }
     if (!$this->hasTranslation()) {
         $this->setTranslation($translation->getTranslation());
     }
     if ($method & Translations::MERGE_PLURAL && !$this->hasPlural()) {
         $this->setPlural($translation->getPlural());
     }
     if ($this->hasPlural() && !$this->hasPluralTranslation() && $translation->hasPluralTranslation()) {
         $this->pluralTranslation = $translation->getPluralTranslation();
     }
     if ($method & Translations::MERGE_REFERENCES) {
         foreach ($translation->getReferences() as $reference) {
             $this->addReference($reference[0], $reference[1]);
         }
     }
     if ($method & Translations::MERGE_COMMENTS) {
         $this->comments = array_values(array_unique(array_merge($translation->getComments(), $this->comments)));
         $this->extractedComments = array_values(array_unique(array_merge($translation->getExtractedComments(), $this->extractedComments)));
         $this->flags = array_values(array_unique(array_merge($translation->getFlags(), $this->flags)));
     }
 }