Пример #1
0
 /**
  * Adds a TranslationUnit instance to the file. It is appenned at the end of
  * collection.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  TranslationUnit translationUnit
  * @return mixed
  */
 public function addTranslationUnit(tao_helpers_translation_TranslationUnit $translationUnit)
 {
     // If the translation unit exists, we replace the target with the new one if it exists.
     foreach ($this->getTranslationUnits() as $tu) {
         if ($tu->getSource() == $translationUnit->getSource()) {
             // If we are here, it means that this TU is being overriden by
             // another one having the same source...
             //
             // Let's make sure we don't override the existing one with an empty target!
             if ($translationUnit->getTarget() !== '') {
                 $tu->setTarget($translationUnit->getTarget());
                 $tu->setAnnotations($translationUnit->getAnnotations());
             }
             return;
         }
     }
     // If we are here, it means that this TU does not exist.
     $translationUnit->setSourceLanguage($this->getSourceLanguage());
     $translationUnit->setTargetLanguage($this->getTargetLanguage());
     array_push($this->translationUnits, $translationUnit);
 }
 /**
  * Short description of method getTranslationsInFile
  *
  * @access private
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  string filePath
  * @return mixed
  */
 private function getTranslationsInFile($filePath)
 {
     // File extension ?
     $extOk = false;
     foreach ($this->getFileTypes() as $exp) {
         if (@preg_match("/\\.{$exp}\$/", $filePath)) {
             $extOk = true;
             break;
         }
     }
     if ($extOk) {
         // We read the file.
         $lines = file($filePath);
         foreach ($lines as $line) {
             $strings = array();
             $patternMatch1 = array();
             $patternMatch2 = array();
             preg_match_all("/__\\(['\"](.*?)['\"]\\)/u", $line, $patternMatch1);
             preg_match_all("/\\{\\{__ ['\"](.*?)['\"]\\}\\}/u", $line, $patternMatch2);
             if (!empty($patternMatch1[1])) {
                 $strings = $patternMatch1[1];
             }
             if (!empty($patternMatch2[1])) {
                 $strings = array_merge($strings, $patternMatch2[1]);
             }
             //preg_match_all("/__(\(| )+['\"](.*?)['\"](\))?/u", $line, $string);
             //lookup for __('to translate') or __ 'to translate'
             //    preg_match_all("/__(\(| )+(('(.*?)')|(\"(.*?)\"))(\))?/u", $line, $string);
             foreach ($strings as $s) {
                 $tu = new tao_helpers_translation_TranslationUnit();
                 $tu->setSource(tao_helpers_translation_POUtils::sanitize($s));
                 $tus = $this->getTranslationUnits();
                 $found = false;
                 // We must add the string as a new TranslationUnit only
                 // if a similiar source does not exist.
                 foreach ($tus as $t) {
                     if ($tu->getSource() == $t->getSource()) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     array_push($tus, $tu);
                     $this->setTranslationUnits($tus);
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Adds a TranslationUnit instance to the file. It is appenned at the end of
  * collection.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param tao_helpers_translation_TranslationUnit $translationUnit
  * @return mixed
  */
 public function addTranslationUnit(tao_helpers_translation_TranslationUnit $translationUnit)
 {
     // If the translation unit exists, we replace the target with the new one if it exists.
     // also now we take care about context
     /** @var tao_helpers_translation_TranslationUnit $tu */
     foreach ($this->getTranslationUnits() as $tu) {
         if ($tu->getSource() == $translationUnit->getSource() && (!$translationUnit->getContext() || $tu->getContext() == $translationUnit->getContext())) {
             $tu->setTarget($translationUnit->getTarget());
             $tu->setAnnotations($translationUnit->getAnnotations());
             return;
         }
     }
     // If we are here, it means that this TU does not exist.
     $translationUnit->setSourceLanguage($this->getSourceLanguage());
     $translationUnit->setTargetLanguage($this->getTargetLanguage());
     $tus = $this->getTranslationUnits();
     array_push($tus, $translationUnit);
     $this->setTranslationUnits($tus);
 }
Пример #4
0
 /**
  * Short description of method hasSameTranslationUnitSource
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  TranslationUnit translationUnit
  * @return boolean
  */
 public function hasSameTranslationUnitSource(tao_helpers_translation_TranslationUnit $translationUnit)
 {
     $returnValue = (bool) false;
     $returnValue = $this->getSource() == $translationUnit->getSource();
     return (bool) $returnValue;
 }
 /**
  * Short description of method getTranslationsInFile
  *
  * @access private
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  string $filePath
  */
 private function getTranslationsInFile($filePath)
 {
     // File extension ?
     $extOk = in_array(\Jig\Utils\FsUtils::getFileExtension($filePath), $this->getFileTypes());
     if ($extOk) {
         foreach ($this->getBannedFileType() as $bannedExt) {
             $extOk &= substr_compare($filePath, $bannedExt, strlen($filePath) - strlen($bannedExt), strlen($bannedExt)) !== 0;
         }
     }
     if ($extOk) {
         // We read the file.
         $lines = file($filePath);
         foreach ($lines as $line) {
             $strings = $this->getTranslationPhrases($line);
             //preg_match_all("/__(\(| )+['\"](.*?)['\"](\))?/u", $line, $string);
             //lookup for __('to translate') or __ 'to translate'
             //    preg_match_all("/__(\(| )+(('(.*?)')|(\"(.*?)\"))(\))?/u", $line, $string);
             foreach ($strings as $s) {
                 $tu = new tao_helpers_translation_TranslationUnit();
                 $tu->setSource(tao_helpers_translation_POUtils::sanitize($s));
                 $tus = $this->getTranslationUnits();
                 $found = false;
                 // We must add the string as a new TranslationUnit only
                 // if a similiar source does not exist.
                 foreach ($tus as $t) {
                     if ($tu->getSource() == $t->getSource()) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $tus[] = $tu;
                     $this->setTranslationUnits($tus);
                 }
             }
         }
     }
 }