* @package tao */ class tao_helpers_translation_POFile extends tao_helpers_translation_TaoTranslationFile { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * Short description of attribute headers * * @access private * @var array */ private $headers = []; // --- OPERATIONS --- /** * Short description of method addHeader * * @access public * @author Jerome Bogaerts, * @param string name * @param string value * @return void */ public function addHeader($name, $value) { $this->headers[$name] = $value; } /** * Short description of method removeHeader * * @access public * @author Jerome Bogaerts, * @param string name * @return void */ public function removeHeader($name) { unset($this->headers[$name]); } /** * Short description of method getHeaders * * @access public * @author Jerome Bogaerts, * @return array */ public function getHeaders() { $returnValue = []; $returnValue = $this->headers; return (array) $returnValue; } /** * Get a collection of POTranslationUnits based on the $flag argument * If no Translation Units are found, an empty array is returned. * * @access public * @author Jerome Bogaerts, * @param string flag A PO compliant string flag. * @return array */ public function getByFlag($flag) { $returnValue = []; foreach ($this->getTranslationUnits() as $tu) { if ($tu->hasFlag($flag)) { $returnValue[] = $tu; } } return (array) $returnValue; } /** * Get a collection of POTranslationUnits that have all the flags referenced * the $flags array. If no TranslationUnits are found, an empty array is * * @access public * @author Jerome Bogaerts, * @param array flags An array of PO compliant string flags. * @return array */ public function getByFlags($flags) { $returnValue = []; foreach ($this->getTranslationUnits() as $tu) { $matching = true; foreach ($flags as $f) { if (!$tu->hasFlag($f)) { $matching = false; break; } } if ($matching == true) { $returnValue[] = $tu; } else { // Prepare next iteration. $matching = true; } } return (array) $returnValue; } /** * 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); } }