Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_translation_POTranslationUnit | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
182 | |
0.00% |
0 / 1 |
| addFlag | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| removeFlag | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| hasFlag | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getFlags | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| setFlags | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | * A PO Translation Unit. |
| 27 | * |
| 28 | * @access public |
| 29 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 30 | * @package tao |
| 31 | |
| 32 | */ |
| 33 | class tao_helpers_translation_POTranslationUnit extends tao_helpers_translation_TranslationUnit |
| 34 | { |
| 35 | // --- ASSOCIATIONS --- |
| 36 | |
| 37 | |
| 38 | // --- ATTRIBUTES --- |
| 39 | |
| 40 | /** |
| 41 | * Annotation identifier for PO translator comments. |
| 42 | * |
| 43 | * @access public |
| 44 | * @var string |
| 45 | */ |
| 46 | public const TRANSLATOR_COMMENTS = 'po-translator-comments'; |
| 47 | |
| 48 | /** |
| 49 | * Annotation identifier for PO extracted comments. |
| 50 | * |
| 51 | * @access public |
| 52 | * @var string |
| 53 | */ |
| 54 | public const EXTRACTED_COMMENTS = 'po-extracted-comments'; |
| 55 | |
| 56 | /** |
| 57 | * Annotation identifier for PO message flags. |
| 58 | * |
| 59 | * @access public |
| 60 | * @var string |
| 61 | */ |
| 62 | public const FLAGS = 'po-flags'; |
| 63 | |
| 64 | /** |
| 65 | * Annotation identifier for PO reference flag. |
| 66 | * |
| 67 | * @access public |
| 68 | * @var string |
| 69 | */ |
| 70 | public const REFERENCE = 'po-reference'; |
| 71 | |
| 72 | /** |
| 73 | * Annotation identifier for the PO previous untranslated string (singular) |
| 74 | * |
| 75 | * @access public |
| 76 | * @var string |
| 77 | */ |
| 78 | public const PREVIOUS_MSGID = 'po-previous-msgid'; |
| 79 | |
| 80 | /** |
| 81 | * Annotation identifier for the PO previous untranslated string (plural) |
| 82 | * |
| 83 | * @access public |
| 84 | * @var string |
| 85 | */ |
| 86 | public const PREVIOUS_MSGID_PLURAL = 'po-previous-msgid-plural'; |
| 87 | |
| 88 | /** |
| 89 | * Annotation identifier for the message context comment. |
| 90 | * |
| 91 | * @access public |
| 92 | * @var string |
| 93 | */ |
| 94 | public const PREVIOUS_MSGCTXT = 'po-previous-msgctxt'; |
| 95 | |
| 96 | // --- OPERATIONS --- |
| 97 | |
| 98 | /** |
| 99 | * Add a PO compliant flag to the TranslationUnit. The FLAGS annotation will |
| 100 | * created if no flags were added before. |
| 101 | * |
| 102 | * @access public |
| 103 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 104 | * @param string flag A flag string. |
| 105 | * @return void |
| 106 | */ |
| 107 | public function addFlag($flag) |
| 108 | { |
| 109 | |
| 110 | $currentAnnotations = $this->getAnnotations(); |
| 111 | if (!isset($currentAnnotations[self::FLAGS])) { |
| 112 | $currentAnnotations[self::FLAGS] = $flag; |
| 113 | } elseif (!(mb_strpos($currentAnnotations[self::FLAGS], $flag, 0, TAO_DEFAULT_ENCODING) !== false)) { |
| 114 | $currentAnnotations[self::FLAGS] .= " ${flag}"; |
| 115 | } |
| 116 | |
| 117 | $this->setAnnotations($currentAnnotations); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Remove a given PO compliant flag from the TranslationUnit. The FLAGS |
| 122 | * will be removed from the TranslationUnit if it was the last one of the |
| 123 | * |
| 124 | * @access public |
| 125 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 126 | * @param string flag A flag string. |
| 127 | * @return void |
| 128 | */ |
| 129 | public function removeFlag($flag) |
| 130 | { |
| 131 | |
| 132 | $currentFlags = $this->getFlags(); |
| 133 | for ($i = 0; $i < count($currentFlags); $i++) { |
| 134 | if ($currentFlags[$i] == $flag) { |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if ($i <= count($currentFlags)) { |
| 140 | // The flag is found. |
| 141 | unset($currentFlags[$i]); |
| 142 | $this->setFlags($currentFlags); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Short description of method hasFlag |
| 148 | * |
| 149 | * @access public |
| 150 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 151 | * @param string flag A PO flag string. |
| 152 | * @return boolean |
| 153 | */ |
| 154 | public function hasFlag($flag) |
| 155 | { |
| 156 | $returnValue = (bool) false; |
| 157 | |
| 158 | |
| 159 | foreach ($this->getFlags() as $f) { |
| 160 | if ($f == $flag) { |
| 161 | $returnValue = true; |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | |
| 167 | return (bool) $returnValue; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Get the flags associated to the TranslationUnit. If there are no flags, |
| 172 | * empty array is returned. Otherwise, a collection of strings is returned. |
| 173 | * |
| 174 | * @access public |
| 175 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 176 | * @return array |
| 177 | */ |
| 178 | public function getFlags() |
| 179 | { |
| 180 | $returnValue = []; |
| 181 | |
| 182 | |
| 183 | $currentAnnotations = $this->getAnnotations(); |
| 184 | if (isset($currentAnnotations[self::FLAGS])) { |
| 185 | $returnValue = explode(" ", $currentAnnotations[self::FLAGS]); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | return (array) $returnValue; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Associate a collection of PO flags to the TranslationUnit. A FLAGS |
| 194 | * will be added to the TranslationUnit will be added consequently to the |
| 195 | * |
| 196 | * @access public |
| 197 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 198 | * @param array flags An array of PO string flags. |
| 199 | */ |
| 200 | public function setFlags($flags) |
| 201 | { |
| 202 | |
| 203 | $currentAnnotations = $this->getAnnotations(); |
| 204 | $currentAnnotations[self::FLAGS] = implode(" ", $flags); |
| 205 | $this->setAnnotations($currentAnnotations); |
| 206 | } |
| 207 | } |