@@ -12,5 +12,5 @@ |
||
12 | 12 | * |
13 | 13 | * @return bool |
14 | 14 | */ |
15 | - public function thereAreErrors( int $segmentId, string $segment, string $translation, ?array $dataRefMap = [], ?string $error = null ): bool; |
|
15 | + public function thereAreErrors(int $segmentId, string $segment, string $translation, ?array $dataRefMap = [], ?string $error = null): bool; |
|
16 | 16 | } |
@@ -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( $seg[ 'status' ], $this->xliffVersion, $stateProp, $lastMrkState ); |
|
276 | + [$stateProp, $lastMrkState] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion, $stateProp, $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 |
@@ -32,22 +32,22 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @inheritDoc |
34 | 34 | */ |
35 | - protected function tagOpen( $parser, string $name, array $attr ) { |
|
35 | + protected function tagOpen($parser, string $name, array $attr) { |
|
36 | 36 | |
37 | - $this->handleOpenUnit( $name, $attr ); |
|
37 | + $this->handleOpenUnit($name, $attr); |
|
38 | 38 | |
39 | - if ( 'mda:metadata' === $name ) { |
|
39 | + if ('mda:metadata' === $name) { |
|
40 | 40 | $this->unitContainsMda = true; |
41 | 41 | } |
42 | 42 | |
43 | - $this->checkSetInTarget( $name ); |
|
43 | + $this->checkSetInTarget($name); |
|
44 | 44 | |
45 | 45 | // open buffer |
46 | - $this->setInBuffer( $name ); |
|
46 | + $this->setInBuffer($name); |
|
47 | 47 | |
48 | 48 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
49 | 49 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
50 | - if ( !$this->inTarget ) { |
|
50 | + if (!$this->inTarget) { |
|
51 | 51 | |
52 | 52 | $tag = ''; |
53 | 53 | |
@@ -70,48 +70,48 @@ discard block |
||
70 | 70 | // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit |
71 | 71 | // |
72 | 72 | if ( |
73 | - ( $name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable' ) && |
|
73 | + ($name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') && |
|
74 | 74 | $this->unitContainsMda === false && |
75 | - !empty( $this->transUnits[ $this->currentTransUnitId ] ) && |
|
75 | + !empty($this->transUnits[$this->currentTransUnitId]) && |
|
76 | 76 | !$this->hasWrittenCounts |
77 | 77 | ) { |
78 | 78 | // we need to update counts here |
79 | 79 | $this->updateCounts(); |
80 | 80 | $this->hasWrittenCounts = true; |
81 | - $tag .= $this->getWordCountGroupForXliffV2(); |
|
81 | + $tag .= $this->getWordCountGroupForXliffV2(); |
|
82 | 82 | $this->unitContainsMda = true; |
83 | 83 | } |
84 | 84 | |
85 | 85 | // construct tag |
86 | 86 | $tag .= "<$name "; |
87 | 87 | |
88 | - foreach ( $attr as $k => $v ) { |
|
88 | + foreach ($attr as $k => $v) { |
|
89 | 89 | //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute |
90 | - if ( $k != 'state' ) { |
|
90 | + if ($k != 'state') { |
|
91 | 91 | $tag .= "$k=\"$v\" "; |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | $seg = $this->getCurrentSegment(); |
96 | 96 | |
97 | - if ( $name === $this->tuTagName and !empty( $seg ) and isset( $seg[ 'sid' ] ) ) { |
|
97 | + if ($name === $this->tuTagName and !empty($seg) and isset($seg['sid'])) { |
|
98 | 98 | |
99 | 99 | // add `mtc:segment-id` to xliff v.2* |
100 | - if ( strpos( $tag, 'mtc:segment-id' ) === false ) { |
|
101 | - $tag .= "mtc:segment-id=\"{$seg[ 'sid' ]}\" "; |
|
100 | + if (strpos($tag, 'mtc:segment-id') === false) { |
|
101 | + $tag .= "mtc:segment-id=\"{$seg['sid']}\" "; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |
105 | 105 | |
106 | 106 | // replace state for xliff v2 |
107 | - if ( 'segment' === $name ) { // add state to segment in Xliff v2 |
|
108 | - [ $stateProp, ] = StatusToStateAttribute::getState( $seg[ 'status' ], $this->xliffVersion ); |
|
107 | + if ('segment' === $name) { // add state to segment in Xliff v2 |
|
108 | + [$stateProp, ] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion); |
|
109 | 109 | $tag .= $stateProp; |
110 | 110 | } |
111 | 111 | |
112 | - $tag = $this->handleOpenXliffTag( $name, $attr, $tag ); |
|
112 | + $tag = $this->handleOpenXliffTag($name, $attr, $tag); |
|
113 | 113 | |
114 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
114 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
115 | 115 | |
116 | 116 | } |
117 | 117 | |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return string |
126 | 126 | */ |
127 | - protected function handleOpenXliffTag( string $name, array $attr, string $tag ): string { |
|
128 | - $tag = parent::handleOpenXliffTag( $name, $attr, $tag ); |
|
127 | + protected function handleOpenXliffTag(string $name, array $attr, string $tag): string { |
|
128 | + $tag = parent::handleOpenXliffTag($name, $attr, $tag); |
|
129 | 129 | // add oasis xliff 20 namespace |
130 | - if ( $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) { |
|
130 | + if ($name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) { |
|
131 | 131 | $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"'; |
132 | 132 | } |
133 | 133 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * @inheritDoc |
139 | 139 | */ |
140 | - protected function tagClose( $parser, string $name ) { |
|
140 | + protected function tagClose($parser, string $name) { |
|
141 | 141 | $tag = ''; |
142 | 142 | |
143 | 143 | /** |
@@ -146,32 +146,32 @@ discard block |
||
146 | 146 | * |
147 | 147 | * self::tagOpen method |
148 | 148 | */ |
149 | - if ( !$this->isEmpty ) { |
|
149 | + if (!$this->isEmpty) { |
|
150 | 150 | |
151 | - if ( !$this->inTarget ) { |
|
151 | + if (!$this->inTarget) { |
|
152 | 152 | $tag = "</$name>"; |
153 | 153 | } |
154 | 154 | |
155 | - if ( 'target' == $name ) { |
|
155 | + if ('target' == $name) { |
|
156 | 156 | |
157 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) && $this->currentTransUnitIsTranslatable !== 'no' ) { |
|
157 | + if (isset($this->transUnits[$this->currentTransUnitId]) && $this->currentTransUnitIsTranslatable !== 'no') { |
|
158 | 158 | |
159 | 159 | $seg = $this->getCurrentSegment(); |
160 | 160 | |
161 | 161 | // update counts |
162 | - if ( !$this->hasWrittenCounts && !empty( $seg ) ) { |
|
163 | - $this->updateSegmentCounts( $seg ); |
|
162 | + if (!$this->hasWrittenCounts && !empty($seg)) { |
|
163 | + $this->updateSegmentCounts($seg); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | // delete translations so the prepareSegment |
167 | 167 | // will put source content in target tag |
168 | - if ( $this->sourceInTarget ) { |
|
169 | - $seg[ 'translation' ] = ''; |
|
168 | + if ($this->sourceInTarget) { |
|
169 | + $seg['translation'] = ''; |
|
170 | 170 | $this->resetCounts(); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // append $translation |
174 | - $translation = $this->prepareTranslation( $seg ); |
|
174 | + $translation = $this->prepareTranslation($seg); |
|
175 | 175 | |
176 | 176 | //append translation |
177 | 177 | $tag = "<target>$translation</target>"; |
@@ -181,22 +181,22 @@ discard block |
||
181 | 181 | // signal we are leaving a target |
182 | 182 | $this->targetWasWritten = true; |
183 | 183 | $this->inTarget = false; |
184 | - $this->postProcAndFlush( $this->outputFP, $tag, true ); |
|
184 | + $this->postProcAndFlush($this->outputFP, $tag, true); |
|
185 | 185 | |
186 | - } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
|
186 | + } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section |
|
187 | 187 | |
188 | 188 | $this->bufferIsActive = false; |
189 | 189 | |
190 | 190 | // only for Xliff 2.* |
191 | 191 | // write here <mda:metaGroup> and <mda:meta> if already present in the <unit> |
192 | - if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) { |
|
192 | + if ('mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts) { |
|
193 | 193 | |
194 | 194 | // we need to update counts here |
195 | 195 | $this->updateCounts(); |
196 | 196 | $this->hasWrittenCounts = true; |
197 | 197 | |
198 | 198 | $tag = $this->CDATABuffer; |
199 | - $tag .= $this->getWordCountGroupForXliffV2( false ); |
|
199 | + $tag .= $this->getWordCountGroupForXliffV2(false); |
|
200 | 200 | $tag .= " </mda:metadata>"; |
201 | 201 | |
202 | 202 | } else { |
@@ -206,19 +206,19 @@ discard block |
||
206 | 206 | $this->CDATABuffer = ""; |
207 | 207 | |
208 | 208 | //flush to the pointer |
209 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
209 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
210 | 210 | |
211 | - } elseif ( 'segment' === $name ) { |
|
211 | + } elseif ('segment' === $name) { |
|
212 | 212 | |
213 | 213 | // only for Xliff 2.* |
214 | 214 | // if segment has no <target> add it BEFORE </segment> |
215 | - if ( !$this->targetWasWritten ) { |
|
215 | + if (!$this->targetWasWritten) { |
|
216 | 216 | |
217 | 217 | $seg = $this->getCurrentSegment(); |
218 | 218 | |
219 | - if ( isset( $seg[ 'translation' ] ) ) { |
|
219 | + if (isset($seg['translation'])) { |
|
220 | 220 | |
221 | - $translation = $this->prepareTranslation( $seg ); |
|
221 | + $translation = $this->prepareTranslation($seg); |
|
222 | 222 | // replace the tag |
223 | 223 | $tag = "<target>$translation</target>"; |
224 | 224 | |
@@ -231,17 +231,17 @@ discard block |
||
231 | 231 | // update segmentPositionInTu |
232 | 232 | $this->segmentInUnitPosition++; |
233 | 233 | |
234 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
234 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
235 | 235 | |
236 | 236 | // we are leaving <segment>, reset $segmentHasTarget |
237 | 237 | $this->targetWasWritten = false; |
238 | 238 | |
239 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
239 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
240 | 240 | $this->CDATABuffer .= "</$name>"; |
241 | 241 | // Do NOT Flush |
242 | 242 | } else { //generic tag closure do Nothing |
243 | 243 | // flush to pointer |
244 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
244 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
245 | 245 | } |
246 | 246 | } else { |
247 | 247 | //ok, nothing to be done; reset flag for next coming tag |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | } |
250 | 250 | |
251 | 251 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
252 | - if ( $this->tuTagName === $name ) { |
|
252 | + if ($this->tuTagName === $name) { |
|
253 | 253 | $this->currentTransUnitIsTranslatable = null; |
254 | 254 | $this->inTU = false; |
255 | 255 | $this->unitContainsMda = false; |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | private function updateCounts() { |
266 | 266 | |
267 | 267 | $seg = $this->getCurrentSegment(); |
268 | - if ( !empty( $seg ) ) { |
|
269 | - $this->updateSegmentCounts( $seg ); |
|
268 | + if (!empty($seg)) { |
|
269 | + $this->updateSegmentCounts($seg); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | } |
@@ -276,30 +276,30 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return string |
278 | 278 | */ |
279 | - private function getWordCountGroupForXliffV2( bool $withMetadataTag = true ): string { |
|
279 | + private function getWordCountGroupForXliffV2(bool $withMetadataTag = true): string { |
|
280 | 280 | |
281 | 281 | $this->mdaGroupCounter++; |
282 | - $segments_count_array = $this->counts[ 'segments_count_array' ]; |
|
282 | + $segments_count_array = $this->counts['segments_count_array']; |
|
283 | 283 | |
284 | 284 | $tag = ''; |
285 | 285 | |
286 | - if ( $withMetadataTag === true ) { |
|
286 | + if ($withMetadataTag === true) { |
|
287 | 287 | $tag .= '<mda:metadata>'; |
288 | 288 | } |
289 | 289 | |
290 | 290 | $index = 0; |
291 | - foreach ( $segments_count_array as $segments_count_item ) { |
|
291 | + foreach ($segments_count_array as $segments_count_item) { |
|
292 | 292 | |
293 | 293 | $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']'; |
294 | 294 | $index++; |
295 | 295 | |
296 | 296 | $tag .= " <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\"> |
297 | - <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta> |
|
298 | - <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta> |
|
297 | + <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta> |
|
298 | + <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta> |
|
299 | 299 | </mda:metaGroup>"; |
300 | 300 | } |
301 | 301 | |
302 | - if ( $withMetadataTag === true ) { |
|
302 | + if ($withMetadataTag === true) { |
|
303 | 303 | $tag .= '</mda:metadata>'; |
304 | 304 | } |
305 | 305 | |
@@ -314,18 +314,18 @@ discard block |
||
314 | 314 | * |
315 | 315 | * @return string |
316 | 316 | */ |
317 | - protected function prepareTranslation( array $seg ): string { |
|
317 | + protected function prepareTranslation(array $seg): string { |
|
318 | 318 | |
319 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
320 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
321 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
319 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
320 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
321 | + $dataRefMap = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
322 | 322 | |
323 | - if ( $seg [ 'translation' ] == '' ) { |
|
323 | + if ($seg ['translation'] == '') { |
|
324 | 324 | $translation = $segment; |
325 | 325 | } else { |
326 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
327 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
328 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
326 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
327 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
328 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
329 | 329 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
330 | 330 | } |
331 | 331 | } |