Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_translation_POFileWriter | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| write | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * An implementation of TranslationFileWriter aiming at writing PO files. |
| 27 | * |
| 28 | * @access public |
| 29 | * @author Jerome Bogaerts |
| 30 | * @package tao |
| 31 | * @since 2.2 |
| 32 | |
| 33 | * @version 1.0 |
| 34 | */ |
| 35 | class tao_helpers_translation_POFileWriter extends tao_helpers_translation_TranslationFileWriter |
| 36 | { |
| 37 | // --- ASSOCIATIONS --- |
| 38 | |
| 39 | |
| 40 | // --- ATTRIBUTES --- |
| 41 | |
| 42 | // --- OPERATIONS --- |
| 43 | |
| 44 | /** |
| 45 | * Short description of method write |
| 46 | * |
| 47 | * @access public |
| 48 | * @author firstname and lastname of author, <author@example.org> |
| 49 | * @return mixed |
| 50 | */ |
| 51 | public function write() |
| 52 | { |
| 53 | |
| 54 | $buffer = ''; |
| 55 | $file = $this->getTranslationFile(); |
| 56 | |
| 57 | // Add PO Headers. |
| 58 | $buffer .= 'msgid ""' . "\n"; |
| 59 | $buffer .= 'msgstr ""' . "\n"; |
| 60 | |
| 61 | // If the TranslationFile is a specific POFile instance, we add PO Headers |
| 62 | // to the output. |
| 63 | if (get_class($this->getTranslationFile()) == 'tao_helpers_translation_POFile') { |
| 64 | foreach ($file->getHeaders() as $name => $value) { |
| 65 | $buffer .= '"' . $name . ': ' . $value . '\n"' . "\n"; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Write all Translation Units. |
| 70 | $buffer .= "\n"; |
| 71 | foreach ($this->getTranslationFile()->getTranslationUnits() as $tu) { |
| 72 | $c = tao_helpers_translation_POUtils::sanitize($tu->getContext(), true); |
| 73 | $s = tao_helpers_translation_POUtils::sanitize($tu->getSource(), true); |
| 74 | $t = tao_helpers_translation_POUtils::sanitize($tu->getTarget(), true); |
| 75 | $a = tao_helpers_translation_POUtils::serializeAnnotations($tu->getAnnotations()); |
| 76 | |
| 77 | if (!empty($a)) { |
| 78 | $buffer .= "${a}\n"; |
| 79 | } |
| 80 | |
| 81 | if ($c) { |
| 82 | $buffer .= "msgctxt \"{$c}\"\n"; |
| 83 | } |
| 84 | |
| 85 | $buffer .= "msgid \"{$s}\"\n"; |
| 86 | $buffer .= "msgstr \"{$t}\"\n"; |
| 87 | $buffer .= "\n"; |
| 88 | } |
| 89 | |
| 90 | return file_put_contents($this->getFilePath(), $buffer); |
| 91 | } |
| 92 | } |