@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | ]; |
33 | 33 | |
34 | 34 | public function replaceTranslation() { |
35 | - fwrite( $this->outputFP, '<?xml version="1.0" encoding="UTF-8"?>' ); |
|
35 | + fwrite($this->outputFP, '<?xml version="1.0" encoding="UTF-8"?>'); |
|
36 | 36 | |
37 | 37 | //create Sax parser |
38 | 38 | $xmlParser = $this->initSaxParser(); |
39 | 39 | |
40 | - while ( $this->currentBuffer = fread( $this->originalFP, 4096 ) ) { |
|
40 | + while ($this->currentBuffer = fread($this->originalFP, 4096)) { |
|
41 | 41 | /* |
42 | 42 | preprocess file |
43 | 43 | */ |
44 | 44 | // obfuscate entities because sax automatically does html_entity_decode |
45 | - $temporary_check_buffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer ); |
|
45 | + $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer); |
|
46 | 46 | |
47 | 47 | //avoid cutting entities in half: |
48 | 48 | //the last fread could have truncated an entity (say, '<' in '&l'), thus invalidating the escaping |
@@ -54,84 +54,84 @@ discard block |
||
54 | 54 | // add 9 Bytes and substitute the entities, if the & is present, and it is not at the end |
55 | 55 | //it can't be an entity, exit the loop |
56 | 56 | |
57 | - while ( true ) { |
|
58 | - $_ampPos = strpos( $temporary_check_buffer, '&' ); |
|
57 | + while (true) { |
|
58 | + $_ampPos = strpos($temporary_check_buffer, '&'); |
|
59 | 59 | |
60 | 60 | //check for real entity or escape it to safely exit from the loop!!! |
61 | - if ( $_ampPos === false || strlen( substr( $temporary_check_buffer, $_ampPos ) ) > 9 ) { |
|
61 | + if ($_ampPos === false || strlen(substr($temporary_check_buffer, $_ampPos)) > 9) { |
|
62 | 62 | $escape_AMP = true; |
63 | 63 | break; |
64 | 64 | } |
65 | 65 | |
66 | 66 | //if an entity is still present, fetch some more and repeat the escaping |
67 | - $this->currentBuffer .= fread( $this->originalFP, 9 ); |
|
68 | - $temporary_check_buffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer ); |
|
67 | + $this->currentBuffer .= fread($this->originalFP, 9); |
|
68 | + $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | //free stuff outside the loop |
72 | - unset( $temporary_check_buffer ); |
|
72 | + unset($temporary_check_buffer); |
|
73 | 73 | |
74 | - $this->currentBuffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer ); |
|
75 | - if ( $escape_AMP ) { |
|
76 | - $this->currentBuffer = str_replace( "&", self::$INTERNAL_TAG_PLACEHOLDER . 'amp' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer ); |
|
74 | + $this->currentBuffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer); |
|
75 | + if ($escape_AMP) { |
|
76 | + $this->currentBuffer = str_replace("&", self::$INTERNAL_TAG_PLACEHOLDER . 'amp' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | //get length of chunk |
80 | - $this->len = strlen( $this->currentBuffer ); |
|
80 | + $this->len = strlen($this->currentBuffer); |
|
81 | 81 | |
82 | 82 | //parse chunk of text |
83 | - if ( !xml_parse( $xmlParser, $this->currentBuffer, feof( $this->originalFP ) ) ) { |
|
83 | + if (!xml_parse($xmlParser, $this->currentBuffer, feof($this->originalFP))) { |
|
84 | 84 | //if unable, raise an exception |
85 | - throw new RuntimeException( sprintf( |
|
85 | + throw new RuntimeException(sprintf( |
|
86 | 86 | "XML error: %s at line %d", |
87 | - xml_error_string( xml_get_error_code( $xmlParser ) ), |
|
88 | - xml_get_current_line_number( $xmlParser ) |
|
89 | - ) ); |
|
87 | + xml_error_string(xml_get_error_code($xmlParser)), |
|
88 | + xml_get_current_line_number($xmlParser) |
|
89 | + )); |
|
90 | 90 | } |
91 | 91 | //get accumulated this->offset in document: as long as SAX pointer advances, we keep track of total bytes it has seen so far; this way, we can translate its global pointer in an address local to the current buffer of text to retrieve last char of tag |
92 | 92 | $this->offset += $this->len; |
93 | 93 | } |
94 | 94 | |
95 | 95 | // close Sax parser |
96 | - $this->closeSaxParser( $xmlParser ); |
|
96 | + $this->closeSaxParser($xmlParser); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @inheritDoc |
102 | 102 | */ |
103 | - protected function tagOpen( $parser, $name, $attr ) { |
|
103 | + protected function tagOpen($parser, $name, $attr) { |
|
104 | 104 | // check if we are entering into a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
105 | - if ( $this->tuTagName === $name ) { |
|
105 | + if ($this->tuTagName === $name) { |
|
106 | 106 | $this->inTU = true; |
107 | 107 | |
108 | 108 | // get id |
109 | 109 | // trim to first 100 characters because this is the limit on Matecat's DB |
110 | - $this->currentTransUnitId = substr( $attr[ 'id' ], 0, 100 ); |
|
110 | + $this->currentTransUnitId = substr($attr['id'], 0, 100); |
|
111 | 111 | |
112 | 112 | // `translate` attribute can be only yes or no |
113 | - if ( isset( $attr[ 'translate' ] ) && $attr[ 'translate' ] === 'no' ) { |
|
114 | - $attr[ 'translate' ] = 'no'; |
|
113 | + if (isset($attr['translate']) && $attr['translate'] === 'no') { |
|
114 | + $attr['translate'] = 'no'; |
|
115 | 115 | } else { |
116 | - $attr[ 'translate' ] = 'yes'; |
|
116 | + $attr['translate'] = 'yes'; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // current 'translate' attribute of the current trans-unit |
120 | - $this->currentTransUnitTranslate = $attr[ 'translate' ]; |
|
120 | + $this->currentTransUnitTranslate = $attr['translate']; |
|
121 | 121 | } |
122 | 122 | |
123 | - if ( 'source' === $name ) { |
|
123 | + if ('source' === $name) { |
|
124 | 124 | $this->sourceAttributes = $attr; |
125 | 125 | } |
126 | 126 | |
127 | - if ( 'mda:metadata' === $name ) { |
|
127 | + if ('mda:metadata' === $name) { |
|
128 | 128 | $this->unitContainsMda = true; |
129 | 129 | } |
130 | 130 | |
131 | 131 | // check if we are entering into a <target> |
132 | - if ( 'target' === $name ) { |
|
132 | + if ('target' === $name) { |
|
133 | 133 | |
134 | - if ( $this->currentTransUnitTranslate === 'no' ) { |
|
134 | + if ($this->currentTransUnitTranslate === 'no') { |
|
135 | 135 | $this->inTarget = false; |
136 | 136 | } else { |
137 | 137 | $this->inTarget = true; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
142 | 142 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
143 | - if ( !$this->inTarget ) { |
|
143 | + if (!$this->inTarget) { |
|
144 | 144 | |
145 | 145 | $tag = ''; |
146 | 146 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | // |
163 | 163 | // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit |
164 | 164 | // |
165 | - if ( $this->xliffVersion === 2 && ( $name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable' ) && $this->unitContainsMda === false ) { |
|
166 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) && !empty( $this->transUnits[ $this->currentTransUnitId ] ) && !$this->hasWrittenCounts ) { |
|
165 | + if ($this->xliffVersion === 2 && ($name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') && $this->unitContainsMda === false) { |
|
166 | + if (isset($this->transUnits[$this->currentTransUnitId]) && !empty($this->transUnits[$this->currentTransUnitId]) && !$this->hasWrittenCounts) { |
|
167 | 167 | |
168 | 168 | // we need to update counts here |
169 | 169 | $this->updateCounts(); |
@@ -180,40 +180,40 @@ discard block |
||
180 | 180 | $lastMrkState = null; |
181 | 181 | $stateProp = ''; |
182 | 182 | |
183 | - foreach ( $attr as $k => $v ) { |
|
183 | + foreach ($attr as $k => $v) { |
|
184 | 184 | |
185 | 185 | //if tag name is file, we must replace the target-language attribute |
186 | - if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) { |
|
186 | + if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) { |
|
187 | 187 | //replace Target language with job language provided from constructor |
188 | 188 | $tag .= "$k=\"$this->targetLang\" "; |
189 | 189 | } else { |
190 | 190 | $pos = 0; |
191 | - if ( $this->currentTransUnitId and isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
192 | - $pos = current( $this->transUnits[ $this->currentTransUnitId ] ); |
|
191 | + if ($this->currentTransUnitId and isset($this->transUnits[$this->currentTransUnitId])) { |
|
192 | + $pos = current($this->transUnits[$this->currentTransUnitId]); |
|
193 | 193 | } |
194 | 194 | |
195 | - if ( $name === $this->tuTagName and isset( $this->segments[ $pos ] ) and isset( $this->segments[ $pos ][ 'sid' ] ) ) { |
|
195 | + if ($name === $this->tuTagName and isset($this->segments[$pos]) and isset($this->segments[$pos]['sid'])) { |
|
196 | 196 | |
197 | - $sid = $this->segments[ $pos ][ 'sid' ]; |
|
197 | + $sid = $this->segments[$pos]['sid']; |
|
198 | 198 | |
199 | 199 | // add `help-id` to xliff v.1* |
200 | 200 | // add `mtc:segment-id` to xliff v.2* |
201 | - if ( $this->xliffVersion === 1 && strpos( $tag, 'help-id' ) === false ) { |
|
202 | - if ( !empty( $sid ) ) { |
|
201 | + if ($this->xliffVersion === 1 && strpos($tag, 'help-id') === false) { |
|
202 | + if (!empty($sid)) { |
|
203 | 203 | $tag .= "help-id=\"$sid\" "; |
204 | 204 | } |
205 | - } elseif ( $this->xliffVersion === 2 && strpos( $tag, 'mtc:segment-id' ) === false ) { |
|
206 | - if ( !empty( $sid ) ) { |
|
205 | + } elseif ($this->xliffVersion === 2 && strpos($tag, 'mtc:segment-id') === false) { |
|
206 | + if (!empty($sid)) { |
|
207 | 207 | $tag .= "mtc:segment-id=\"$sid\" "; |
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - } elseif ( 'segment' === $name && $this->xliffVersion === 2 ) { // add state to segment in Xliff v2 |
|
212 | - [ $stateProp, $lastMrkState ] = $this->setTransUnitState( $this->segments[ $pos ], $stateProp, $lastMrkState ); |
|
211 | + } elseif ('segment' === $name && $this->xliffVersion === 2) { // add state to segment in Xliff v2 |
|
212 | + [$stateProp, $lastMrkState] = $this->setTransUnitState($this->segments[$pos], $stateProp, $lastMrkState); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute |
216 | - if ( $k != 'state' ) { |
|
216 | + if ($k != 'state') { |
|
217 | 217 | $tag .= "$k=\"$v\" "; |
218 | 218 | } |
219 | 219 | |
@@ -222,49 +222,49 @@ discard block |
||
222 | 222 | } |
223 | 223 | |
224 | 224 | // replace state for xliff v2 |
225 | - if ( $stateProp ) { |
|
225 | + if ($stateProp) { |
|
226 | 226 | $tag .= $stateProp; |
227 | 227 | } |
228 | 228 | |
229 | 229 | // add oasis xliff 20 namespace |
230 | - if ( $this->xliffVersion === 2 && $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) { |
|
230 | + if ($this->xliffVersion === 2 && $name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) { |
|
231 | 231 | $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"'; |
232 | 232 | } |
233 | 233 | |
234 | 234 | // add MateCat specific namespace, we want maybe add non-XLIFF attributes |
235 | - if ( $name === 'xliff' && !array_key_exists( 'xmlns:mtc', $attr ) ) { |
|
235 | + if ($name === 'xliff' && !array_key_exists('xmlns:mtc', $attr)) { |
|
236 | 236 | $tag .= ' xmlns:mtc="https://www.matecat.com" '; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // trgLang |
240 | - if ( $name === 'xliff' ) { |
|
241 | - $tag = preg_replace( '/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag ); |
|
240 | + if ($name === 'xliff') { |
|
241 | + $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | //this logic helps detecting empty tags |
245 | 245 | //get current position of SAX pointer in all the stream of data is has read so far: |
246 | 246 | //it points at the end of current tag |
247 | - $idx = xml_get_current_byte_index( $parser ); |
|
247 | + $idx = xml_get_current_byte_index($parser); |
|
248 | 248 | |
249 | 249 | //check whether the bounds of current tag are entirely in current buffer or the end of the current tag |
250 | 250 | //is outside current buffer (in the latter case, it's in next buffer to be read by the while loop); |
251 | 251 | //this check is necessary because we may have truncated a tag in half with current read, |
252 | 252 | //and the other half may be encountered in the next buffer it will be passed |
253 | - if ( isset( $this->currentBuffer[ $idx - $this->offset ] ) ) { |
|
253 | + if (isset($this->currentBuffer[$idx - $this->offset])) { |
|
254 | 254 | //if this tag entire lenght fitted in the buffer, the last char must be the last |
255 | 255 | //symbol before the '>'; if it's an empty tag, it is assumed that it's a '/' |
256 | - $lastChar = $this->currentBuffer[ $idx - $this->offset ]; |
|
256 | + $lastChar = $this->currentBuffer[$idx - $this->offset]; |
|
257 | 257 | } else { |
258 | 258 | //if it's out, simple use the last character of the chunk |
259 | - $lastChar = $this->currentBuffer[ $this->len - 1 ]; |
|
259 | + $lastChar = $this->currentBuffer[$this->len - 1]; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | //trim last space |
263 | - $tag = rtrim( $tag ); |
|
263 | + $tag = rtrim($tag); |
|
264 | 264 | |
265 | 265 | //detect empty tag |
266 | - $this->isEmpty = ( $lastChar == '/' || $name == 'x' ); |
|
267 | - if ( $this->isEmpty ) { |
|
266 | + $this->isEmpty = ($lastChar == '/' || $name == 'x'); |
|
267 | + if ($this->isEmpty) { |
|
268 | 268 | $tag .= '/'; |
269 | 269 | } |
270 | 270 | |
@@ -272,29 +272,29 @@ discard block |
||
272 | 272 | $tag .= ">"; |
273 | 273 | |
274 | 274 | //set a a Buffer for the segSource Source tag |
275 | - if ( $this->bufferIsActive || in_array( $name, $this->nodesToCopy ) ) { // we are opening a critical CDATA section |
|
275 | + if ($this->bufferIsActive || in_array($name, $this->nodesToCopy)) { // we are opening a critical CDATA section |
|
276 | 276 | |
277 | 277 | //WARNING BECAUSE SOURCE AND SEG-SOURCE TAGS CAN BE EMPTY IN SOME CASES!!!!! |
278 | 278 | //so check for isEmpty also in conjunction with name |
279 | - if ( $this->isEmpty && ( 'source' === $name || 'seg-source' === $name ) ) { |
|
280 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
279 | + if ($this->isEmpty && ('source' === $name || 'seg-source' === $name)) { |
|
280 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
281 | 281 | } else { |
282 | 282 | //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer |
283 | 283 | $this->bufferIsActive = true; |
284 | - $this->CDATABuffer .= $tag; |
|
284 | + $this->CDATABuffer .= $tag; |
|
285 | 285 | } |
286 | 286 | } else { |
287 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
287 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | 291 | // update segmentPositionInTu |
292 | 292 | |
293 | - if ( $this->xliffVersion === 1 && $this->inTU && $name === 'source' ) { |
|
293 | + if ($this->xliffVersion === 1 && $this->inTU && $name === 'source') { |
|
294 | 294 | $this->segmentPositionInTu++; |
295 | 295 | } |
296 | 296 | |
297 | - if ( $this->xliffVersion === 2 && $this->inTU && $name === 'segment' ) { |
|
297 | + if ($this->xliffVersion === 2 && $this->inTU && $name === 'segment') { |
|
298 | 298 | $this->segmentPositionInTu++; |
299 | 299 | } |
300 | 300 | } |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | /** |
303 | 303 | * @inheritDoc |
304 | 304 | */ |
305 | - protected function tagClose( $parser, $name ) { |
|
305 | + protected function tagClose($parser, $name) { |
|
306 | 306 | $tag = ''; |
307 | 307 | |
308 | 308 | /** |
@@ -311,26 +311,26 @@ discard block |
||
311 | 311 | * |
312 | 312 | * self::tagOpen method |
313 | 313 | */ |
314 | - if ( !$this->isEmpty && !( $this->inTarget && $name !== 'target' ) ) { |
|
314 | + if (!$this->isEmpty && !($this->inTarget && $name !== 'target')) { |
|
315 | 315 | |
316 | - if ( !$this->inTarget ) { |
|
316 | + if (!$this->inTarget) { |
|
317 | 317 | $tag = "</$name>"; |
318 | 318 | } |
319 | 319 | |
320 | - if ( 'target' == $name ) { |
|
320 | + if ('target' == $name) { |
|
321 | 321 | |
322 | - if ( $this->currentTransUnitTranslate === 'no' ) { |
|
322 | + if ($this->currentTransUnitTranslate === 'no') { |
|
323 | 323 | // do nothing |
324 | - } elseif ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
324 | + } elseif (isset($this->transUnits[$this->currentTransUnitId])) { |
|
325 | 325 | |
326 | 326 | // get translation of current segment, by indirect indexing: id -> positional index -> segment |
327 | 327 | // actually there may be more that one segment to that ID if there are two mrk of the same source segment |
328 | 328 | |
329 | - $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ]; |
|
329 | + $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId]; |
|
330 | 330 | |
331 | 331 | // $currentSegmentId |
332 | - if ( !empty( $listOfSegmentsIds ) ) { |
|
333 | - $this->setCurrentSegmentArray( $listOfSegmentsIds ); |
|
332 | + if (!empty($listOfSegmentsIds)) { |
|
333 | + $this->setCurrentSegmentArray($listOfSegmentsIds); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /* |
@@ -347,12 +347,12 @@ discard block |
||
347 | 347 | $this->lastTransUnit = []; |
348 | 348 | |
349 | 349 | $last_value = null; |
350 | - $segmentsCount = count( $listOfSegmentsIds ); |
|
351 | - for ( $i = 0; $i < $segmentsCount; $i++ ) { |
|
352 | - $id = $listOfSegmentsIds[ $i ]; |
|
353 | - if ( isset( $this->segments[ $id ] ) && ( $i == 0 || $last_value + 1 == $listOfSegmentsIds[ $i ] ) ) { |
|
354 | - $last_value = $listOfSegmentsIds[ $i ]; |
|
355 | - $this->lastTransUnit[] = $this->segments[ $id ]; |
|
350 | + $segmentsCount = count($listOfSegmentsIds); |
|
351 | + for ($i = 0; $i < $segmentsCount; $i++) { |
|
352 | + $id = $listOfSegmentsIds[$i]; |
|
353 | + if (isset($this->segments[$id]) && ($i == 0 || $last_value + 1 == $listOfSegmentsIds[$i])) { |
|
354 | + $last_value = $listOfSegmentsIds[$i]; |
|
355 | + $this->lastTransUnit[] = $this->segments[$id]; |
|
356 | 356 | } |
357 | 357 | } |
358 | 358 | |
@@ -364,27 +364,27 @@ discard block |
||
364 | 364 | // we must reset the lastMrkId found because this is a new segment. |
365 | 365 | $lastMrkId = -1; |
366 | 366 | |
367 | - if ( $this->xliffVersion === 2 ) { |
|
368 | - $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ]; |
|
367 | + if ($this->xliffVersion === 2) { |
|
368 | + $seg = $this->segments[$this->currentSegmentArray['sid']]; |
|
369 | 369 | |
370 | 370 | // update counts |
371 | - if ( !$this->hasWrittenCounts && !empty( $seg ) ) { |
|
372 | - $this->updateSegmentCounts( $seg ); |
|
371 | + if (!$this->hasWrittenCounts && !empty($seg)) { |
|
372 | + $this->updateSegmentCounts($seg); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | // delete translations so the prepareSegment |
376 | 376 | // will put source content in target tag |
377 | - if ( $this->sourceInTarget ) { |
|
378 | - $seg[ 'translation' ] = ''; |
|
377 | + if ($this->sourceInTarget) { |
|
378 | + $seg['translation'] = ''; |
|
379 | 379 | $this->resetCounts(); |
380 | 380 | } |
381 | 381 | |
382 | 382 | // append $translation |
383 | - $translation = $this->prepareTranslation( $seg, $translation ); |
|
383 | + $translation = $this->prepareTranslation($seg, $translation); |
|
384 | 384 | |
385 | - [ $stateProp, ] = $this->setTransUnitState( $seg, $stateProp, null ); |
|
385 | + [$stateProp, ] = $this->setTransUnitState($seg, $stateProp, null); |
|
386 | 386 | } else { |
387 | - foreach ( $listOfSegmentsIds as $pos => $id ) { |
|
387 | + foreach ($listOfSegmentsIds as $pos => $id) { |
|
388 | 388 | |
389 | 389 | /* |
390 | 390 | * This routine works to respect the positional orders of markers. |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | * pre-assign zero to the new mrk if this is the first one ( in this segment ) |
398 | 398 | * If it is null leave it NULL |
399 | 399 | */ |
400 | - if ( (int)$this->segments[ $id ][ "mrk_id" ] < 0 && $this->segments[ $id ][ "mrk_id" ] !== null ) { |
|
401 | - $this->segments[ $id ][ "mrk_id" ] = 0; |
|
400 | + if ((int)$this->segments[$id]["mrk_id"] < 0 && $this->segments[$id]["mrk_id"] !== null) { |
|
401 | + $this->segments[$id]["mrk_id"] = 0; |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /* |
@@ -407,61 +407,61 @@ discard block |
||
407 | 407 | * ( null <= -1 ) === true |
408 | 408 | * so, cast to int |
409 | 409 | */ |
410 | - if ( (int)$this->segments[ $id ][ "mrk_id" ] <= $lastMrkId ) { |
|
410 | + if ((int)$this->segments[$id]["mrk_id"] <= $lastMrkId) { |
|
411 | 411 | break; |
412 | 412 | } |
413 | 413 | |
414 | 414 | // set $this->currentSegment |
415 | - $seg = $this->segments[ $id ]; |
|
415 | + $seg = $this->segments[$id]; |
|
416 | 416 | |
417 | 417 | // update counts |
418 | - if ( !empty( $seg ) ) { |
|
419 | - $this->updateSegmentCounts( $seg ); |
|
418 | + if (!empty($seg)) { |
|
419 | + $this->updateSegmentCounts($seg); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | // delete translations so the prepareSegment |
423 | 423 | // will put source content in target tag |
424 | - if ( $this->sourceInTarget ) { |
|
425 | - $seg[ 'translation' ] = ''; |
|
424 | + if ($this->sourceInTarget) { |
|
425 | + $seg['translation'] = ''; |
|
426 | 426 | $this->resetCounts(); |
427 | 427 | } |
428 | 428 | |
429 | 429 | // append $translation |
430 | - $translation = $this->prepareTranslation( $seg, $translation ); |
|
430 | + $translation = $this->prepareTranslation($seg, $translation); |
|
431 | 431 | |
432 | 432 | // for xliff 2 we need $this->transUnits[ $this->currentId ] [ $pos ] for populating metadata |
433 | 433 | |
434 | - unset( $this->transUnits[ $this->currentTransUnitId ] [ $pos ] ); |
|
434 | + unset($this->transUnits[$this->currentTransUnitId] [$pos]); |
|
435 | 435 | |
436 | - $lastMrkId = $this->segments[ $id ][ "mrk_id" ]; |
|
436 | + $lastMrkId = $this->segments[$id]["mrk_id"]; |
|
437 | 437 | |
438 | - [ $stateProp, $lastMrkState ] = $this->setTransUnitState( $seg, $stateProp, $lastMrkState ); |
|
438 | + [$stateProp, $lastMrkState] = $this->setTransUnitState($seg, $stateProp, $lastMrkState); |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | 442 | //append translation |
443 | - $tag = $this->createTargetTag( $translation, $stateProp ); |
|
443 | + $tag = $this->createTargetTag($translation, $stateProp); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | |
447 | 447 | // signal we are leaving a target |
448 | 448 | $this->targetWasWritten = true; |
449 | 449 | $this->inTarget = false; |
450 | - $this->postProcAndFlush( $this->outputFP, $tag, $treatAsCDATA = true ); |
|
451 | - } elseif ( in_array( $name, $this->nodesToCopy ) ) { // we are closing a critical CDATA section |
|
450 | + $this->postProcAndFlush($this->outputFP, $tag, $treatAsCDATA = true); |
|
451 | + } elseif (in_array($name, $this->nodesToCopy)) { // we are closing a critical CDATA section |
|
452 | 452 | |
453 | 453 | $this->bufferIsActive = false; |
454 | 454 | |
455 | 455 | // only for Xliff 2.* |
456 | 456 | // write here <mda:metaGroup> and <mda:meta> if already present in the <unit> |
457 | - if ( 'mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts ) { |
|
457 | + if ('mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts) { |
|
458 | 458 | |
459 | 459 | // we need to update counts here |
460 | 460 | $this->updateCounts(); |
461 | 461 | $this->hasWrittenCounts = true; |
462 | 462 | |
463 | 463 | $tag = $this->CDATABuffer; |
464 | - $tag .= $this->getWordCountGroupForXliffV2( false ); |
|
464 | + $tag .= $this->getWordCountGroupForXliffV2(false); |
|
465 | 465 | $tag .= " </mda:metadata>"; |
466 | 466 | |
467 | 467 | } else { |
@@ -471,67 +471,67 @@ discard block |
||
471 | 471 | $this->CDATABuffer = ""; |
472 | 472 | |
473 | 473 | //flush to pointer |
474 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
475 | - } elseif ( 'segment' === $name ) { |
|
474 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
475 | + } elseif ('segment' === $name) { |
|
476 | 476 | |
477 | 477 | // only for Xliff 2.* |
478 | 478 | // if segment has no <target> add it BEFORE </segment> |
479 | - if ( $this->xliffVersion === 2 && !$this->targetWasWritten ) { |
|
479 | + if ($this->xliffVersion === 2 && !$this->targetWasWritten) { |
|
480 | 480 | |
481 | 481 | $seg = $this->getCurrentSegment(); |
482 | 482 | |
483 | - if ( isset( $seg[ 'translation' ] ) ) { |
|
483 | + if (isset($seg['translation'])) { |
|
484 | 484 | |
485 | - $translation = $this->prepareTranslation( $seg ); |
|
486 | - [ $stateProp, ] = $this->setTransUnitState( $seg, '', null ); |
|
485 | + $translation = $this->prepareTranslation($seg); |
|
486 | + [$stateProp, ] = $this->setTransUnitState($seg, '', null); |
|
487 | 487 | |
488 | - $tag = $this->createTargetTag( $translation, $stateProp ); |
|
488 | + $tag = $this->createTargetTag($translation, $stateProp); |
|
489 | 489 | |
490 | 490 | } |
491 | 491 | |
492 | 492 | $tag .= '</segment>'; |
493 | 493 | } |
494 | 494 | |
495 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
495 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
496 | 496 | |
497 | 497 | // we are leaving <segment>, reset $segmentHasTarget |
498 | 498 | $this->targetWasWritten = false; |
499 | 499 | |
500 | - } elseif ( $name === 'trans-unit' ) { |
|
500 | + } elseif ($name === 'trans-unit') { |
|
501 | 501 | |
502 | 502 | // only for Xliff 1.* |
503 | 503 | // handling </trans-unit> closure |
504 | - if ( !$this->targetWasWritten ) { |
|
504 | + if (!$this->targetWasWritten) { |
|
505 | 505 | |
506 | 506 | $seg = $this->getCurrentSegment(); |
507 | 507 | |
508 | - if ( isset( $seg[ 'translation' ] ) ) { |
|
509 | - $translation = $this->prepareTranslation( $seg ); |
|
510 | - [ $stateProp, ] = $this->setTransUnitState( $seg, '', null ); |
|
508 | + if (isset($seg['translation'])) { |
|
509 | + $translation = $this->prepareTranslation($seg); |
|
510 | + [$stateProp, ] = $this->setTransUnitState($seg, '', null); |
|
511 | 511 | |
512 | - $tag = $this->createTargetTag( $translation, $stateProp ); |
|
512 | + $tag = $this->createTargetTag($translation, $stateProp); |
|
513 | 513 | |
514 | 514 | } |
515 | 515 | |
516 | 516 | $tag .= '</trans-unit>'; |
517 | 517 | |
518 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
518 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
519 | 519 | |
520 | 520 | } else { |
521 | - $this->postProcAndFlush( $this->outputFP, '</trans-unit>' ); |
|
521 | + $this->postProcAndFlush($this->outputFP, '</trans-unit>'); |
|
522 | 522 | $this->targetWasWritten = false; |
523 | 523 | } |
524 | 524 | |
525 | 525 | |
526 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
526 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
527 | 527 | $this->CDATABuffer .= "</$name>"; |
528 | 528 | // Do NOT Flush |
529 | 529 | } else { //generic tag closure do Nothing |
530 | 530 | // flush to pointer |
531 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
531 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
532 | 532 | } |
533 | - } elseif ( $this->CDATABuffer === '<note/>' && $this->bufferIsActive === true ) { |
|
534 | - $this->postProcAndFlush( $this->outputFP, '<note/>' ); |
|
533 | + } elseif ($this->CDATABuffer === '<note/>' && $this->bufferIsActive === true) { |
|
534 | + $this->postProcAndFlush($this->outputFP, '<note/>'); |
|
535 | 535 | $this->bufferIsActive = false; |
536 | 536 | $this->CDATABuffer = ''; |
537 | 537 | $this->isEmpty = false; |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | } |
542 | 542 | |
543 | 543 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
544 | - if ( $this->tuTagName === $name ) { |
|
544 | + if ($this->tuTagName === $name) { |
|
545 | 545 | $this->currentTransUnitTranslate = null; |
546 | 546 | $this->inTU = false; |
547 | 547 | $this->segmentPositionInTu = -1; |
@@ -558,21 +558,21 @@ discard block |
||
558 | 558 | * |
559 | 559 | * @param array $listOfSegmentsIds |
560 | 560 | */ |
561 | - private function setCurrentSegmentArray( array $listOfSegmentsIds = [] ) { |
|
561 | + private function setCurrentSegmentArray(array $listOfSegmentsIds = []) { |
|
562 | 562 | // $currentSegmentId |
563 | - if ( empty( $this->currentSegmentArray ) ) { |
|
563 | + if (empty($this->currentSegmentArray)) { |
|
564 | 564 | $this->currentSegmentArray = [ |
565 | - 'sid' => $listOfSegmentsIds[ 0 ], |
|
565 | + 'sid' => $listOfSegmentsIds[0], |
|
566 | 566 | 'tid' => $this->currentTransUnitId, |
567 | 567 | ]; |
568 | 568 | } else { |
569 | - if ( $this->currentSegmentArray[ 'tid' ] === $this->currentTransUnitId ) { |
|
570 | - $key = array_search( $this->currentSegmentArray[ 'sid' ], $listOfSegmentsIds ); |
|
571 | - $this->currentSegmentArray[ 'sid' ] = $listOfSegmentsIds[ $key + 1 ]; |
|
572 | - $this->currentSegmentArray[ 'tid' ] = $this->currentTransUnitId; |
|
569 | + if ($this->currentSegmentArray['tid'] === $this->currentTransUnitId) { |
|
570 | + $key = array_search($this->currentSegmentArray['sid'], $listOfSegmentsIds); |
|
571 | + $this->currentSegmentArray['sid'] = $listOfSegmentsIds[$key + 1]; |
|
572 | + $this->currentSegmentArray['tid'] = $this->currentTransUnitId; |
|
573 | 573 | } else { |
574 | 574 | $this->currentSegmentArray = [ |
575 | - 'sid' => $listOfSegmentsIds[ 0 ], |
|
575 | + 'sid' => $listOfSegmentsIds[0], |
|
576 | 576 | 'tid' => $this->currentTransUnitId, |
577 | 577 | ]; |
578 | 578 | } |
@@ -584,23 +584,23 @@ discard block |
||
584 | 584 | */ |
585 | 585 | private function updateCounts() { |
586 | 586 | // populate counts |
587 | - $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ]; |
|
587 | + $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId]; |
|
588 | 588 | |
589 | 589 | // $currentSegmentId |
590 | - if ( !empty( $listOfSegmentsIds ) ) { |
|
591 | - $this->setCurrentSegmentArray( $listOfSegmentsIds ); |
|
590 | + if (!empty($listOfSegmentsIds)) { |
|
591 | + $this->setCurrentSegmentArray($listOfSegmentsIds); |
|
592 | 592 | } |
593 | 593 | |
594 | - if ( $this->xliffVersion === 2 ) { |
|
595 | - $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ]; |
|
596 | - if ( !empty( $seg ) ) { |
|
597 | - $this->updateSegmentCounts( $seg ); |
|
594 | + if ($this->xliffVersion === 2) { |
|
595 | + $seg = $this->segments[$this->currentSegmentArray['sid']]; |
|
596 | + if (!empty($seg)) { |
|
597 | + $this->updateSegmentCounts($seg); |
|
598 | 598 | } |
599 | 599 | } else { |
600 | - foreach ( $listOfSegmentsIds as $pos => $id ) { |
|
601 | - $seg = $this->segments[ $id ]; |
|
602 | - if ( !empty( $seg ) ) { |
|
603 | - $this->updateSegmentCounts( $seg ); |
|
600 | + foreach ($listOfSegmentsIds as $pos => $id) { |
|
601 | + $seg = $this->segments[$id]; |
|
602 | + if (!empty($seg)) { |
|
603 | + $this->updateSegmentCounts($seg); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | } |
@@ -611,27 +611,27 @@ discard block |
||
611 | 611 | /** |
612 | 612 | * @param array $seg |
613 | 613 | */ |
614 | - private function updateSegmentCounts( array $seg = [] ) { |
|
614 | + private function updateSegmentCounts(array $seg = []) { |
|
615 | 615 | |
616 | - $raw_word_count = $seg[ 'raw_word_count' ]; |
|
617 | - $eq_word_count = ( floor( $seg[ 'eq_word_count' ] * 100 ) / 100 ); |
|
616 | + $raw_word_count = $seg['raw_word_count']; |
|
617 | + $eq_word_count = (floor($seg['eq_word_count'] * 100) / 100); |
|
618 | 618 | |
619 | 619 | |
620 | - $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ]; |
|
620 | + $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId]; |
|
621 | 621 | |
622 | - $this->counts[ 'segments_count_array' ][ $seg[ 'sid' ] ] = [ |
|
622 | + $this->counts['segments_count_array'][$seg['sid']] = [ |
|
623 | 623 | 'raw_word_count' => $raw_word_count, |
624 | 624 | 'eq_word_count' => $eq_word_count, |
625 | 625 | ]; |
626 | 626 | |
627 | - $this->counts[ 'raw_word_count' ] += $raw_word_count; |
|
628 | - $this->counts[ 'eq_word_count' ] += $eq_word_count; |
|
627 | + $this->counts['raw_word_count'] += $raw_word_count; |
|
628 | + $this->counts['eq_word_count'] += $eq_word_count; |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | private function resetCounts() { |
632 | - $this->counts[ 'segments_count_array' ] = []; |
|
633 | - $this->counts[ 'raw_word_count' ] = 0; |
|
634 | - $this->counts[ 'eq_word_count' ] = 0; |
|
632 | + $this->counts['segments_count_array'] = []; |
|
633 | + $this->counts['raw_word_count'] = 0; |
|
634 | + $this->counts['eq_word_count'] = 0; |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | /** |
@@ -642,38 +642,38 @@ discard block |
||
642 | 642 | * |
643 | 643 | * @return string |
644 | 644 | */ |
645 | - protected function prepareTranslation( $seg, $transUnitTranslation = "" ) { |
|
645 | + protected function prepareTranslation($seg, $transUnitTranslation = "") { |
|
646 | 646 | $endTags = ""; |
647 | 647 | |
648 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
649 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
650 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
648 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
649 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
650 | + $dataRefMap = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
651 | 651 | |
652 | - if ( $seg [ 'translation' ] == '' ) { |
|
652 | + if ($seg ['translation'] == '') { |
|
653 | 653 | $translation = $segment; |
654 | 654 | } else { |
655 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
656 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
657 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
655 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
656 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
657 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
658 | 658 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
659 | 659 | } |
660 | 660 | } |
661 | 661 | } |
662 | 662 | |
663 | 663 | // for xliff v2 we ignore the marks on purpose |
664 | - if ( $this->xliffVersion === 2 ) { |
|
664 | + if ($this->xliffVersion === 2) { |
|
665 | 665 | return $translation; |
666 | 666 | } |
667 | 667 | |
668 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
669 | - if ( $this->targetLang === 'ja-JP' ) { |
|
670 | - $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] ); |
|
668 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
669 | + if ($this->targetLang === 'ja-JP') { |
|
670 | + $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']); |
|
671 | 671 | } |
672 | 672 | |
673 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>"; |
|
673 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>"; |
|
674 | 674 | } |
675 | 675 | |
676 | - $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . $seg[ 'succ_tags' ]; |
|
676 | + $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . $seg['succ_tags']; |
|
677 | 677 | |
678 | 678 | return $transUnitTranslation; |
679 | 679 | } |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | * |
686 | 686 | * @return string |
687 | 687 | */ |
688 | - private function getWordCountGroup( $raw_word_count, $eq_word_count ) { |
|
688 | + private function getWordCountGroup($raw_word_count, $eq_word_count) { |
|
689 | 689 | return "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">$raw_word_count</count><count count-type=\"x-matecat-weighted\">$eq_word_count</count></count-group>"; |
690 | 690 | } |
691 | 691 | |
@@ -693,11 +693,11 @@ discard block |
||
693 | 693 | * @return array |
694 | 694 | */ |
695 | 695 | private function getCurrentSegment() { |
696 | - if ( $this->currentTransUnitTranslate === 'yes' && isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
697 | - $index = $this->transUnits[ $this->currentTransUnitId ][ $this->segmentPositionInTu ]; |
|
696 | + if ($this->currentTransUnitTranslate === 'yes' && isset($this->transUnits[$this->currentTransUnitId])) { |
|
697 | + $index = $this->transUnits[$this->currentTransUnitId][$this->segmentPositionInTu]; |
|
698 | 698 | |
699 | - if ( isset( $this->segments[ $index ] ) ) { |
|
700 | - return $this->segments[ $index ]; |
|
699 | + if (isset($this->segments[$index])) { |
|
700 | + return $this->segments[$index]; |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
@@ -712,21 +712,21 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @return string |
714 | 714 | */ |
715 | - private function createTargetTag( $translation, $stateProp ) { |
|
715 | + private function createTargetTag($translation, $stateProp) { |
|
716 | 716 | |
717 | 717 | $targetLang = ''; |
718 | - if ( $this->xliffVersion === 1 ) { |
|
718 | + if ($this->xliffVersion === 1) { |
|
719 | 719 | $targetLang = ' xml:lang="' . $this->targetLang . '"'; |
720 | 720 | } |
721 | 721 | |
722 | - switch ( $this->xliffVersion ) { |
|
722 | + switch ($this->xliffVersion) { |
|
723 | 723 | case 1: |
724 | 724 | default: |
725 | 725 | $tag = "<target $targetLang $stateProp>$translation</target>"; |
726 | 726 | |
727 | 727 | // if it's a Trados file don't append count group |
728 | - if ( get_class( $this ) !== SdlXliffSAXTranslationReplacer::class ) { |
|
729 | - $tag .= $this->getWordCountGroup( $this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ] ); |
|
728 | + if (get_class($this) !== SdlXliffSAXTranslationReplacer::class) { |
|
729 | + $tag .= $this->getWordCountGroup($this->counts['raw_word_count'], $this->counts['eq_word_count']); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | return $tag; |
@@ -742,33 +742,33 @@ discard block |
||
742 | 742 | * |
743 | 743 | * @return string |
744 | 744 | */ |
745 | - private function getWordCountGroupForXliffV2( $withMetadataTag = true ) { |
|
745 | + private function getWordCountGroupForXliffV2($withMetadataTag = true) { |
|
746 | 746 | |
747 | 747 | $this->mdaGroupCounter++; |
748 | - $segments_count_array = $this->counts[ 'segments_count_array' ]; |
|
748 | + $segments_count_array = $this->counts['segments_count_array']; |
|
749 | 749 | |
750 | 750 | $id = $this->currentSegmentArray; |
751 | 751 | |
752 | 752 | |
753 | 753 | $return = ''; |
754 | 754 | |
755 | - if ( $withMetadataTag === true ) { |
|
755 | + if ($withMetadataTag === true) { |
|
756 | 756 | $return .= '<mda:metadata>'; |
757 | 757 | } |
758 | 758 | |
759 | 759 | $index = 0; |
760 | - foreach ( $segments_count_array as $segments_count_item ) { |
|
760 | + foreach ($segments_count_array as $segments_count_item) { |
|
761 | 761 | |
762 | 762 | $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']'; |
763 | 763 | $index++; |
764 | 764 | |
765 | 765 | $return .= " <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\"> |
766 | - <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta> |
|
767 | - <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta> |
|
766 | + <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta> |
|
767 | + <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta> |
|
768 | 768 | </mda:metaGroup>"; |
769 | 769 | } |
770 | 770 | |
771 | - if ( $withMetadataTag === true ) { |
|
771 | + if ($withMetadataTag === true) { |
|
772 | 772 | $return .= '</mda:metadata>'; |
773 | 773 | } |
774 | 774 | |
@@ -783,25 +783,25 @@ discard block |
||
783 | 783 | * |
784 | 784 | * @return array |
785 | 785 | */ |
786 | - private function setTransUnitState( $seg, $state_prop, $lastMrkState ) { |
|
787 | - switch ( $seg[ 'status' ] ) { |
|
786 | + private function setTransUnitState($seg, $state_prop, $lastMrkState) { |
|
787 | + switch ($seg['status']) { |
|
788 | 788 | |
789 | 789 | case TranslationStatus::STATUS_FIXED: |
790 | 790 | case TranslationStatus::STATUS_APPROVED2: |
791 | - if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2 ) { |
|
791 | + if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2) { |
|
792 | 792 | $state_prop = "state=\"final\""; |
793 | 793 | $lastMrkState = TranslationStatus::STATUS_APPROVED2; |
794 | 794 | } |
795 | 795 | break; |
796 | 796 | case TranslationStatus::STATUS_APPROVED: |
797 | - if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
|
798 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\""; |
|
797 | + if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED) { |
|
798 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"reviewed\"" : "state=\"signed-off\""; |
|
799 | 799 | $lastMrkState = TranslationStatus::STATUS_APPROVED; |
800 | 800 | } |
801 | 801 | break; |
802 | 802 | |
803 | 803 | case TranslationStatus::STATUS_TRANSLATED: |
804 | - if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
|
804 | + if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED) { |
|
805 | 805 | $state_prop = "state=\"translated\""; |
806 | 806 | $lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
807 | 807 | } |
@@ -809,22 +809,22 @@ discard block |
||
809 | 809 | |
810 | 810 | case TranslationStatus::STATUS_REJECTED: // if there is a mark REJECTED and there is not a DRAFT, all the trans-unit is REJECTED. In V2 there is no way to mark |
811 | 811 | case TranslationStatus::STATUS_REBUTTED: |
812 | - if ( ( $lastMrkState == null ) || ( $lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT ) ) { |
|
813 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\""; |
|
812 | + if (($lastMrkState == null) || ($lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT)) { |
|
813 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"needs-review-translation\""; |
|
814 | 814 | $lastMrkState = TranslationStatus::STATUS_REJECTED; |
815 | 815 | } |
816 | 816 | break; |
817 | 817 | |
818 | 818 | case TranslationStatus::STATUS_NEW: |
819 | - if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_NEW ) { |
|
820 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
|
819 | + if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_NEW) { |
|
820 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\""; |
|
821 | 821 | $lastMrkState = TranslationStatus::STATUS_NEW; |
822 | 822 | } |
823 | 823 | break; |
824 | 824 | |
825 | 825 | case TranslationStatus::STATUS_DRAFT: |
826 | - if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_DRAFT ) { |
|
827 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
|
826 | + if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_DRAFT) { |
|
827 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\""; |
|
828 | 828 | $lastMrkState = TranslationStatus::STATUS_DRAFT; |
829 | 829 | } |
830 | 830 | break; |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | // this is the case when a segment is not showed in cattool, so the row in |
834 | 834 | // segment_translations does not exists and |
835 | 835 | // ---> $seg[ 'status' ] is NULL |
836 | - if ( $lastMrkState == null ) { //this is the first MRK ID |
|
836 | + if ($lastMrkState == null) { //this is the first MRK ID |
|
837 | 837 | $state_prop = "state=\"translated\""; |
838 | 838 | $lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
839 | 839 | } else { |
@@ -842,17 +842,17 @@ discard block |
||
842 | 842 | break; |
843 | 843 | } |
844 | 844 | |
845 | - return [ $state_prop, $lastMrkState ]; |
|
845 | + return [$state_prop, $lastMrkState]; |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | /** |
849 | 849 | * @inheritDoc |
850 | 850 | */ |
851 | - protected function characterData( $parser, $data ) { |
|
851 | + protected function characterData($parser, $data) { |
|
852 | 852 | // don't write <target> data |
853 | - if ( !$this->inTarget && !$this->bufferIsActive ) { |
|
854 | - $this->postProcAndFlush( $this->outputFP, $data ); |
|
855 | - } elseif ( $this->bufferIsActive ) { |
|
853 | + if (!$this->inTarget && !$this->bufferIsActive) { |
|
854 | + $this->postProcAndFlush($this->outputFP, $data); |
|
855 | + } elseif ($this->bufferIsActive) { |
|
856 | 856 | $this->CDATABuffer .= $data; |
857 | 857 | } |
858 | 858 | } |