Beispiel #1
0
 public static function getByRow($row)
 {
     $result = null;
     if ($row && $row['mtID']) {
         $result = new Translation($row['context'], $row['msgid'], $row['msgidPlural']);
         $result->mtID = $row['mtID'];
         $result->mtSectionID = $row['mtSectionID'];
         $result->setTranslation($row['msgstr']);
         if (isset($row['comments'])) {
             foreach (explode("\n", $row['comments']) as $comment) {
                 $result->addExtractedComment($comment);
             }
         }
         if ($result->hasPlural() && isset($row['msgstrPlurals'])) {
             foreach (explode("", $row['msgstrPlurals']) as $pluralIndex => $plural) {
                 $result->setPluralTranslation($plural, $pluralIndex);
             }
         }
         if (isset($row['reference'])) {
             foreach (explode("\n", $row['reference']) as $reference) {
                 if ($reference !== '') {
                     $line = null;
                     $p = strrpos($reference, ':');
                     if ($p) {
                         $s = substr($reference, $p + 1);
                         if (preg_match('/^\\d+$/', $s)) {
                             $line = (int) $s;
                             $reference = substr($reference, 0, $p);
                         }
                     }
                     $result->addReference($reference, $line);
                 }
             }
         }
         if (isset($row['flags'])) {
             foreach (explode("\n", $row['flags']) as $flag) {
                 if ($flag !== '') {
                     $result->addFlag($flag);
                 }
             }
         }
     }
     return $result;
 }
Beispiel #2
0
 /**
  * Merge the translations of two translations.
  * 
  * @param Translation $from
  * @param Translation $to
  * @param int         $options
  */
 public static function mergeTranslation(Translation $from, Translation $to, $options = self::DEFAULTS)
 {
     $override = (bool) ($options & self::TRANSLATION_OVERRIDE);
     if (!$to->hasTranslation() || $from->hasTranslation() && $override) {
         $to->setTranslation($from->getTranslation());
     }
     if (!$to->hasPlural() || $from->hasPlural() && $override) {
         $to->setPlural($from->getPlural());
     }
     if (!$to->hasPluralTranslations() || $from->hasPluralTranslations() && $override) {
         $to->setPluralTranslations($from->getPluralTranslations());
     }
 }