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