Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
ApertiumCxserverWebService.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\WebService;
5
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}
Implements support for Apertium translation service via the Cxserver API.
Used for interacting with translation services supported by Cxserver.
unwrapUntranslatable(string $text)
Undo the hopyfully untouched mangling done by wrapUntranslatable.