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