@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | ?string $lastMrkState = null |
27 | 27 | ): array { |
28 | 28 | |
29 | - $status = empty( $status ) ? TranslationStatus::STATUS_TRANSLATED : $status; |
|
29 | + $status = empty($status) ? TranslationStatus::STATUS_TRANSLATED : $status; |
|
30 | 30 | |
31 | 31 | $stateLevelsMap = [ |
32 | 32 | TranslationStatus::STATUS_APPROVED2 => 100, |
@@ -37,26 +37,26 @@ discard block |
||
37 | 37 | TranslationStatus::STATUS_NEW => 50 |
38 | 38 | ]; |
39 | 39 | |
40 | - $orderedValues = array_flip( $stateLevelsMap ); |
|
40 | + $orderedValues = array_flip($stateLevelsMap); |
|
41 | 41 | |
42 | 42 | // Define state mappings for different statuses |
43 | 43 | $stateMap = [ |
44 | - TranslationStatus::STATUS_APPROVED2 => [ "state=\"final\"", TranslationStatus::STATUS_APPROVED2 ], |
|
44 | + TranslationStatus::STATUS_APPROVED2 => ["state=\"final\"", TranslationStatus::STATUS_APPROVED2], |
|
45 | 45 | TranslationStatus::STATUS_APPROVED => [ |
46 | - ( $xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\"", |
|
46 | + ($xliffVersion === 2) ? "state=\"reviewed\"" : "state=\"signed-off\"", |
|
47 | 47 | TranslationStatus::STATUS_APPROVED |
48 | 48 | ], |
49 | - TranslationStatus::STATUS_TRANSLATED => [ "state=\"translated\"", TranslationStatus::STATUS_TRANSLATED ], |
|
49 | + TranslationStatus::STATUS_TRANSLATED => ["state=\"translated\"", TranslationStatus::STATUS_TRANSLATED], |
|
50 | 50 | TranslationStatus::STATUS_REJECTED => [ |
51 | - ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\"", |
|
51 | + ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"needs-review-translation\"", |
|
52 | 52 | TranslationStatus::STATUS_REJECTED |
53 | 53 | ], |
54 | 54 | TranslationStatus::STATUS_NEW => [ |
55 | - ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"", |
|
55 | + ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"", |
|
56 | 56 | TranslationStatus::STATUS_NEW |
57 | 57 | ], |
58 | 58 | TranslationStatus::STATUS_DRAFT => [ |
59 | - ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"", |
|
59 | + ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"", |
|
60 | 60 | TranslationStatus::STATUS_DRAFT |
61 | 61 | ], |
62 | 62 | ]; |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | // ---> $seg[ 'status' ] is NULL |
68 | 68 | // If lastMrkState is empty |
69 | 69 | $minStatus = min( |
70 | - $stateLevelsMap[ $status ], |
|
71 | - ( $stateLevelsMap[ $lastMrkState ] ?? $stateLevelsMap[ TranslationStatus::STATUS_NEW ] ) |
|
70 | + $stateLevelsMap[$status], |
|
71 | + ($stateLevelsMap[$lastMrkState] ?? $stateLevelsMap[TranslationStatus::STATUS_NEW]) |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | // If the last mark state is set, get the minimum value, otherwise get the current state |
75 | - [ $state_prop, $lastMrkState ] = empty( $lastMrkState ) ? $stateMap[ $status ] : $stateMap[ $orderedValues[ $minStatus ] ]; |
|
75 | + [$state_prop, $lastMrkState] = empty($lastMrkState) ? $stateMap[$status] : $stateMap[$orderedValues[$minStatus]]; |
|
76 | 76 | |
77 | - return [ $state_prop, $lastMrkState ]; |
|
77 | + return [$state_prop, $lastMrkState]; |
|
78 | 78 | |
79 | 79 | } |
80 | 80 |
@@ -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 ) and isset( $seg[ 'sid' ] ) ) { |
|
62 | + if ($name === $this->tuTagName && !empty($seg) and 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 | |
@@ -73,48 +73,48 @@ discard block |
||
73 | 73 | // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit |
74 | 74 | // |
75 | 75 | if ( |
76 | - ( $name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable' ) && |
|
76 | + ($name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') && |
|
77 | 77 | $this->unitContainsMda === false && |
78 | - !empty( $this->transUnits[ $this->currentTransUnitId ] ) && |
|
78 | + !empty($this->transUnits[$this->currentTransUnitId]) && |
|
79 | 79 | !$this->hasWrittenCounts |
80 | 80 | ) { |
81 | 81 | // we need to update counts here |
82 | 82 | $this->updateCounts(); |
83 | 83 | $this->hasWrittenCounts = true; |
84 | - $tag .= $this->getWordCountGroupForXliffV2(); |
|
84 | + $tag .= $this->getWordCountGroupForXliffV2(); |
|
85 | 85 | $this->unitContainsMda = true; |
86 | 86 | } |
87 | 87 | |
88 | 88 | // construct tag |
89 | 89 | $tag .= "<$name "; |
90 | 90 | |
91 | - foreach ( $attr as $k => $v ) { |
|
91 | + foreach ($attr as $k => $v) { |
|
92 | 92 | //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute |
93 | - if ( $k != 'state' ) { |
|
93 | + if ($k != 'state') { |
|
94 | 94 | $tag .= "$k=\"$v\" "; |
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | 98 | $seg = $this->getCurrentSegment(); |
99 | 99 | |
100 | - if ( $name === $this->tuTagName and !empty( $seg ) and isset( $seg[ 'sid' ] ) ) { |
|
100 | + if ($name === $this->tuTagName and !empty($seg) and isset($seg['sid'])) { |
|
101 | 101 | |
102 | 102 | // add `mtc:segment-id` to xliff v.2* |
103 | - if ( strpos( $tag, 'mtc:segment-id' ) === false ) { |
|
104 | - $tag .= "mtc:segment-id=\"{$seg[ 'sid' ]}\" "; |
|
103 | + if (strpos($tag, 'mtc:segment-id') === false) { |
|
104 | + $tag .= "mtc:segment-id=\"{$seg['sid']}\" "; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } |
108 | 108 | |
109 | 109 | // replace state for xliff v2 |
110 | - if ( 'segment' === $name ) { // add state to segment in Xliff v2 |
|
111 | - [ $stateProp, ] = StatusToStateAttribute::getState( $this->xliffVersion, $seg[ 'status' ] ); |
|
110 | + if ('segment' === $name) { // add state to segment in Xliff v2 |
|
111 | + [$stateProp, ] = StatusToStateAttribute::getState($this->xliffVersion, $seg['status']); |
|
112 | 112 | $tag .= $stateProp; |
113 | 113 | } |
114 | 114 | |
115 | - $tag = $this->handleOpenXliffTag( $name, $attr, $tag ); |
|
115 | + $tag = $this->handleOpenXliffTag($name, $attr, $tag); |
|
116 | 116 | |
117 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
117 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | * |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - protected function handleOpenXliffTag( string $name, array $attr, string $tag ): string { |
|
131 | - $tag = parent::handleOpenXliffTag( $name, $attr, $tag ); |
|
130 | + protected function handleOpenXliffTag(string $name, array $attr, string $tag): string { |
|
131 | + $tag = parent::handleOpenXliffTag($name, $attr, $tag); |
|
132 | 132 | // add oasis xliff 20 namespace |
133 | - if ( $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) { |
|
133 | + if ($name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) { |
|
134 | 134 | $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"'; |
135 | 135 | } |
136 | 136 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | /** |
141 | 141 | * @inheritDoc |
142 | 142 | */ |
143 | - protected function tagClose( $parser, string $name ) { |
|
143 | + protected function tagClose($parser, string $name) { |
|
144 | 144 | $tag = ''; |
145 | 145 | |
146 | 146 | /** |
@@ -149,32 +149,32 @@ discard block |
||
149 | 149 | * |
150 | 150 | * self::tagOpen method |
151 | 151 | */ |
152 | - if ( !$this->isEmpty ) { |
|
152 | + if (!$this->isEmpty) { |
|
153 | 153 | |
154 | - if ( !$this->inTarget ) { |
|
154 | + if (!$this->inTarget) { |
|
155 | 155 | $tag = "</$name>"; |
156 | 156 | } |
157 | 157 | |
158 | - if ( 'target' == $name ) { |
|
158 | + if ('target' == $name) { |
|
159 | 159 | |
160 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
160 | + if (isset($this->transUnits[$this->currentTransUnitId])) { |
|
161 | 161 | |
162 | 162 | $seg = $this->getCurrentSegment(); |
163 | 163 | |
164 | 164 | // update counts |
165 | - if ( !$this->hasWrittenCounts && !empty( $seg ) ) { |
|
166 | - $this->updateSegmentCounts( $seg ); |
|
165 | + if (!$this->hasWrittenCounts && !empty($seg)) { |
|
166 | + $this->updateSegmentCounts($seg); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // delete translations so the prepareSegment |
170 | 170 | // will put source content in target tag |
171 | - if ( $this->sourceInTarget ) { |
|
172 | - $seg[ 'translation' ] = ''; |
|
171 | + if ($this->sourceInTarget) { |
|
172 | + $seg['translation'] = ''; |
|
173 | 173 | $this->resetCounts(); |
174 | 174 | } |
175 | 175 | |
176 | 176 | // append $translation |
177 | - $translation = $this->prepareTranslation( $seg ); |
|
177 | + $translation = $this->prepareTranslation($seg); |
|
178 | 178 | |
179 | 179 | //append translation |
180 | 180 | $tag = "<target>$translation</target>"; |
@@ -184,22 +184,22 @@ discard block |
||
184 | 184 | // signal we are leaving a target |
185 | 185 | $this->targetWasWritten = true; |
186 | 186 | $this->inTarget = false; |
187 | - $this->postProcAndFlush( $this->outputFP, $tag, true ); |
|
187 | + $this->postProcAndFlush($this->outputFP, $tag, true); |
|
188 | 188 | |
189 | - } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
|
189 | + } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section |
|
190 | 190 | |
191 | 191 | $this->bufferIsActive = false; |
192 | 192 | |
193 | 193 | // only for Xliff 2.* |
194 | 194 | // write here <mda:metaGroup> and <mda:meta> if already present in the <unit> |
195 | - if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) { |
|
195 | + if ('mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts) { |
|
196 | 196 | |
197 | 197 | // we need to update counts here |
198 | 198 | $this->updateCounts(); |
199 | 199 | $this->hasWrittenCounts = true; |
200 | 200 | |
201 | 201 | $tag = $this->CDATABuffer; |
202 | - $tag .= $this->getWordCountGroupForXliffV2( false ); |
|
202 | + $tag .= $this->getWordCountGroupForXliffV2(false); |
|
203 | 203 | $tag .= " </mda:metadata>"; |
204 | 204 | |
205 | 205 | } else { |
@@ -209,19 +209,19 @@ discard block |
||
209 | 209 | $this->CDATABuffer = ""; |
210 | 210 | |
211 | 211 | //flush to the pointer |
212 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
212 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
213 | 213 | |
214 | - } elseif ( 'segment' === $name ) { |
|
214 | + } elseif ('segment' === $name) { |
|
215 | 215 | |
216 | 216 | // only for Xliff 2.* |
217 | 217 | // if segment has no <target> add it BEFORE </segment> |
218 | - if ( !$this->targetWasWritten ) { |
|
218 | + if (!$this->targetWasWritten) { |
|
219 | 219 | |
220 | 220 | $seg = $this->getCurrentSegment(); |
221 | 221 | |
222 | - if ( isset( $seg[ 'translation' ] ) ) { |
|
222 | + if (isset($seg['translation'])) { |
|
223 | 223 | |
224 | - $translation = $this->prepareTranslation( $seg ); |
|
224 | + $translation = $this->prepareTranslation($seg); |
|
225 | 225 | // replace the tag |
226 | 226 | $tag = "<target>$translation</target>"; |
227 | 227 | |
@@ -234,17 +234,17 @@ discard block |
||
234 | 234 | // update segmentPositionInTu |
235 | 235 | $this->segmentInUnitPosition++; |
236 | 236 | |
237 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
237 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
238 | 238 | |
239 | 239 | // we are leaving <segment>, reset $segmentHasTarget |
240 | 240 | $this->targetWasWritten = false; |
241 | 241 | |
242 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
242 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
243 | 243 | $this->CDATABuffer .= "</$name>"; |
244 | 244 | // Do NOT Flush |
245 | 245 | } else { //generic tag closure do Nothing |
246 | 246 | // flush to pointer |
247 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
247 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
248 | 248 | } |
249 | 249 | } else { |
250 | 250 | //ok, nothing to be done; reset flag for next coming tag |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
255 | - if ( $this->tuTagName === $name ) { |
|
255 | + if ($this->tuTagName === $name) { |
|
256 | 256 | $this->currentTransUnitIsTranslatable = null; |
257 | 257 | $this->inTU = false; |
258 | 258 | $this->unitContainsMda = false; |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | private function updateCounts() { |
269 | 269 | |
270 | 270 | $seg = $this->getCurrentSegment(); |
271 | - if ( !empty( $seg ) ) { |
|
272 | - $this->updateSegmentCounts( $seg ); |
|
271 | + if (!empty($seg)) { |
|
272 | + $this->updateSegmentCounts($seg); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | } |
@@ -279,30 +279,30 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return string |
281 | 281 | */ |
282 | - private function getWordCountGroupForXliffV2( bool $withMetadataTag = true ): string { |
|
282 | + private function getWordCountGroupForXliffV2(bool $withMetadataTag = true): string { |
|
283 | 283 | |
284 | 284 | $this->mdaGroupCounter++; |
285 | - $segments_count_array = $this->counts[ 'segments_count_array' ]; |
|
285 | + $segments_count_array = $this->counts['segments_count_array']; |
|
286 | 286 | |
287 | 287 | $tag = ''; |
288 | 288 | |
289 | - if ( $withMetadataTag === true ) { |
|
289 | + if ($withMetadataTag === true) { |
|
290 | 290 | $tag .= '<mda:metadata>'; |
291 | 291 | } |
292 | 292 | |
293 | 293 | $index = 0; |
294 | - foreach ( $segments_count_array as $segments_count_item ) { |
|
294 | + foreach ($segments_count_array as $segments_count_item) { |
|
295 | 295 | |
296 | 296 | $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']'; |
297 | 297 | $index++; |
298 | 298 | |
299 | 299 | $tag .= " <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\"> |
300 | - <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta> |
|
301 | - <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta> |
|
300 | + <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta> |
|
301 | + <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta> |
|
302 | 302 | </mda:metaGroup>"; |
303 | 303 | } |
304 | 304 | |
305 | - if ( $withMetadataTag === true ) { |
|
305 | + if ($withMetadataTag === true) { |
|
306 | 306 | $tag .= '</mda:metadata>'; |
307 | 307 | } |
308 | 308 | |
@@ -317,18 +317,18 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @return string |
319 | 319 | */ |
320 | - protected function prepareTranslation( array $seg ): string { |
|
320 | + protected function prepareTranslation(array $seg): string { |
|
321 | 321 | |
322 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
323 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
324 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
322 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
323 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
324 | + $dataRefMap = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
325 | 325 | |
326 | - if ( $seg [ 'translation' ] == '' ) { |
|
326 | + if ($seg ['translation'] == '') { |
|
327 | 327 | $translation = $segment; |
328 | 328 | } else { |
329 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
330 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
331 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
329 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
330 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
331 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
332 | 332 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
333 | 333 | } |
334 | 334 | } |