24 private const CONSTRUCTOR_OPTIONS = [
26 'TranslateTranslationDefaultService',
27 'TranslateTranslationServices',
30 public function __construct(
36 parent::__construct( $mainModule, $moduleName );
37 $this->options =
new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $config );
40 public function execute():
void {
41 if ( !$this->getAvailableTranslationServices() ) {
42 $this->dieWithError(
'apierror-translate-notranslationservices' );
45 $params = $this->extractRequestParams();
47 $server = $this->ttmServerFactory->create( $params[
'service' ] );
49 $this->dieWithError(
'apierror-translate-notranslationservices' );
52 $suggestions = $server->query(
53 $params[
'sourcelanguage'],
54 $params[
'targetlanguage'],
58 $result = $this->getResult();
59 foreach ( $suggestions as $sug ) {
60 $sug[
'location'] = $server->expandLocation( $sug );
61 unset( $sug[
'wiki'] );
62 $result->addValue( $this->getModuleName(),
null, $sug );
65 $result->addIndexedTagName( $this->getModuleName(),
'suggestion' );
68 private function getAvailableTranslationServices(): array {
69 $translationServices = $this->options->get(
'TranslateTranslationServices' );
72 foreach ( $translationServices as $id => $config ) {
73 $public = $config[
'public'] ??
false;
74 if ( $config[
'type'] ===
'ttmserver' && $public ) {
82 protected function getAllowedParams(): array {
83 $available = $this->getAvailableTranslationServices();
87 ParamValidator::PARAM_TYPE => $available,
90 ParamValidator::PARAM_TYPE =>
'string',
91 ParamValidator::PARAM_REQUIRED =>
true,
94 ParamValidator::PARAM_TYPE =>
'string',
95 ParamValidator::PARAM_REQUIRED =>
true,
98 ParamValidator::PARAM_TYPE =>
'string',
99 ParamValidator::PARAM_REQUIRED =>
true,
106 $ret[
'service'][ParamValidator::PARAM_DEFAULT] =
107 $this->options->get(
'TranslateTranslationDefaultService' );
113 protected function getExamplesMessages(): array {
115 'action=ttmserver&sourcelanguage=en&targetlanguage=fi&text=Help'
116 =>
'apihelp-ttmserver-example-1',