@@ -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,22 +471,22 @@ 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->targetWasWritten ) { |
|
| 479 | + if (!$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 | 488 | // replace the tag |
| 489 | - $tag = $this->createTargetTag( $translation, $stateProp ); |
|
| 489 | + $tag = $this->createTargetTag($translation, $stateProp); |
|
| 490 | 490 | |
| 491 | 491 | $tag .= '</segment>'; |
| 492 | 492 | |
@@ -494,46 +494,46 @@ discard block |
||
| 494 | 494 | |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 497 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 498 | 498 | |
| 499 | 499 | // we are leaving <segment>, reset $segmentHasTarget |
| 500 | 500 | $this->targetWasWritten = false; |
| 501 | 501 | |
| 502 | - } elseif ( $name === 'trans-unit' ) { |
|
| 502 | + } elseif ($name === 'trans-unit') { |
|
| 503 | 503 | |
| 504 | 504 | // only for Xliff 1.* |
| 505 | 505 | // handling </trans-unit> closure |
| 506 | - if ( !$this->targetWasWritten ) { |
|
| 506 | + if (!$this->targetWasWritten) { |
|
| 507 | 507 | |
| 508 | 508 | $seg = $this->getCurrentSegment(); |
| 509 | 509 | |
| 510 | - if ( isset( $seg[ 'translation' ] ) ) { |
|
| 511 | - $translation = $this->prepareTranslation( $seg ); |
|
| 512 | - [ $stateProp, ] = $this->setTransUnitState( $seg, '', null ); |
|
| 510 | + if (isset($seg['translation'])) { |
|
| 511 | + $translation = $this->prepareTranslation($seg); |
|
| 512 | + [$stateProp, ] = $this->setTransUnitState($seg, '', null); |
|
| 513 | 513 | |
| 514 | 514 | // replace the tag |
| 515 | - $tag = $this->createTargetTag( $translation, $stateProp ); |
|
| 515 | + $tag = $this->createTargetTag($translation, $stateProp); |
|
| 516 | 516 | $tag .= '</trans-unit>'; |
| 517 | 517 | |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 520 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 521 | 521 | |
| 522 | 522 | } else { |
| 523 | - $this->postProcAndFlush( $this->outputFP, '</trans-unit>' ); |
|
| 523 | + $this->postProcAndFlush($this->outputFP, '</trans-unit>'); |
|
| 524 | 524 | $this->targetWasWritten = false; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
| 528 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
| 528 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
| 529 | 529 | $this->CDATABuffer .= "</$name>"; |
| 530 | 530 | // Do NOT Flush |
| 531 | 531 | } else { //generic tag closure do Nothing |
| 532 | 532 | // flush to pointer |
| 533 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 533 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 534 | 534 | } |
| 535 | - } elseif ( $this->CDATABuffer === '<note/>' && $this->bufferIsActive === true ) { |
|
| 536 | - $this->postProcAndFlush( $this->outputFP, '<note/>' ); |
|
| 535 | + } elseif ($this->CDATABuffer === '<note/>' && $this->bufferIsActive === true) { |
|
| 536 | + $this->postProcAndFlush($this->outputFP, '<note/>'); |
|
| 537 | 537 | $this->bufferIsActive = false; |
| 538 | 538 | $this->CDATABuffer = ''; |
| 539 | 539 | $this->isEmpty = false; |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
| 546 | - if ( $this->tuTagName === $name ) { |
|
| 546 | + if ($this->tuTagName === $name) { |
|
| 547 | 547 | $this->currentTransUnitTranslate = null; |
| 548 | 548 | $this->inTU = false; |
| 549 | 549 | $this->segmentPositionInTu = -1; |
@@ -560,21 +560,21 @@ discard block |
||
| 560 | 560 | * |
| 561 | 561 | * @param array $listOfSegmentsIds |
| 562 | 562 | */ |
| 563 | - private function setCurrentSegmentArray( array $listOfSegmentsIds = [] ) { |
|
| 563 | + private function setCurrentSegmentArray(array $listOfSegmentsIds = []) { |
|
| 564 | 564 | // $currentSegmentId |
| 565 | - if ( empty( $this->currentSegmentArray ) ) { |
|
| 565 | + if (empty($this->currentSegmentArray)) { |
|
| 566 | 566 | $this->currentSegmentArray = [ |
| 567 | - 'sid' => $listOfSegmentsIds[ 0 ], |
|
| 567 | + 'sid' => $listOfSegmentsIds[0], |
|
| 568 | 568 | 'tid' => $this->currentTransUnitId, |
| 569 | 569 | ]; |
| 570 | 570 | } else { |
| 571 | - if ( $this->currentSegmentArray[ 'tid' ] === $this->currentTransUnitId ) { |
|
| 572 | - $key = array_search( $this->currentSegmentArray[ 'sid' ], $listOfSegmentsIds ); |
|
| 573 | - $this->currentSegmentArray[ 'sid' ] = $listOfSegmentsIds[ $key + 1 ]; |
|
| 574 | - $this->currentSegmentArray[ 'tid' ] = $this->currentTransUnitId; |
|
| 571 | + if ($this->currentSegmentArray['tid'] === $this->currentTransUnitId) { |
|
| 572 | + $key = array_search($this->currentSegmentArray['sid'], $listOfSegmentsIds); |
|
| 573 | + $this->currentSegmentArray['sid'] = $listOfSegmentsIds[$key + 1]; |
|
| 574 | + $this->currentSegmentArray['tid'] = $this->currentTransUnitId; |
|
| 575 | 575 | } else { |
| 576 | 576 | $this->currentSegmentArray = [ |
| 577 | - 'sid' => $listOfSegmentsIds[ 0 ], |
|
| 577 | + 'sid' => $listOfSegmentsIds[0], |
|
| 578 | 578 | 'tid' => $this->currentTransUnitId, |
| 579 | 579 | ]; |
| 580 | 580 | } |
@@ -586,23 +586,23 @@ discard block |
||
| 586 | 586 | */ |
| 587 | 587 | private function updateCounts() { |
| 588 | 588 | // populate counts |
| 589 | - $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ]; |
|
| 589 | + $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId]; |
|
| 590 | 590 | |
| 591 | 591 | // $currentSegmentId |
| 592 | - if ( !empty( $listOfSegmentsIds ) ) { |
|
| 593 | - $this->setCurrentSegmentArray( $listOfSegmentsIds ); |
|
| 592 | + if (!empty($listOfSegmentsIds)) { |
|
| 593 | + $this->setCurrentSegmentArray($listOfSegmentsIds); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - if ( $this->xliffVersion === 2 ) { |
|
| 597 | - $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ]; |
|
| 598 | - if ( !empty( $seg ) ) { |
|
| 599 | - $this->updateSegmentCounts( $seg ); |
|
| 596 | + if ($this->xliffVersion === 2) { |
|
| 597 | + $seg = $this->segments[$this->currentSegmentArray['sid']]; |
|
| 598 | + if (!empty($seg)) { |
|
| 599 | + $this->updateSegmentCounts($seg); |
|
| 600 | 600 | } |
| 601 | 601 | } else { |
| 602 | - foreach ( $listOfSegmentsIds as $pos => $id ) { |
|
| 603 | - $seg = $this->segments[ $id ]; |
|
| 604 | - if ( !empty( $seg ) ) { |
|
| 605 | - $this->updateSegmentCounts( $seg ); |
|
| 602 | + foreach ($listOfSegmentsIds as $pos => $id) { |
|
| 603 | + $seg = $this->segments[$id]; |
|
| 604 | + if (!empty($seg)) { |
|
| 605 | + $this->updateSegmentCounts($seg); |
|
| 606 | 606 | } |
| 607 | 607 | } |
| 608 | 608 | } |
@@ -613,27 +613,27 @@ discard block |
||
| 613 | 613 | /** |
| 614 | 614 | * @param array $seg |
| 615 | 615 | */ |
| 616 | - private function updateSegmentCounts( array $seg = [] ) { |
|
| 616 | + private function updateSegmentCounts(array $seg = []) { |
|
| 617 | 617 | |
| 618 | - $raw_word_count = $seg[ 'raw_word_count' ]; |
|
| 619 | - $eq_word_count = ( floor( $seg[ 'eq_word_count' ] * 100 ) / 100 ); |
|
| 618 | + $raw_word_count = $seg['raw_word_count']; |
|
| 619 | + $eq_word_count = (floor($seg['eq_word_count'] * 100) / 100); |
|
| 620 | 620 | |
| 621 | 621 | |
| 622 | - $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ]; |
|
| 622 | + $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId]; |
|
| 623 | 623 | |
| 624 | - $this->counts[ 'segments_count_array' ][ $seg[ 'sid' ] ] = [ |
|
| 624 | + $this->counts['segments_count_array'][$seg['sid']] = [ |
|
| 625 | 625 | 'raw_word_count' => $raw_word_count, |
| 626 | 626 | 'eq_word_count' => $eq_word_count, |
| 627 | 627 | ]; |
| 628 | 628 | |
| 629 | - $this->counts[ 'raw_word_count' ] += $raw_word_count; |
|
| 630 | - $this->counts[ 'eq_word_count' ] += $eq_word_count; |
|
| 629 | + $this->counts['raw_word_count'] += $raw_word_count; |
|
| 630 | + $this->counts['eq_word_count'] += $eq_word_count; |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | private function resetCounts() { |
| 634 | - $this->counts[ 'segments_count_array' ] = []; |
|
| 635 | - $this->counts[ 'raw_word_count' ] = 0; |
|
| 636 | - $this->counts[ 'eq_word_count' ] = 0; |
|
| 634 | + $this->counts['segments_count_array'] = []; |
|
| 635 | + $this->counts['raw_word_count'] = 0; |
|
| 636 | + $this->counts['eq_word_count'] = 0; |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -644,38 +644,38 @@ discard block |
||
| 644 | 644 | * |
| 645 | 645 | * @return string |
| 646 | 646 | */ |
| 647 | - protected function prepareTranslation( $seg, $transUnitTranslation = "" ) { |
|
| 647 | + protected function prepareTranslation($seg, $transUnitTranslation = "") { |
|
| 648 | 648 | $endTags = ""; |
| 649 | 649 | |
| 650 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
| 651 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
| 652 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
| 650 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
| 651 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
| 652 | + $dataRefMap = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
| 653 | 653 | |
| 654 | - if ( $seg [ 'translation' ] == '' ) { |
|
| 654 | + if ($seg ['translation'] == '') { |
|
| 655 | 655 | $translation = $segment; |
| 656 | 656 | } else { |
| 657 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
| 658 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
| 659 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
| 657 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
| 658 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
| 659 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
| 660 | 660 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
| 661 | 661 | } |
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | // for xliff v2 we ignore the marks on purpose |
| 666 | - if ( $this->xliffVersion === 2 ) { |
|
| 666 | + if ($this->xliffVersion === 2) { |
|
| 667 | 667 | return $translation; |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
| 671 | - if ( $this->targetLang === 'ja-JP' ) { |
|
| 672 | - $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] ); |
|
| 670 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
| 671 | + if ($this->targetLang === 'ja-JP') { |
|
| 672 | + $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>"; |
|
| 675 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>"; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . $seg[ 'succ_tags' ]; |
|
| 678 | + $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . $seg['succ_tags']; |
|
| 679 | 679 | |
| 680 | 680 | return $transUnitTranslation; |
| 681 | 681 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | * |
| 688 | 688 | * @return string |
| 689 | 689 | */ |
| 690 | - private function getWordCountGroup( $raw_word_count, $eq_word_count ) { |
|
| 690 | + private function getWordCountGroup($raw_word_count, $eq_word_count) { |
|
| 691 | 691 | 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>"; |
| 692 | 692 | } |
| 693 | 693 | |
@@ -695,11 +695,11 @@ discard block |
||
| 695 | 695 | * @return array |
| 696 | 696 | */ |
| 697 | 697 | private function getCurrentSegment() { |
| 698 | - if ( $this->currentTransUnitTranslate === 'yes' && isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
| 699 | - $index = $this->transUnits[ $this->currentTransUnitId ][ $this->segmentPositionInTu ]; |
|
| 698 | + if ($this->currentTransUnitTranslate === 'yes' && isset($this->transUnits[$this->currentTransUnitId])) { |
|
| 699 | + $index = $this->transUnits[$this->currentTransUnitId][$this->segmentPositionInTu]; |
|
| 700 | 700 | |
| 701 | - if ( isset( $this->segments[ $index ] ) ) { |
|
| 702 | - return $this->segments[ $index ]; |
|
| 701 | + if (isset($this->segments[$index])) { |
|
| 702 | + return $this->segments[$index]; |
|
| 703 | 703 | } |
| 704 | 704 | } |
| 705 | 705 | |
@@ -714,21 +714,21 @@ discard block |
||
| 714 | 714 | * |
| 715 | 715 | * @return string |
| 716 | 716 | */ |
| 717 | - private function createTargetTag( $translation, $stateProp ) { |
|
| 717 | + private function createTargetTag($translation, $stateProp) { |
|
| 718 | 718 | |
| 719 | 719 | $targetLang = ''; |
| 720 | - if ( $this->xliffVersion === 1 ) { |
|
| 720 | + if ($this->xliffVersion === 1) { |
|
| 721 | 721 | $targetLang = ' xml:lang="' . $this->targetLang . '"'; |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - switch ( $this->xliffVersion ) { |
|
| 724 | + switch ($this->xliffVersion) { |
|
| 725 | 725 | case 1: |
| 726 | 726 | default: |
| 727 | 727 | $tag = "<target $targetLang $stateProp>$translation</target>"; |
| 728 | 728 | |
| 729 | 729 | // if it's a Trados file don't append count group |
| 730 | - if ( get_class( $this ) !== SdlXliffSAXTranslationReplacer::class ) { |
|
| 731 | - $tag .= $this->getWordCountGroup( $this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ] ); |
|
| 730 | + if (get_class($this) !== SdlXliffSAXTranslationReplacer::class) { |
|
| 731 | + $tag .= $this->getWordCountGroup($this->counts['raw_word_count'], $this->counts['eq_word_count']); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | return $tag; |
@@ -744,33 +744,33 @@ discard block |
||
| 744 | 744 | * |
| 745 | 745 | * @return string |
| 746 | 746 | */ |
| 747 | - private function getWordCountGroupForXliffV2( $withMetadataTag = true ) { |
|
| 747 | + private function getWordCountGroupForXliffV2($withMetadataTag = true) { |
|
| 748 | 748 | |
| 749 | 749 | $this->mdaGroupCounter++; |
| 750 | - $segments_count_array = $this->counts[ 'segments_count_array' ]; |
|
| 750 | + $segments_count_array = $this->counts['segments_count_array']; |
|
| 751 | 751 | |
| 752 | 752 | $id = $this->currentSegmentArray; |
| 753 | 753 | |
| 754 | 754 | |
| 755 | 755 | $return = ''; |
| 756 | 756 | |
| 757 | - if ( $withMetadataTag === true ) { |
|
| 757 | + if ($withMetadataTag === true) { |
|
| 758 | 758 | $return .= '<mda:metadata>'; |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | $index = 0; |
| 762 | - foreach ( $segments_count_array as $segments_count_item ) { |
|
| 762 | + foreach ($segments_count_array as $segments_count_item) { |
|
| 763 | 763 | |
| 764 | 764 | $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']'; |
| 765 | 765 | $index++; |
| 766 | 766 | |
| 767 | 767 | $return .= " <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\"> |
| 768 | - <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta> |
|
| 769 | - <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta> |
|
| 768 | + <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta> |
|
| 769 | + <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta> |
|
| 770 | 770 | </mda:metaGroup>"; |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - if ( $withMetadataTag === true ) { |
|
| 773 | + if ($withMetadataTag === true) { |
|
| 774 | 774 | $return .= '</mda:metadata>'; |
| 775 | 775 | } |
| 776 | 776 | |
@@ -785,25 +785,25 @@ discard block |
||
| 785 | 785 | * |
| 786 | 786 | * @return array |
| 787 | 787 | */ |
| 788 | - private function setTransUnitState( $seg, $state_prop, $lastMrkState ) { |
|
| 789 | - switch ( $seg[ 'status' ] ) { |
|
| 788 | + private function setTransUnitState($seg, $state_prop, $lastMrkState) { |
|
| 789 | + switch ($seg['status']) { |
|
| 790 | 790 | |
| 791 | 791 | case TranslationStatus::STATUS_FIXED: |
| 792 | 792 | case TranslationStatus::STATUS_APPROVED2: |
| 793 | - if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2 ) { |
|
| 793 | + if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2) { |
|
| 794 | 794 | $state_prop = "state=\"final\""; |
| 795 | 795 | $lastMrkState = TranslationStatus::STATUS_APPROVED2; |
| 796 | 796 | } |
| 797 | 797 | break; |
| 798 | 798 | case TranslationStatus::STATUS_APPROVED: |
| 799 | - if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
|
| 800 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\""; |
|
| 799 | + if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED) { |
|
| 800 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"reviewed\"" : "state=\"signed-off\""; |
|
| 801 | 801 | $lastMrkState = TranslationStatus::STATUS_APPROVED; |
| 802 | 802 | } |
| 803 | 803 | break; |
| 804 | 804 | |
| 805 | 805 | case TranslationStatus::STATUS_TRANSLATED: |
| 806 | - if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
|
| 806 | + if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED) { |
|
| 807 | 807 | $state_prop = "state=\"translated\""; |
| 808 | 808 | $lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
| 809 | 809 | } |
@@ -811,22 +811,22 @@ discard block |
||
| 811 | 811 | |
| 812 | 812 | 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 |
| 813 | 813 | case TranslationStatus::STATUS_REBUTTED: |
| 814 | - if ( ( $lastMrkState == null ) || ( $lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT ) ) { |
|
| 815 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\""; |
|
| 814 | + if (($lastMrkState == null) || ($lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT)) { |
|
| 815 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"needs-review-translation\""; |
|
| 816 | 816 | $lastMrkState = TranslationStatus::STATUS_REJECTED; |
| 817 | 817 | } |
| 818 | 818 | break; |
| 819 | 819 | |
| 820 | 820 | case TranslationStatus::STATUS_NEW: |
| 821 | - if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_NEW ) { |
|
| 822 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
|
| 821 | + if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_NEW) { |
|
| 822 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\""; |
|
| 823 | 823 | $lastMrkState = TranslationStatus::STATUS_NEW; |
| 824 | 824 | } |
| 825 | 825 | break; |
| 826 | 826 | |
| 827 | 827 | case TranslationStatus::STATUS_DRAFT: |
| 828 | - if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_DRAFT ) { |
|
| 829 | - $state_prop = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
|
| 828 | + if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_DRAFT) { |
|
| 829 | + $state_prop = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\""; |
|
| 830 | 830 | $lastMrkState = TranslationStatus::STATUS_DRAFT; |
| 831 | 831 | } |
| 832 | 832 | break; |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | // this is the case when a segment is not showed in cattool, so the row in |
| 836 | 836 | // segment_translations does not exists and |
| 837 | 837 | // ---> $seg[ 'status' ] is NULL |
| 838 | - if ( $lastMrkState == null ) { //this is the first MRK ID |
|
| 838 | + if ($lastMrkState == null) { //this is the first MRK ID |
|
| 839 | 839 | $state_prop = "state=\"translated\""; |
| 840 | 840 | $lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
| 841 | 841 | } else { |
@@ -844,17 +844,17 @@ discard block |
||
| 844 | 844 | break; |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | - return [ $state_prop, $lastMrkState ]; |
|
| 847 | + return [$state_prop, $lastMrkState]; |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | /** |
| 851 | 851 | * @inheritDoc |
| 852 | 852 | */ |
| 853 | - protected function characterData( $parser, $data ) { |
|
| 853 | + protected function characterData($parser, $data) { |
|
| 854 | 854 | // don't write <target> data |
| 855 | - if ( !$this->inTarget && !$this->bufferIsActive ) { |
|
| 856 | - $this->postProcAndFlush( $this->outputFP, $data ); |
|
| 857 | - } elseif ( $this->bufferIsActive ) { |
|
| 855 | + if (!$this->inTarget && !$this->bufferIsActive) { |
|
| 856 | + $this->postProcAndFlush($this->outputFP, $data); |
|
| 857 | + } elseif ($this->bufferIsActive) { |
|
| 858 | 858 | $this->CDATABuffer .= $data; |
| 859 | 859 | } |
| 860 | 860 | } |