ApiTTMServer.php

Go to the documentation of this file.
00001 <?php
00017 class ApiTTMServer extends ApiBase {
00018 
00019     public function execute() {
00020         global $wgTranslateTranslationServices;
00021         $params = $this->extractRequestParams();
00022 
00023         $config = $wgTranslateTranslationServices[$params['service']];
00024         $server = TTMServer::factory( $config );
00025 
00026         $suggestions = $server->query(
00027             $params['sourcelanguage'],
00028             $params['targetlanguage'],
00029             $params['text']
00030         );
00031 
00032         $result = $this->getResult();
00033         foreach ( $suggestions as $sug ) {
00034             $sug['location'] = $server->expandLocation( $sug );
00035             unset( $sug['wiki'] );
00036             $result->addValue( $this->getModuleName(), null, $sug );
00037         }
00038 
00039         $result->setIndexedTagName_internal( $this->getModuleName(), 'suggestion' );
00040     }
00041 
00042     protected function getAvailableTranslationServices() {
00043         global $wgTranslateTranslationServices;
00044 
00045         $good = array();
00046         foreach ( $wgTranslateTranslationServices as $id => $config ) {
00047             if ( isset( $config['public'] ) && $config['public'] === true ) {
00048                 $good[] = $id;
00049             }
00050         }
00051 
00052         return $good;
00053     }
00054 
00055     public function getAllowedParams() {
00056         $available = $this->getAvailableTranslationServices();
00057 
00058         return array(
00059             'service' => array(
00060                 ApiBase::PARAM_TYPE => $available,
00061                 ApiBase::PARAM_DFLT => 'TTMServer',
00062             ),
00063             'sourcelanguage' => array(
00064                 ApiBase::PARAM_TYPE => 'string',
00065                 ApiBase::PARAM_REQUIRED => true,
00066             ),
00067             'targetlanguage' => array(
00068                 ApiBase::PARAM_TYPE => 'string',
00069                 ApiBase::PARAM_REQUIRED => true,
00070             ),
00071             'text' => array(
00072                 ApiBase::PARAM_TYPE => 'string',
00073                 ApiBase::PARAM_REQUIRED => true,
00074             ),
00075         );
00076     }
00077 
00078     public function getParamDescription() {
00079         return array(
00080             'service' => 'Which of the available translation services to use.',
00081             'sourcelanguage' => 'A language code of the source text',
00082             'targetlanguage' => 'A language code of the suggestion',
00083             'text' => 'The text to find suggestions for',
00084         );
00085     }
00086 
00087     public function getDescription() {
00088         return 'Query suggestions from translation memories';
00089     }
00090 
00091     public function getExamples() {
00092         return array(
00093             'api.php?action=ttmserver&sourcelanguage=en&targetlanguage=fi&text=Help',
00094         );
00095     }
00096 
00097     public function getVersion() {
00098         return __CLASS__ . ': ' . TRANSLATE_VERSION;
00099     }
00100 }
Generated on Tue Oct 29 00:00:23 2013 for MediaWiki Translate Extension by  doxygen 1.6.3