23 public function __construct() {
24 parent::__construct();
25 $this->addDescription(
'Test webservices.' );
29 'Which service to use',
36 'Source language tag',
43 'Target language tag',
53 $this->requireExtension(
'Translate' );
56 public function execute() {
57 global $wgTranslateTranslationServices;
59 $name = $this->getOption(
'service' );
61 if ( !isset( $wgTranslateTranslationServices[ $name ] ) ) {
62 $this->fatalError(
"Unknown service.\n" );
65 $service = TranslationWebService::factory( $name, $wgTranslateTranslationServices[ $name ] );
67 $this->output(
"$msg\n" );
70 $from = $this->getOption(
'from' );
71 $to = $this->getOption(
'to' );
72 $text = $this->getArg( 0 );
74 if ( !$service->isSupportedLanguagePair( $from, $to ) ) {
75 $this->fatalError(
"Unsupported language pair.\n" );
78 $query = $service->getQueries( $text, $from, $to );
79 if ( $query === [] ) {
80 $this->fatalError(
"Service query error.\n" );
84 $id = $agg->addQuery( $query[ 0 ] );
86 $res = $agg->getResponse( $id );
88 $this->output( $service->getResultData( $res ), 1 );