* @return mixed */ public function write() { $buffer = ''; $file = $this->getTranslationFile(); // Add PO Headers. $buffer .= 'msgid ""' . "\n"; $buffer .= 'msgstr ""' . "\n"; // If the TranslationFile is a specific POFile instance, we add PO Headers // to the output. if (get_class($this->getTranslationFile()) == 'tao_helpers_translation_POFile') { foreach ($file->getHeaders() as $name => $value) { $buffer .= '"' . $name . ': ' . $value . '\n"' . "\n"; } } // Write all Translation Units. $buffer .= "\n"; foreach ($this->getTranslationFile()->getTranslationUnits() as $tu) { $c = tao_helpers_translation_POUtils::sanitize($tu->getContext(), true); $s = tao_helpers_translation_POUtils::sanitize($tu->getSource(), true); $t = tao_helpers_translation_POUtils::sanitize($tu->getTarget(), true); $a = tao_helpers_translation_POUtils::serializeAnnotations($tu->getAnnotations()); if (!empty($a)) { $buffer .= "${a}\n"; } if ($c) { $buffer .= "msgctxt \"{$c}\"\n"; } $buffer .= "msgid \"{$s}\"\n"; $buffer .= "msgstr \"{$t}\"\n"; $buffer .= "\n"; } return file_put_contents($this->getFilePath(), $buffer); } }