Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 21 |
CRAP | |
0.00% |
0 / 1 |
tao_helpers_translation_TranslationUnit | |
0.00% |
0 / 50 |
|
0.00% |
0 / 21 |
552 | |
0.00% |
0 / 1 |
setAnnotations | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAnnotations | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
addAnnotation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
removeAnnotation | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getAnnotation | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getSource | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getTarget | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
setSource | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setTarget | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
setSourceLanguage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
setTargetLanguage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getContext | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setContext | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSourceLanguage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getTargetLanguage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
__toString | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
hasSameTranslationUnitSource | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
hasSameTranslationUnitTarget | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
hasSameTranslationUnitSourceLanguage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
hasSameTranslationUnitTargetLanguage | |
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 Translation Unit represents a single unit of translation of a software, |
27 | * file, ... It has a source text in the original language and a target in which |
28 | * text has to be translated. |
29 | * |
30 | * Example: |
31 | * Source (English): The end is far away |
32 | * Target (Yoda English): Far away the end is |
33 | * |
34 | * @access public |
35 | * @author Jerome Bogaerts |
36 | * @package tao |
37 | * @since 2.2 |
38 | |
39 | * @version 1.0 |
40 | */ |
41 | class tao_helpers_translation_TranslationUnit implements tao_helpers_translation_Annotable |
42 | { |
43 | // --- ASSOCIATIONS --- |
44 | |
45 | |
46 | // --- ATTRIBUTES --- |
47 | |
48 | /** |
49 | * Short description of attribute source |
50 | * |
51 | * @access private |
52 | * @var string |
53 | */ |
54 | private $source = ''; |
55 | |
56 | /** |
57 | * Short description of attribute target |
58 | * |
59 | * @access private |
60 | * @var string |
61 | */ |
62 | private $target = ''; |
63 | |
64 | /** |
65 | * Short description of attribute sourceLanguage |
66 | * |
67 | * @access private |
68 | * @var string |
69 | */ |
70 | private $sourceLanguage = ''; |
71 | |
72 | /** |
73 | * Short description of attribute targetLanguage |
74 | * |
75 | * @access private |
76 | * @var string |
77 | */ |
78 | private $targetLanguage = ''; |
79 | |
80 | /** |
81 | * The annotations bound to this translation unit. |
82 | * |
83 | * @access private |
84 | * @var array |
85 | */ |
86 | private $annotations = []; |
87 | |
88 | /** |
89 | * The context of the translation bound to this translation unit. |
90 | * |
91 | * @access private |
92 | * @var string |
93 | */ |
94 | private $context = ''; |
95 | |
96 | // --- OPERATIONS --- |
97 | |
98 | /** |
99 | * Sets the collection of annotations bound to this Translation Object. |
100 | * |
101 | * @access public |
102 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
103 | * @param array $annotations An associative array of annotations where keys are the annotation names and values are |
104 | * annotation values. |
105 | * @return void |
106 | */ |
107 | public function setAnnotations($annotations) |
108 | { |
109 | |
110 | $this->annotations = $annotations; |
111 | } |
112 | |
113 | /** |
114 | * Returns an associative array that represents a collection of annotations |
115 | * keys are annotation names and values annotation values. |
116 | * |
117 | * @access public |
118 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
119 | * @return array |
120 | */ |
121 | public function getAnnotations() |
122 | { |
123 | $returnValue = []; |
124 | |
125 | |
126 | $returnValue = $this->annotations; |
127 | |
128 | |
129 | return (array) $returnValue; |
130 | } |
131 | |
132 | /** |
133 | * Adds an annotation with a given name and value. If value is not provided, |
134 | * annotation will be taken into account as a flag. |
135 | * |
136 | * @access public |
137 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
138 | * @param string name The name of the annotation to add. |
139 | * @param string value The value of the annotation to add. |
140 | * @return void |
141 | */ |
142 | public function addAnnotation($name, $value = '') |
143 | { |
144 | |
145 | $this->annotations[$name] = $value; |
146 | } |
147 | |
148 | /** |
149 | * Removes an annotation for a given annotation name. |
150 | * |
151 | * @access public |
152 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
153 | * @param string name The name of the annotation to remove. |
154 | * @return void |
155 | */ |
156 | public function removeAnnotation($name) |
157 | { |
158 | |
159 | if (isset($this->annotations[$name])) { |
160 | unset($this->annotations[$name]); |
161 | } |
162 | } |
163 | |
164 | /** |
165 | * Get an annotation for a given annotation name. Returns an associative |
166 | * where keys are 'name' and 'value'. |
167 | * |
168 | * @access public |
169 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
170 | * @param string name |
171 | * @return array |
172 | */ |
173 | public function getAnnotation($name) |
174 | { |
175 | $returnValue = []; |
176 | |
177 | |
178 | if (isset($this->annotations[$name])) { |
179 | $returnValue = ['name' => $name, 'value' => $this->annotations[$name]]; |
180 | } else { |
181 | $returnValue = null; |
182 | } |
183 | |
184 | |
185 | return (array) $returnValue; |
186 | } |
187 | |
188 | /** |
189 | * Gets the source text. |
190 | * |
191 | * @access public |
192 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
193 | * @return string |
194 | */ |
195 | public function getSource() |
196 | { |
197 | $returnValue = (string) ''; |
198 | |
199 | |
200 | $returnValue = $this->source; |
201 | |
202 | |
203 | return (string) $returnValue; |
204 | } |
205 | |
206 | /** |
207 | * Gets the target text. |
208 | * |
209 | * @access public |
210 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
211 | * @return string |
212 | */ |
213 | public function getTarget() |
214 | { |
215 | $returnValue = (string) ''; |
216 | |
217 | |
218 | $returnValue = $this->target; |
219 | |
220 | |
221 | return (string) $returnValue; |
222 | } |
223 | |
224 | /** |
225 | * Sets the source text. |
226 | * |
227 | * @access public |
228 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
229 | * @param string source |
230 | * @return mixed |
231 | */ |
232 | public function setSource($source) |
233 | { |
234 | |
235 | $this->source = $source; |
236 | } |
237 | |
238 | /** |
239 | * Sets the target text. |
240 | * |
241 | * @access public |
242 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
243 | * @param string target |
244 | * @return mixed |
245 | */ |
246 | public function setTarget($target) |
247 | { |
248 | |
249 | $this->target = $target; |
250 | } |
251 | |
252 | /** |
253 | * Creates a new instance of Translation Unit with specific source & target. |
254 | * |
255 | * @access public |
256 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
257 | * @return mixed |
258 | */ |
259 | public function __construct() |
260 | { |
261 | |
262 | // Default values for source and target languages are en-US. |
263 | $this->setSourceLanguage(tao_helpers_translation_Utils::getDefaultLanguage()); |
264 | $this->setTargetLanguage(tao_helpers_translation_Utils::getDefaultLanguage()); |
265 | } |
266 | |
267 | /** |
268 | * Short description of method setSourceLanguage |
269 | * |
270 | * @access public |
271 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
272 | * @param string sourceLanguage |
273 | * @return mixed |
274 | */ |
275 | public function setSourceLanguage($sourceLanguage) |
276 | { |
277 | |
278 | $this->sourceLanguage = $sourceLanguage; |
279 | $this->addAnnotation('sourceLanguage', $sourceLanguage); |
280 | } |
281 | |
282 | /** |
283 | * Short description of method setTargetLanguage |
284 | * |
285 | * @access public |
286 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
287 | * @param string targetLanguage |
288 | * @return mixed |
289 | */ |
290 | public function setTargetLanguage($targetLanguage) |
291 | { |
292 | |
293 | $this->targetLanguage = $targetLanguage; |
294 | $this->addAnnotation('targetLanguage', $targetLanguage); |
295 | } |
296 | |
297 | /** |
298 | * @return string |
299 | */ |
300 | public function getContext() |
301 | { |
302 | return $this->context; |
303 | } |
304 | |
305 | /** |
306 | * @param string $context |
307 | */ |
308 | public function setContext($context) |
309 | { |
310 | $this->context = $context; |
311 | } |
312 | |
313 | |
314 | |
315 | /** |
316 | * Short description of method getSourceLanguage |
317 | * |
318 | * @access public |
319 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
320 | * @return string |
321 | */ |
322 | public function getSourceLanguage() |
323 | { |
324 | $returnValue = (string) ''; |
325 | |
326 | |
327 | $returnValue = $this->sourceLanguage; |
328 | |
329 | |
330 | return (string) $returnValue; |
331 | } |
332 | |
333 | /** |
334 | * Short description of method getTargetLanguage |
335 | * |
336 | * @access public |
337 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
338 | * @return string |
339 | */ |
340 | public function getTargetLanguage() |
341 | { |
342 | $returnValue = (string) ''; |
343 | |
344 | |
345 | $returnValue = $this->targetLanguage; |
346 | |
347 | |
348 | return (string) $returnValue; |
349 | } |
350 | |
351 | /** |
352 | * Short description of method __toString |
353 | * |
354 | * @access public |
355 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
356 | * @return string |
357 | */ |
358 | public function __toString() |
359 | { |
360 | $returnValue = (string) ''; |
361 | |
362 | |
363 | $returnValue = $this->getSourceLanguage() . '->' . $this->getTargetLanguage() . ':' . |
364 | $this->getSource() . '-' . $this->getTarget(); |
365 | |
366 | |
367 | return (string) $returnValue; |
368 | } |
369 | |
370 | /** |
371 | * Short description of method hasSameTranslationUnitSource |
372 | * |
373 | * @access public |
374 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
375 | * @param TranslationUnit translationUnit |
376 | * @return boolean |
377 | */ |
378 | public function hasSameTranslationUnitSource(tao_helpers_translation_TranslationUnit $translationUnit) |
379 | { |
380 | $returnValue = (bool) false; |
381 | |
382 | |
383 | $returnValue = $this->getSource() == $translationUnit->getSource(); |
384 | |
385 | |
386 | return (bool) $returnValue; |
387 | } |
388 | |
389 | /** |
390 | * Short description of method hasSameTranslationUnitTarget |
391 | * |
392 | * @access public |
393 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
394 | * @param TranslationUnit translationUnit |
395 | * @return boolean |
396 | */ |
397 | public function hasSameTranslationUnitTarget(tao_helpers_translation_TranslationUnit $translationUnit) |
398 | { |
399 | $returnValue = (bool) false; |
400 | |
401 | |
402 | $returnValue = $this->getTarget() == $translationUnit->getTarget(); |
403 | |
404 | |
405 | return (bool) $returnValue; |
406 | } |
407 | |
408 | /** |
409 | * Checks whether or not a given TranslationUnit has the same source |
410 | * than the current instance. |
411 | * |
412 | * @access public |
413 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
414 | * @param TranslationUnit translationUnit |
415 | * @return boolean |
416 | */ |
417 | public function hasSameTranslationUnitSourceLanguage(tao_helpers_translation_TranslationUnit $translationUnit) |
418 | { |
419 | $returnValue = (bool) false; |
420 | |
421 | |
422 | $returnValue = $this->getSourceLanguage() == $translationUnit->getSourceLanguage(); |
423 | |
424 | |
425 | return (bool) $returnValue; |
426 | } |
427 | |
428 | /** |
429 | * Checks whether or not a given TranslationUnit has the same target |
430 | * than the current instance. |
431 | * |
432 | * @access public |
433 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
434 | * @param TranslationUnit translationUnit |
435 | * @return boolean |
436 | */ |
437 | public function hasSameTranslationUnitTargetLanguage(tao_helpers_translation_TranslationUnit $translationUnit) |
438 | { |
439 | $returnValue = (bool) false; |
440 | |
441 | |
442 | $returnValue = $this->getTargetLanguage() == $translationUnit->getTargetLanguage(); |
443 | |
444 | |
445 | return (bool) $returnValue; |
446 | } |
447 | } |