TTMServerAid.php
Go to the documentation of this file.00001 <?php
00017 class TTMServerAid extends TranslationAid {
00018 public function getData() {
00019 $suggestions = array();
00020
00021 $text = $this->getDefinition();
00022 $from = $this->group->getSourceLanguage();
00023 $to = $this->handle->getCode();
00024
00025 global $wgTranslateTranslationServices;
00026 foreach ( $wgTranslateTranslationServices as $name => $config ) {
00027 $server = TTMServer::factory( $config );
00028
00029 try {
00030 if ( $server instanceof RemoteTTMServer ) {
00031 $service = TranslationWebService::factory( $name, $config );
00032 $query = $service->getSuggestions( array( $from => $text ), $from, $to );
00033 } elseif ( $server instanceof ReadableTTMServer ) {
00034 $query = $server->query( $from, $to, $text );
00035 } else {
00036 continue;
00037 }
00038 } catch ( Exception $e ) {
00039
00040 continue;
00041 }
00042
00043 foreach ( $query as $item ) {
00044 $item['service'] = $name;
00045 $item['source_language'] = $from;
00046 $item['local'] = $server->isLocalSuggestion( $item );
00047 $item['uri'] = $server->expandLocation( $item );
00048 $suggestions[] = $item;
00049 }
00050 }
00051
00052 $suggestions = TTMServer::sortSuggestions( $suggestions );
00053 $suggestions['**'] = 'suggestion';
00054
00055 return $suggestions;
00056 }
00057 }