@@ -16,38 +16,38 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @inheritDoc |
18 | 18 | */ |
19 | - protected function tagOpen( $parser, string $name, array $attr ) { |
|
19 | + protected function tagOpen($parser, string $name, array $attr) { |
|
20 | 20 | |
21 | - $this->handleOpenUnit( $name, $attr ); |
|
21 | + $this->handleOpenUnit($name, $attr); |
|
22 | 22 | |
23 | 23 | // check if we are entering into a <target> |
24 | - $this->checkSetInTarget( $name ); |
|
24 | + $this->checkSetInTarget($name); |
|
25 | 25 | |
26 | 26 | // reset Marker positions |
27 | - if ( 'sdl:seg-defs' == $name ) { |
|
27 | + if ('sdl:seg-defs' == $name) { |
|
28 | 28 | $this->segmentInUnitPosition = 0; |
29 | 29 | } |
30 | 30 | |
31 | 31 | // open buffer |
32 | - $this->setInBuffer( $name ); |
|
32 | + $this->setInBuffer($name); |
|
33 | 33 | |
34 | 34 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
35 | 35 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
36 | - if ( !$this->inTarget ) { |
|
36 | + if (!$this->inTarget) { |
|
37 | 37 | |
38 | 38 | // costruct tag |
39 | 39 | $tag = "<$name "; |
40 | 40 | |
41 | - foreach ( $attr as $k => $v ) { |
|
41 | + foreach ($attr as $k => $v) { |
|
42 | 42 | |
43 | 43 | // if tag name is file, we must replace the target-language attribute |
44 | - if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) { |
|
44 | + if ($name == 'file' && $k == 'target-language' && !empty($this->targetLang)) { |
|
45 | 45 | //replace Target language with job language provided from constructor |
46 | 46 | $tag .= "$k=\"$this->targetLang\" "; |
47 | 47 | } else { |
48 | 48 | //normal tag flux, put attributes in it |
49 | 49 | // Warning, this is NOT an elseif |
50 | - if ( $k != 'conf' ) { |
|
50 | + if ($k != 'conf') { |
|
51 | 51 | //put also the current attribute in it if it is not a "conf" attribute |
52 | 52 | $tag .= "$k=\"$v\" "; |
53 | 53 | } |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | |
57 | 57 | $seg = $this->getCurrentSegment(); |
58 | 58 | |
59 | - if ( 'sdl:seg' == $name && !empty( $seg ) && isset( $seg[ 'sid' ] ) ) { |
|
60 | - $tag .= $this->prepareTargetStatuses( $seg ); |
|
59 | + if ('sdl:seg' == $name && !empty($seg) && isset($seg['sid'])) { |
|
60 | + $tag .= $this->prepareTargetStatuses($seg); |
|
61 | 61 | } |
62 | 62 | |
63 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
63 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
64 | 64 | |
65 | 65 | } |
66 | 66 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - protected function prepareTargetStatuses( $segment ): string { |
|
74 | + protected function prepareTargetStatuses($segment): string { |
|
75 | 75 | $statusMap = [ |
76 | 76 | 'NEW' => '', |
77 | 77 | 'DRAFT' => 'Draft', |
@@ -81,19 +81,19 @@ discard block |
||
81 | 81 | 'REJECTED' => 'RejectedTranslation', |
82 | 82 | ]; |
83 | 83 | |
84 | - return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" "; |
|
84 | + return "conf=\"{$statusMap[$segment['status']]}\" "; |
|
85 | 85 | } |
86 | 86 | |
87 | - protected function rebuildMarks( array $seg, string $translation ): string { |
|
87 | + protected function rebuildMarks(array $seg, string $translation): string { |
|
88 | 88 | |
89 | - $trailingSpaces = str_repeat( ' ', Strings::getTheNumberOfTrailingSpaces( $translation ) ); |
|
89 | + $trailingSpaces = str_repeat(' ', Strings::getTheNumberOfTrailingSpaces($translation)); |
|
90 | 90 | |
91 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
92 | - if ( $this->targetLang === 'ja-JP' ) { |
|
93 | - $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] ); |
|
91 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
92 | + if ($this->targetLang === 'ja-JP') { |
|
93 | + $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']); |
|
94 | 94 | } |
95 | 95 | |
96 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim( $translation ) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces; |
|
96 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . rtrim($translation) . $seg['mrk_succ_tags'] . "</mrk>" . $trailingSpaces; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | return $translation; |
@@ -27,28 +27,28 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @inheritDoc |
29 | 29 | */ |
30 | - protected function tagOpen( $parser, string $name, array $attr ) { |
|
30 | + protected function tagOpen($parser, string $name, array $attr) { |
|
31 | 31 | |
32 | - $this->handleOpenUnit( $name, $attr ); |
|
32 | + $this->handleOpenUnit($name, $attr); |
|
33 | 33 | |
34 | - $this->checkSetInTarget( $name ); |
|
34 | + $this->checkSetInTarget($name); |
|
35 | 35 | |
36 | 36 | // open buffer |
37 | - $this->setInBuffer( $name ); |
|
37 | + $this->setInBuffer($name); |
|
38 | 38 | |
39 | 39 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
40 | 40 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
41 | - if ( !$this->inTarget ) { |
|
41 | + if (!$this->inTarget) { |
|
42 | 42 | |
43 | 43 | $tag = ''; |
44 | 44 | |
45 | 45 | // construct tag |
46 | 46 | $tag .= "<$name "; |
47 | 47 | |
48 | - foreach ( $attr as $k => $v ) { |
|
48 | + foreach ($attr as $k => $v) { |
|
49 | 49 | |
50 | 50 | //if tag name is file, we must replace the target-language attribute |
51 | - if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) { |
|
51 | + if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) { |
|
52 | 52 | //replace Target language with job language provided from constructor |
53 | 53 | $tag .= "$k=\"$this->targetLang\" "; |
54 | 54 | } else { |
@@ -59,20 +59,20 @@ discard block |
||
59 | 59 | |
60 | 60 | $seg = $this->getCurrentSegment(); |
61 | 61 | |
62 | - if ( $name === $this->tuTagName && !empty( $seg ) && isset( $seg[ 'sid' ] ) ) { |
|
62 | + if ($name === $this->tuTagName && !empty($seg) && isset($seg['sid'])) { |
|
63 | 63 | |
64 | 64 | // add `help-id` to xliff v.1* |
65 | - if ( strpos( $tag, 'help-id' ) === false ) { |
|
66 | - if ( !empty( $seg[ 'sid' ] ) ) { |
|
67 | - $tag .= "help-id=\"{$seg[ 'sid' ]}\" "; |
|
65 | + if (strpos($tag, 'help-id') === false) { |
|
66 | + if (!empty($seg['sid'])) { |
|
67 | + $tag .= "help-id=\"{$seg['sid']}\" "; |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | 71 | } |
72 | 72 | |
73 | - $tag = $this->handleOpenXliffTag( $name, $attr, $tag ); |
|
73 | + $tag = $this->handleOpenXliffTag($name, $attr, $tag); |
|
74 | 74 | |
75 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
75 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
76 | 76 | |
77 | 77 | } |
78 | 78 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * @inheritDoc |
84 | 84 | */ |
85 | - protected function tagClose( $parser, string $name ) { |
|
85 | + protected function tagClose($parser, string $name) { |
|
86 | 86 | $tag = ''; |
87 | 87 | |
88 | 88 | /** |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * |
92 | 92 | * self::tagOpen method |
93 | 93 | */ |
94 | - if ( !$this->isEmpty ) { |
|
94 | + if (!$this->isEmpty) { |
|
95 | 95 | |
96 | - if ( !$this->inTarget ) { |
|
96 | + if (!$this->inTarget) { |
|
97 | 97 | $tag = "</$name>"; |
98 | 98 | } |
99 | 99 | |
100 | - if ( 'target' == $name ) { |
|
100 | + if ('target' == $name) { |
|
101 | 101 | |
102 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
102 | + if (isset($this->transUnits[$this->currentTransUnitId])) { |
|
103 | 103 | |
104 | 104 | // get translation of current segment, by indirect indexing: id -> positional index -> segment |
105 | 105 | // actually there may be more than one segment to that ID if there are two mrk of the same source segment |
@@ -110,42 +110,42 @@ discard block |
||
110 | 110 | $this->targetWasWritten = true; |
111 | 111 | // signal we are leaving a target |
112 | 112 | $this->inTarget = false; |
113 | - $this->postProcAndFlush( $this->outputFP, $tag, true ); |
|
113 | + $this->postProcAndFlush($this->outputFP, $tag, true); |
|
114 | 114 | |
115 | - } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
|
115 | + } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section |
|
116 | 116 | |
117 | 117 | $this->bufferIsActive = false; |
118 | 118 | $tag = $this->CDATABuffer . "</$name>"; |
119 | 119 | $this->CDATABuffer = ""; |
120 | 120 | |
121 | 121 | //flush to the pointer |
122 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
122 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
123 | 123 | |
124 | - } elseif ( $name === $this->tuTagName ) { |
|
124 | + } elseif ($name === $this->tuTagName) { |
|
125 | 125 | |
126 | 126 | $tag = ""; |
127 | 127 | |
128 | 128 | // handling </trans-unit> closure |
129 | - if ( !$this->targetWasWritten ) { |
|
129 | + if (!$this->targetWasWritten) { |
|
130 | 130 | |
131 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
131 | + if (isset($this->transUnits[$this->currentTransUnitId])) { |
|
132 | 132 | $tag = $this->rebuildTarget(); |
133 | 133 | } else { |
134 | - $tag = $this->createTargetTag( "", "" ); |
|
134 | + $tag = $this->createTargetTag("", ""); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | } |
138 | 138 | |
139 | - $tag .= "</$this->tuTagName>"; |
|
139 | + $tag .= "</$this->tuTagName>"; |
|
140 | 140 | $this->targetWasWritten = false; |
141 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
141 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
142 | 142 | |
143 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
143 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
144 | 144 | $this->CDATABuffer .= "</$name>"; |
145 | 145 | // Do NOT Flush |
146 | 146 | } else { //generic tag closure do Nothing |
147 | 147 | // flush to pointer |
148 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
148 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | } else { |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
157 | - if ( $this->tuTagName === $name ) { |
|
157 | + if ($this->tuTagName === $name) { |
|
158 | 158 | $this->currentTransUnitIsTranslatable = null; |
159 | 159 | $this->inTU = false; |
160 | 160 | $this->hasWrittenCounts = false; |
@@ -171,31 +171,31 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return string |
173 | 173 | */ |
174 | - protected function prepareTranslation( array $seg, string $transUnitTranslation = "" ): string { |
|
174 | + protected function prepareTranslation(array $seg, string $transUnitTranslation = ""): string { |
|
175 | 175 | |
176 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
177 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
176 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
177 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
178 | 178 | |
179 | - if ( $seg [ 'translation' ] == '' ) { |
|
179 | + if ($seg ['translation'] == '') { |
|
180 | 180 | $translation = $segment; |
181 | 181 | } else { |
182 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
183 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
184 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, [], $error ) ) { |
|
182 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
183 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
184 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, [], $error)) { |
|
185 | 185 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
186 | 186 | } |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | - $transUnitTranslation .= $seg[ 'prev_tags' ] . $this->rebuildMarks( $seg, $translation ) . ltrim( $seg[ 'succ_tags' ] ); |
|
190 | + $transUnitTranslation .= $seg['prev_tags'] . $this->rebuildMarks($seg, $translation) . ltrim($seg['succ_tags']); |
|
191 | 191 | |
192 | 192 | return $transUnitTranslation; |
193 | 193 | } |
194 | 194 | |
195 | - protected function rebuildMarks( array $seg, string $translation ): string { |
|
195 | + protected function rebuildMarks(array $seg, string $translation): string { |
|
196 | 196 | |
197 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
198 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>"; |
|
197 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
198 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>"; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | return $translation; |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return string |
212 | 212 | */ |
213 | - private function createTargetTag( string $translation, string $stateProp ): string { |
|
213 | + private function createTargetTag(string $translation, string $stateProp): string { |
|
214 | 214 | $targetLang = ' xml:lang="' . $this->targetLang . '"'; |
215 | 215 | $tag = "<target $targetLang $stateProp>$translation</target>"; |
216 | - $tag .= "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">" . $this->counts[ 'raw_word_count' ] . "</count><count count-type=\"x-matecat-weighted\">" . $this->counts[ 'eq_word_count' ] . '</count></count-group>'; |
|
216 | + $tag .= "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">" . $this->counts['raw_word_count'] . "</count><count count-type=\"x-matecat-weighted\">" . $this->counts['eq_word_count'] . '</count></count-group>'; |
|
217 | 217 | |
218 | 218 | return $tag; |
219 | 219 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | // we must reset the lastMrkId found because this is a new segment. |
230 | 230 | $lastMrkId = -1; |
231 | 231 | |
232 | - foreach ( $this->lastTransUnit as $pos => $seg ) { |
|
232 | + foreach ($this->lastTransUnit as $pos => $seg) { |
|
233 | 233 | |
234 | 234 | /* |
235 | 235 | * This routine works to respect the positional orders of markers. |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | * pre-assign zero to the new mrk if this is the first one ( in this segment ) |
243 | 243 | * If it is null leave it NULL |
244 | 244 | */ |
245 | - if ( (int)$seg[ "mrk_id" ] < 0 && $seg[ "mrk_id" ] !== null ) { |
|
246 | - $seg[ "mrk_id" ] = 0; |
|
245 | + if ((int)$seg["mrk_id"] < 0 && $seg["mrk_id"] !== null) { |
|
246 | + $seg["mrk_id"] = 0; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /* |
@@ -252,33 +252,33 @@ discard block |
||
252 | 252 | * ( null <= -1 ) === true |
253 | 253 | * so, cast to int |
254 | 254 | */ |
255 | - if ( (int)$seg[ "mrk_id" ] <= $lastMrkId ) { |
|
255 | + if ((int)$seg["mrk_id"] <= $lastMrkId) { |
|
256 | 256 | break; |
257 | 257 | } |
258 | 258 | |
259 | 259 | // update counts |
260 | - if ( !empty( $seg ) ) { |
|
261 | - $this->updateSegmentCounts( $seg ); |
|
260 | + if (!empty($seg)) { |
|
261 | + $this->updateSegmentCounts($seg); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | // delete translations so the prepareSegment |
265 | 265 | // will put source content in target tag |
266 | - if ( $this->sourceInTarget ) { |
|
267 | - $seg[ 'translation' ] = ''; |
|
266 | + if ($this->sourceInTarget) { |
|
267 | + $seg['translation'] = ''; |
|
268 | 268 | $this->resetCounts(); |
269 | 269 | } |
270 | 270 | |
271 | 271 | // append $translation |
272 | - $translation = $this->prepareTranslation( $seg, $translation ); |
|
272 | + $translation = $this->prepareTranslation($seg, $translation); |
|
273 | 273 | |
274 | - $lastMrkId = $seg[ "mrk_id" ]; |
|
274 | + $lastMrkId = $seg["mrk_id"]; |
|
275 | 275 | |
276 | - [ $stateProp, $lastMrkState ] = StatusToStateAttribute::getState( $this->xliffVersion, $seg[ 'status' ], $lastMrkState ); |
|
276 | + [$stateProp, $lastMrkState] = StatusToStateAttribute::getState($this->xliffVersion, $seg['status'], $lastMrkState); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
280 | 280 | //append translation |
281 | - return $this->createTargetTag( $translation, $stateProp ); |
|
281 | + return $this->createTargetTag($translation, $stateProp); |
|
282 | 282 | |
283 | 283 | } |
284 | 284 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @var bool |
22 | 22 | */ |
23 | - protected bool $unitContainsMda = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*) |
|
23 | + protected bool $unitContainsMda = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*) |
|
24 | 24 | /** |
25 | 25 | * @var array |
26 | 26 | */ |
@@ -35,22 +35,22 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @inheritDoc |
37 | 37 | */ |
38 | - protected function tagOpen( $parser, string $name, array $attr ) { |
|
38 | + protected function tagOpen($parser, string $name, array $attr) { |
|
39 | 39 | |
40 | - $this->handleOpenUnit( $name, $attr ); |
|
40 | + $this->handleOpenUnit($name, $attr); |
|
41 | 41 | |
42 | - if ( 'mda:metadata' === $name ) { |
|
42 | + if ('mda:metadata' === $name) { |
|
43 | 43 | $this->unitContainsMda = true; |
44 | 44 | } |
45 | 45 | |
46 | - $this->checkSetInTarget( $name ); |
|
46 | + $this->checkSetInTarget($name); |
|
47 | 47 | |
48 | 48 | // open buffer |
49 | - $this->setInBuffer( $name ); |
|
49 | + $this->setInBuffer($name); |
|
50 | 50 | |
51 | 51 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
52 | 52 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
53 | - if ( !$this->inTarget ) { |
|
53 | + if (!$this->inTarget) { |
|
54 | 54 | |
55 | 55 | $tag = ''; |
56 | 56 | |
@@ -72,48 +72,48 @@ discard block |
||
72 | 72 | // |
73 | 73 | // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit |
74 | 74 | // |
75 | - if ( in_array( $name, [ 'notes', 'originalData', 'segment', 'ignorable' ] ) && |
|
75 | + if (in_array($name, ['notes', 'originalData', 'segment', 'ignorable']) && |
|
76 | 76 | $this->unitContainsMda === false && |
77 | - !empty( $this->transUnits[ $this->currentTransUnitId ] ) && |
|
77 | + !empty($this->transUnits[$this->currentTransUnitId]) && |
|
78 | 78 | !$this->hasWrittenCounts |
79 | 79 | ) { |
80 | 80 | // we need to update counts here |
81 | 81 | $this->updateCounts(); |
82 | 82 | $this->hasWrittenCounts = true; |
83 | - $tag .= $this->getWordCountGroupForXliffV2(); |
|
83 | + $tag .= $this->getWordCountGroupForXliffV2(); |
|
84 | 84 | $this->unitContainsMda = true; |
85 | 85 | } |
86 | 86 | |
87 | 87 | // construct tag |
88 | 88 | $tag .= "<$name "; |
89 | 89 | |
90 | - foreach ( $attr as $k => $v ) { |
|
90 | + foreach ($attr as $k => $v) { |
|
91 | 91 | //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute |
92 | - if ( $k != 'state' ) { |
|
92 | + if ($k != 'state') { |
|
93 | 93 | $tag .= "$k=\"$v\" "; |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | 97 | $seg = $this->getCurrentSegment(); |
98 | 98 | |
99 | - if ( $name === $this->tuTagName && !empty( $seg ) && isset( $seg[ 'sid' ] ) ) { |
|
99 | + if ($name === $this->tuTagName && !empty($seg) && isset($seg['sid'])) { |
|
100 | 100 | |
101 | 101 | // add `mtc:segment-id` to xliff v.2* |
102 | - if ( strpos( $tag, 'mtc:segment-id' ) === false ) { |
|
103 | - $tag .= "mtc:segment-id=\"{$seg[ 'sid' ]}\" "; |
|
102 | + if (strpos($tag, 'mtc:segment-id') === false) { |
|
103 | + $tag .= "mtc:segment-id=\"{$seg['sid']}\" "; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | } |
107 | 107 | |
108 | 108 | // replace state for xliff v2 |
109 | - if ( 'segment' === $name ) { // add state to segment in Xliff v2 |
|
110 | - [ $stateProp, ] = StatusToStateAttribute::getState( $this->xliffVersion, $seg[ 'status' ] ); |
|
109 | + if ('segment' === $name) { // add state to segment in Xliff v2 |
|
110 | + [$stateProp, ] = StatusToStateAttribute::getState($this->xliffVersion, $seg['status']); |
|
111 | 111 | $tag .= $stateProp; |
112 | 112 | } |
113 | 113 | |
114 | - $tag = $this->handleOpenXliffTag( $name, $attr, $tag ); |
|
114 | + $tag = $this->handleOpenXliffTag($name, $attr, $tag); |
|
115 | 115 | |
116 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
116 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - protected function handleOpenXliffTag( string $name, array $attr, string $tag ): string { |
|
130 | - $tag = parent::handleOpenXliffTag( $name, $attr, $tag ); |
|
129 | + protected function handleOpenXliffTag(string $name, array $attr, string $tag): string { |
|
130 | + $tag = parent::handleOpenXliffTag($name, $attr, $tag); |
|
131 | 131 | // add oasis xliff 20 namespace |
132 | - if ( $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) { |
|
132 | + if ($name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) { |
|
133 | 133 | $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"'; |
134 | 134 | } |
135 | 135 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | /** |
140 | 140 | * @inheritDoc |
141 | 141 | */ |
142 | - protected function tagClose( $parser, string $name ) { |
|
142 | + protected function tagClose($parser, string $name) { |
|
143 | 143 | $tag = ''; |
144 | 144 | |
145 | 145 | /** |
@@ -148,32 +148,32 @@ discard block |
||
148 | 148 | * |
149 | 149 | * self::tagOpen method |
150 | 150 | */ |
151 | - if ( !$this->isEmpty ) { |
|
151 | + if (!$this->isEmpty) { |
|
152 | 152 | |
153 | - if ( !$this->inTarget ) { |
|
153 | + if (!$this->inTarget) { |
|
154 | 154 | $tag = "</$name>"; |
155 | 155 | } |
156 | 156 | |
157 | - if ( 'target' == $name ) { |
|
157 | + if ('target' == $name) { |
|
158 | 158 | |
159 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
159 | + if (isset($this->transUnits[$this->currentTransUnitId])) { |
|
160 | 160 | |
161 | 161 | $seg = $this->getCurrentSegment(); |
162 | 162 | |
163 | 163 | // update counts |
164 | - if ( !$this->hasWrittenCounts && !empty( $seg ) ) { |
|
165 | - $this->updateSegmentCounts( $seg ); |
|
164 | + if (!$this->hasWrittenCounts && !empty($seg)) { |
|
165 | + $this->updateSegmentCounts($seg); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // delete translations so the prepareSegment |
169 | 169 | // will put source content in target tag |
170 | - if ( $this->sourceInTarget ) { |
|
171 | - $seg[ 'translation' ] = ''; |
|
170 | + if ($this->sourceInTarget) { |
|
171 | + $seg['translation'] = ''; |
|
172 | 172 | $this->resetCounts(); |
173 | 173 | } |
174 | 174 | |
175 | 175 | // append $translation |
176 | - $translation = $this->prepareTranslation( $seg ); |
|
176 | + $translation = $this->prepareTranslation($seg); |
|
177 | 177 | |
178 | 178 | //append translation |
179 | 179 | $tag = "<target>$translation</target>"; |
@@ -183,22 +183,22 @@ discard block |
||
183 | 183 | // signal we are leaving a target |
184 | 184 | $this->targetWasWritten = true; |
185 | 185 | $this->inTarget = false; |
186 | - $this->postProcAndFlush( $this->outputFP, $tag, true ); |
|
186 | + $this->postProcAndFlush($this->outputFP, $tag, true); |
|
187 | 187 | |
188 | - } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
|
188 | + } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section |
|
189 | 189 | |
190 | 190 | $this->bufferIsActive = false; |
191 | 191 | |
192 | 192 | // only for Xliff 2.* |
193 | 193 | // write here <mda:metaGroup> and <mda:meta> if already present in the <unit> |
194 | - if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) { |
|
194 | + if ('mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts) { |
|
195 | 195 | |
196 | 196 | // we need to update counts here |
197 | 197 | $this->updateCounts(); |
198 | 198 | $this->hasWrittenCounts = true; |
199 | 199 | |
200 | 200 | $tag = $this->CDATABuffer; |
201 | - $tag .= $this->getWordCountGroupForXliffV2( false ); |
|
201 | + $tag .= $this->getWordCountGroupForXliffV2(false); |
|
202 | 202 | $tag .= " </mda:metadata>"; |
203 | 203 | |
204 | 204 | } else { |
@@ -208,19 +208,19 @@ discard block |
||
208 | 208 | $this->CDATABuffer = ""; |
209 | 209 | |
210 | 210 | //flush to the pointer |
211 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
211 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
212 | 212 | |
213 | - } elseif ( 'segment' === $name ) { |
|
213 | + } elseif ('segment' === $name) { |
|
214 | 214 | |
215 | 215 | // only for Xliff 2.* |
216 | 216 | // if segment has no <target> add it BEFORE </segment> |
217 | - if ( !$this->targetWasWritten ) { |
|
217 | + if (!$this->targetWasWritten) { |
|
218 | 218 | |
219 | 219 | $seg = $this->getCurrentSegment(); |
220 | 220 | |
221 | - if ( isset( $seg[ 'translation' ] ) ) { |
|
221 | + if (isset($seg['translation'])) { |
|
222 | 222 | |
223 | - $translation = $this->prepareTranslation( $seg ); |
|
223 | + $translation = $this->prepareTranslation($seg); |
|
224 | 224 | // replace the tag |
225 | 225 | $tag = "<target>$translation</target>"; |
226 | 226 | |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | // update segmentPositionInTu |
234 | 234 | $this->segmentInUnitPosition++; |
235 | 235 | |
236 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
236 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
237 | 237 | |
238 | 238 | // we are leaving <segment>, reset $segmentHasTarget |
239 | 239 | $this->targetWasWritten = false; |
240 | 240 | |
241 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
241 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
242 | 242 | $this->CDATABuffer .= "</$name>"; |
243 | 243 | // Do NOT Flush |
244 | 244 | } else { //generic tag closure do Nothing |
245 | 245 | // flush to pointer |
246 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
246 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
247 | 247 | } |
248 | 248 | } else { |
249 | 249 | //ok, nothing to be done; reset flag for next coming tag |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | } |
252 | 252 | |
253 | 253 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
254 | - if ( $this->tuTagName === $name ) { |
|
254 | + if ($this->tuTagName === $name) { |
|
255 | 255 | $this->currentTransUnitIsTranslatable = null; |
256 | 256 | $this->inTU = false; |
257 | 257 | $this->unitContainsMda = false; |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | private function updateCounts() { |
268 | 268 | |
269 | 269 | $seg = $this->getCurrentSegment(); |
270 | - if ( !empty( $seg ) ) { |
|
271 | - $this->updateSegmentCounts( $seg ); |
|
270 | + if (!empty($seg)) { |
|
271 | + $this->updateSegmentCounts($seg); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | } |
@@ -278,30 +278,30 @@ discard block |
||
278 | 278 | * |
279 | 279 | * @return string |
280 | 280 | */ |
281 | - private function getWordCountGroupForXliffV2( bool $withMetadataTag = true ): string { |
|
281 | + private function getWordCountGroupForXliffV2(bool $withMetadataTag = true): string { |
|
282 | 282 | |
283 | 283 | $this->mdaGroupCounter++; |
284 | - $segments_count_array = $this->counts[ 'segments_count_array' ]; |
|
284 | + $segments_count_array = $this->counts['segments_count_array']; |
|
285 | 285 | |
286 | 286 | $tag = ''; |
287 | 287 | |
288 | - if ( $withMetadataTag === true ) { |
|
288 | + if ($withMetadataTag === true) { |
|
289 | 289 | $tag .= '<mda:metadata>'; |
290 | 290 | } |
291 | 291 | |
292 | 292 | $index = 0; |
293 | - foreach ( $segments_count_array as $segments_count_item ) { |
|
293 | + foreach ($segments_count_array as $segments_count_item) { |
|
294 | 294 | |
295 | 295 | $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']'; |
296 | 296 | $index++; |
297 | 297 | |
298 | 298 | $tag .= " <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\"> |
299 | - <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta> |
|
300 | - <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta> |
|
299 | + <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta> |
|
300 | + <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta> |
|
301 | 301 | </mda:metaGroup>"; |
302 | 302 | } |
303 | 303 | |
304 | - if ( $withMetadataTag === true ) { |
|
304 | + if ($withMetadataTag === true) { |
|
305 | 305 | $tag .= '</mda:metadata>'; |
306 | 306 | } |
307 | 307 | |
@@ -316,18 +316,18 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return string |
318 | 318 | */ |
319 | - protected function prepareTranslation( array $seg ): string { |
|
319 | + protected function prepareTranslation(array $seg): string { |
|
320 | 320 | |
321 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
322 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
323 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
321 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
322 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
323 | + $dataRefMap = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
324 | 324 | |
325 | - if ( $seg [ 'translation' ] == '' ) { |
|
325 | + if ($seg ['translation'] == '') { |
|
326 | 326 | $translation = $segment; |
327 | 327 | } else { |
328 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
329 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
330 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
328 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
329 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
330 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
331 | 331 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
332 | 332 | } |
333 | 333 | } |