summaryrefslogtreecommitdiff
blob: dee7680dafc1cdfd2c0ca1eb7af6e95fdff80cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
 * Translation aid provider.
 *
 * @file
 * @author Niklas Laxström
 * @copyright Copyright © 2012-2013, Niklas Laxström
 * @license GPL-2.0+
 */

/**
 * Translation aid which gives suggestion from machine translation services.
 *
 * @ingroup TranslationAids
 * @since 2013-01-01
 */
class MachineTranslationAid extends TranslationAid {
	public function getData() {
		$suggestions = array( '**' => 'suggestion' );

		$translations = $this->getTranslations();
		$from = $this->group->getSourceLanguage();
		$to = $this->handle->getCode();

		global $wgTranslateTranslationServices;
		foreach ( $wgTranslateTranslationServices as $name => $config ) {
			if ( $config['type'] === 'ttmserver' ) {
				continue;
			}

			$service = TranslationWebService::factory( $name, $config );
			if ( !$service ) {
				continue;
			}

			$results = $service->getSuggestions( $translations, $from, $to );
			$suggestions = array_merge( $suggestions, $results );
		}

		return $suggestions;
	}
}