Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApertiumCxserverWebService | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
handlePairsForService | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
handleServiceResponse | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getServiceName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\WebService; |
5 | |
6 | /** |
7 | * Implements support for Apertium translation service via the Cxserver API |
8 | * @ingroup TranslationWebService |
9 | * @author Niklas Laxström |
10 | * @license GPL-2.0-or-later |
11 | * @since 2015.02; renamed in 2023.06 |
12 | */ |
13 | class ApertiumCxserverWebService extends CxserverWebService { |
14 | // Exclusions per https://phabricator.wikimedia.org/T177434 |
15 | private const EXCLUDED_APERTIUM_TARGET_LANGUAGES = [ 'fr', 'es', 'nl' ]; |
16 | |
17 | protected function handlePairsForService( array $response ): array { |
18 | $pairs = []; |
19 | foreach ( $response[$this->getServiceName()] as $source => $targets ) { |
20 | $filteredTargets = array_diff( $targets, self::EXCLUDED_APERTIUM_TARGET_LANGUAGES ); |
21 | foreach ( $filteredTargets as $target ) { |
22 | $pairs[$source][$target] = true; |
23 | } |
24 | } |
25 | |
26 | return $pairs; |
27 | } |
28 | |
29 | protected function handleServiceResponse( array $responseBody ): string { |
30 | $text = $responseBody[ 'contents' ]; |
31 | if ( preg_match( '~^<div>(.*)</div>$~', $text ) ) { |
32 | $text = preg_replace( '~^<div>(.*)</div>$~', '\1', $text ); |
33 | } |
34 | |
35 | return trim( $this->unwrapUntranslatable( $text ) ); |
36 | } |
37 | |
38 | protected function getServiceName(): string { |
39 | return 'Apertium'; |
40 | } |
41 | } |