@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | * @return mixed |
70 | 70 | * @throws Exception |
71 | 71 | */ |
72 | - public function fromLayer0ToLayer2( $segment ) { |
|
72 | + public function fromLayer0ToLayer2($segment) { |
|
73 | 73 | return $this->fromLayer1ToLayer2( |
74 | - $this->fromLayer0ToLayer1( $segment ) |
|
74 | + $this->fromLayer0ToLayer1($segment) |
|
75 | 75 | ); |
76 | 76 | } |
77 | 77 | |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * @return mixed |
84 | 84 | * @throws Exception |
85 | 85 | */ |
86 | - public function fromLayer1ToLayer2( $segment ) { |
|
87 | - $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); |
|
88 | - $channel->addLast( new SpecialEntitiesToPlaceholdersForView() ); |
|
89 | - $channel->addLast( new EntityToEmoji() ); |
|
90 | - $channel->addLast( new DataRefReplace() ); |
|
86 | + public function fromLayer1ToLayer2($segment) { |
|
87 | + $channel = new Pipeline($this->source, $this->target, $this->dataRefMap); |
|
88 | + $channel->addLast(new SpecialEntitiesToPlaceholdersForView()); |
|
89 | + $channel->addLast(new EntityToEmoji()); |
|
90 | + $channel->addLast(new DataRefReplace()); |
|
91 | 91 | |
92 | 92 | /** @var $channel Pipeline */ |
93 | - $channel = $this->featureSet->filter( 'fromLayer1ToLayer2', $channel ); |
|
93 | + $channel = $this->featureSet->filter('fromLayer1ToLayer2', $channel); |
|
94 | 94 | |
95 | - return $channel->transform( $segment ); |
|
95 | + return $channel->transform($segment); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -103,20 +103,20 @@ discard block |
||
103 | 103 | * @return mixed |
104 | 104 | * @throws Exception |
105 | 105 | */ |
106 | - public function fromLayer2ToLayer1( $segment ) { |
|
107 | - $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); |
|
108 | - $channel->addLast( new CtrlCharsPlaceHoldToAscii() ); |
|
109 | - $channel->addLast( new PlaceHoldXliffTags() ); |
|
110 | - $channel->addLast( new FromLayer2TorawXML() ); |
|
111 | - $channel->addLast( new EmojiToEntity() ); |
|
112 | - $channel->addLast( new RestoreXliffTagsContent() ); |
|
113 | - $channel->addLast( new RestorePlaceHoldersToXLIFFLtGt() ); |
|
114 | - $channel->addLast( new DataRefRestore() ); |
|
106 | + public function fromLayer2ToLayer1($segment) { |
|
107 | + $channel = new Pipeline($this->source, $this->target, $this->dataRefMap); |
|
108 | + $channel->addLast(new CtrlCharsPlaceHoldToAscii()); |
|
109 | + $channel->addLast(new PlaceHoldXliffTags()); |
|
110 | + $channel->addLast(new FromLayer2TorawXML()); |
|
111 | + $channel->addLast(new EmojiToEntity()); |
|
112 | + $channel->addLast(new RestoreXliffTagsContent()); |
|
113 | + $channel->addLast(new RestorePlaceHoldersToXLIFFLtGt()); |
|
114 | + $channel->addLast(new DataRefRestore()); |
|
115 | 115 | |
116 | 116 | /** @var $channel Pipeline */ |
117 | - $channel = $this->featureSet->filter( 'fromLayer2ToLayer1', $channel ); |
|
117 | + $channel = $this->featureSet->filter('fromLayer2ToLayer1', $channel); |
|
118 | 118 | |
119 | - return $channel->transform( $segment ); |
|
119 | + return $channel->transform($segment); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @return mixed |
132 | 132 | * @throws Exception |
133 | 133 | */ |
134 | - public function fromLayer2ToLayer0( $segment ) { |
|
134 | + public function fromLayer2ToLayer0($segment) { |
|
135 | 135 | return $this->fromLayer1ToLayer0( |
136 | - $this->fromLayer2ToLayer1( $segment ) |
|
136 | + $this->fromLayer2ToLayer1($segment) |
|
137 | 137 | ); |
138 | 138 | } |
139 | 139 | |
@@ -145,31 +145,31 @@ discard block |
||
145 | 145 | * @return mixed |
146 | 146 | * @throws Exception |
147 | 147 | */ |
148 | - public function fromLayer0ToLayer1( $segment ) { |
|
149 | - $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); |
|
150 | - $channel->addLast( new StandardPHToMateCatCustomPH() ); |
|
151 | - $channel->addLast( new StandardXEquivTextToMateCatCustomPH() ); |
|
152 | - $channel->addLast( new PlaceHoldXliffTags() ); |
|
153 | - $channel->addLast( new LtGtDecode() ); |
|
154 | - $channel->addLast( new HtmlToPh() ); |
|
155 | - $channel->addLast( new Variables() ); |
|
156 | - $channel->addLast( new TwigToPh() ); |
|
157 | - $channel->addLast( new RubyOnRailsI18n() ); |
|
158 | - $channel->addLast( new Snails() ); |
|
159 | - $channel->addLast( new DoubleSquareBrackets() ); |
|
160 | - $channel->addLast( new DollarCurlyBrackets() ); |
|
161 | - $channel->addLast( new PercentNumberSnail() ); |
|
162 | - $channel->addLast( new Percentages() ); |
|
163 | - $channel->addLast( new SquareSprintf() ); |
|
164 | - $channel->addLast( new SprintfToPH() ); |
|
165 | - $channel->addLast( new RestoreXliffTagsContent() ); |
|
166 | - $channel->addLast( new RestorePlaceHoldersToXLIFFLtGt() ); |
|
167 | - $channel->addLast( new EquivTextToBase64() ); |
|
148 | + public function fromLayer0ToLayer1($segment) { |
|
149 | + $channel = new Pipeline($this->source, $this->target, $this->dataRefMap); |
|
150 | + $channel->addLast(new StandardPHToMateCatCustomPH()); |
|
151 | + $channel->addLast(new StandardXEquivTextToMateCatCustomPH()); |
|
152 | + $channel->addLast(new PlaceHoldXliffTags()); |
|
153 | + $channel->addLast(new LtGtDecode()); |
|
154 | + $channel->addLast(new HtmlToPh()); |
|
155 | + $channel->addLast(new Variables()); |
|
156 | + $channel->addLast(new TwigToPh()); |
|
157 | + $channel->addLast(new RubyOnRailsI18n()); |
|
158 | + $channel->addLast(new Snails()); |
|
159 | + $channel->addLast(new DoubleSquareBrackets()); |
|
160 | + $channel->addLast(new DollarCurlyBrackets()); |
|
161 | + $channel->addLast(new PercentNumberSnail()); |
|
162 | + $channel->addLast(new Percentages()); |
|
163 | + $channel->addLast(new SquareSprintf()); |
|
164 | + $channel->addLast(new SprintfToPH()); |
|
165 | + $channel->addLast(new RestoreXliffTagsContent()); |
|
166 | + $channel->addLast(new RestorePlaceHoldersToXLIFFLtGt()); |
|
167 | + $channel->addLast(new EquivTextToBase64()); |
|
168 | 168 | |
169 | 169 | /** @var $channel Pipeline */ |
170 | - $channel = $this->featureSet->filter( 'fromLayer0ToLayer1', $channel ); |
|
170 | + $channel = $this->featureSet->filter('fromLayer0ToLayer1', $channel); |
|
171 | 171 | |
172 | - return $channel->transform( $segment ); |
|
172 | + return $channel->transform($segment); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -180,21 +180,21 @@ discard block |
||
180 | 180 | * @return mixed |
181 | 181 | * @throws Exception |
182 | 182 | */ |
183 | - public function fromLayer1ToLayer0( $segment ) { |
|
184 | - $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); |
|
185 | - $channel->addLast( new MateCatCustomPHToOriginalValue() ); |
|
186 | - $channel->addLast( new PlaceHoldXliffTags() ); |
|
187 | - $channel->addLast( new EncodeToRawXML() ); |
|
188 | - $channel->addLast( new LtGtEncode() ); |
|
189 | - $channel->addLast( new RestoreXliffTagsContent() ); |
|
190 | - $channel->addLast( new RestorePlaceHoldersToXLIFFLtGt() ); |
|
191 | - $channel->addLast( new SplitPlaceholder() ); |
|
192 | - $channel->addLast( new RestoreEquivText() ); |
|
183 | + public function fromLayer1ToLayer0($segment) { |
|
184 | + $channel = new Pipeline($this->source, $this->target, $this->dataRefMap); |
|
185 | + $channel->addLast(new MateCatCustomPHToOriginalValue()); |
|
186 | + $channel->addLast(new PlaceHoldXliffTags()); |
|
187 | + $channel->addLast(new EncodeToRawXML()); |
|
188 | + $channel->addLast(new LtGtEncode()); |
|
189 | + $channel->addLast(new RestoreXliffTagsContent()); |
|
190 | + $channel->addLast(new RestorePlaceHoldersToXLIFFLtGt()); |
|
191 | + $channel->addLast(new SplitPlaceholder()); |
|
192 | + $channel->addLast(new RestoreEquivText()); |
|
193 | 193 | |
194 | 194 | /** @var $channel Pipeline */ |
195 | - $channel = $this->featureSet->filter( 'fromLayer1ToLayer0', $channel ); |
|
195 | + $channel = $this->featureSet->filter('fromLayer1ToLayer0', $channel); |
|
196 | 196 | |
197 | - return $channel->transform( $segment ); |
|
197 | + return $channel->transform($segment); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -205,18 +205,18 @@ discard block |
||
205 | 205 | * @return mixed |
206 | 206 | * @throws Exception |
207 | 207 | */ |
208 | - public function fromRawXliffToLayer0( $segment ) { |
|
209 | - $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); |
|
210 | - $channel->addLast( new RemoveDangerousChars() ); |
|
211 | - $channel->addLast( new PlaceHoldXliffTags() ); |
|
212 | - $channel->addLast( new EncodeControlCharsInXliff() ); |
|
213 | - $channel->addLast( new RestoreXliffTagsContent() ); |
|
214 | - $channel->addLast( new RestorePlaceHoldersToXLIFFLtGt() ); |
|
208 | + public function fromRawXliffToLayer0($segment) { |
|
209 | + $channel = new Pipeline($this->source, $this->target, $this->dataRefMap); |
|
210 | + $channel->addLast(new RemoveDangerousChars()); |
|
211 | + $channel->addLast(new PlaceHoldXliffTags()); |
|
212 | + $channel->addLast(new EncodeControlCharsInXliff()); |
|
213 | + $channel->addLast(new RestoreXliffTagsContent()); |
|
214 | + $channel->addLast(new RestorePlaceHoldersToXLIFFLtGt()); |
|
215 | 215 | |
216 | 216 | /** @var $channel Pipeline */ |
217 | - $channel = $this->featureSet->filter( 'fromRawXliffToLayer0', $channel ); |
|
217 | + $channel = $this->featureSet->filter('fromRawXliffToLayer0', $channel); |
|
218 | 218 | |
219 | - return $channel->transform( $segment ); |
|
219 | + return $channel->transform($segment); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -227,18 +227,18 @@ discard block |
||
227 | 227 | * @return mixed |
228 | 228 | * @throws Exception |
229 | 229 | */ |
230 | - public function fromLayer0ToRawXliff( $segment ) { |
|
231 | - $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); |
|
232 | - $channel->addLast( new PlaceHoldXliffTags() ); |
|
233 | - $channel->addLast( new RemoveDangerousChars() ); |
|
234 | - $channel->addLast( new RestoreXliffTagsContent() ); |
|
235 | - $channel->addLast( new RestorePlaceHoldersToXLIFFLtGt() ); |
|
236 | - $channel->addLast( new LtGtEncode() ); |
|
230 | + public function fromLayer0ToRawXliff($segment) { |
|
231 | + $channel = new Pipeline($this->source, $this->target, $this->dataRefMap); |
|
232 | + $channel->addLast(new PlaceHoldXliffTags()); |
|
233 | + $channel->addLast(new RemoveDangerousChars()); |
|
234 | + $channel->addLast(new RestoreXliffTagsContent()); |
|
235 | + $channel->addLast(new RestorePlaceHoldersToXLIFFLtGt()); |
|
236 | + $channel->addLast(new LtGtEncode()); |
|
237 | 237 | |
238 | 238 | /** @var $channel Pipeline */ |
239 | - $channel = $this->featureSet->filter( 'fromLayer0ToRawXliff', $channel ); |
|
239 | + $channel = $this->featureSet->filter('fromLayer0ToRawXliff', $channel); |
|
240 | 240 | |
241 | - return $channel->transform( $segment ); |
|
241 | + return $channel->transform($segment); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -256,37 +256,37 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return string |
258 | 258 | */ |
259 | - public function realignIDInLayer1( $source, $target ) { |
|
259 | + public function realignIDInLayer1($source, $target) { |
|
260 | 260 | $pattern = '|<ph id ?= ?["\'](mtc_[0-9]+)["\'] ?(equiv-text=["\'].+?["\'] ?)/>|ui'; |
261 | - preg_match_all( $pattern, $source, $src_tags, PREG_PATTERN_ORDER ); |
|
262 | - preg_match_all( $pattern, $target, $trg_tags, PREG_PATTERN_ORDER ); |
|
261 | + preg_match_all($pattern, $source, $src_tags, PREG_PATTERN_ORDER); |
|
262 | + preg_match_all($pattern, $target, $trg_tags, PREG_PATTERN_ORDER); |
|
263 | 263 | |
264 | - if ( count( $src_tags[ 0 ] ) != count( $trg_tags[ 0 ] ) ) { |
|
264 | + if (count($src_tags[0]) != count($trg_tags[0])) { |
|
265 | 265 | return $target; //WRONG NUMBER OF TAGS, in the translation there is a tag mismatch, let the user fix it |
266 | 266 | } |
267 | 267 | |
268 | 268 | $notFoundTargetTags = []; |
269 | 269 | |
270 | 270 | $start_offset = 0; |
271 | - foreach ( $trg_tags[ 2 ] as $trg_tag_position => $b64 ) { |
|
271 | + foreach ($trg_tags[2] as $trg_tag_position => $b64) { |
|
272 | 272 | |
273 | - $src_tag_position = array_search( $b64, $src_tags[ 2 ], true ); |
|
273 | + $src_tag_position = array_search($b64, $src_tags[2], true); |
|
274 | 274 | |
275 | - if ( $src_tag_position === false ) { |
|
275 | + if ($src_tag_position === false) { |
|
276 | 276 | //this means that the content of a tag is changed in the translation |
277 | - $notFoundTargetTags[ $trg_tag_position ] = $b64; |
|
277 | + $notFoundTargetTags[$trg_tag_position] = $b64; |
|
278 | 278 | continue; |
279 | 279 | } else { |
280 | - unset( $src_tags[ 2 ][ $src_tag_position ] ); // remove the index to allow array_search to find the equal next one if it is present |
|
280 | + unset($src_tags[2][$src_tag_position]); // remove the index to allow array_search to find the equal next one if it is present |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | //replace ONLY ONE element AND the EXACT ONE |
284 | - $tag_position_in_string = strpos( $target, $trg_tags[ 0 ][ $trg_tag_position ], $start_offset ); |
|
285 | - $target = substr_replace( $target, $src_tags[ 0 ][ $src_tag_position ], $tag_position_in_string, strlen( $trg_tags[ 0 ][ $trg_tag_position ] ) ); |
|
286 | - $start_offset = $tag_position_in_string + strlen( $src_tags[ 0 ][ $src_tag_position ] ); // set the next starting point |
|
284 | + $tag_position_in_string = strpos($target, $trg_tags[0][$trg_tag_position], $start_offset); |
|
285 | + $target = substr_replace($target, $src_tags[0][$src_tag_position], $tag_position_in_string, strlen($trg_tags[0][$trg_tag_position])); |
|
286 | + $start_offset = $tag_position_in_string + strlen($src_tags[0][$src_tag_position]); // set the next starting point |
|
287 | 287 | } |
288 | 288 | |
289 | - if ( !empty( $notFoundTargetTags ) ) { |
|
289 | + if (!empty($notFoundTargetTags)) { |
|
290 | 290 | //do something ?!? how to re-align if they are changed in value and changed in position? |
291 | 291 | } |
292 | 292 |
@@ -13,13 +13,13 @@ |
||
13 | 13 | |
14 | 14 | class EquivTextToBase64 extends AbstractHandler { |
15 | 15 | |
16 | - public function transform( $segment ) { |
|
16 | + public function transform($segment) { |
|
17 | 17 | |
18 | 18 | // extract equiv-text attribute |
19 | 19 | preg_match_all('/equiv-text=\"(.*?)\"/', $segment, $equiv_tags); |
20 | 20 | |
21 | - if(!empty($equiv_tags[0])){ |
|
22 | - foreach ($equiv_tags[0] as $index => $equiv_tag){ |
|
21 | + if (!empty($equiv_tags[0])) { |
|
22 | + foreach ($equiv_tags[0] as $index => $equiv_tag) { |
|
23 | 23 | $tag = $equiv_tags[1][$index]; |
24 | 24 | |
25 | 25 | if (strpos($tag, "base64:") === false) { |
@@ -15,9 +15,9 @@ |
||
15 | 15 | |
16 | 16 | class RestorePlaceHoldersToXLIFFLtGt extends AbstractHandler { |
17 | 17 | |
18 | - public function transform( $segment ) { |
|
19 | - $segment = str_replace( ConstantEnum::LTPLACEHOLDER, "<", $segment ); |
|
20 | - $segment = str_replace( ConstantEnum::GTPLACEHOLDER, ">", $segment ); |
|
18 | + public function transform($segment) { |
|
19 | + $segment = str_replace(ConstantEnum::LTPLACEHOLDER, "<", $segment); |
|
20 | + $segment = str_replace(ConstantEnum::GTPLACEHOLDER, ">", $segment); |
|
21 | 21 | |
22 | 22 | return $segment; |
23 | 23 | } |
@@ -13,13 +13,13 @@ |
||
13 | 13 | |
14 | 14 | class RestoreEquivText extends AbstractHandler { |
15 | 15 | |
16 | - public function transform( $segment ) { |
|
16 | + public function transform($segment) { |
|
17 | 17 | |
18 | 18 | // extract equiv-text attribute |
19 | 19 | preg_match_all('/equiv-text=\"(.*?)\"/', $segment, $equiv_tags); |
20 | 20 | |
21 | - if(!empty($equiv_tags[0])){ |
|
22 | - foreach ($equiv_tags[0] as $index => $equiv_tag){ |
|
21 | + if (!empty($equiv_tags[0])) { |
|
22 | + foreach ($equiv_tags[0] as $index => $equiv_tag) { |
|
23 | 23 | $tag = $equiv_tags[1][$index]; |
24 | 24 | |
25 | 25 | if (strpos($tag, "base64:") !== false) { |