Jump to content

Topic on Extension talk:Translate

Debug machine translation services, translation aids (Yandex mt service)

6
Summary by Nikerabbit

Tracked in Phab:T178895

Andreas Plank (talkcontribs)

Hi,

I've installed Translate extension (MLEB 2017.07, MW 1.28.2) and configured the machine translation service for Yandex according to documentation but I get no api activity or network activity whatsoever. If I call the translation aid http://localhost/w/api.php?action=translationaids&format=json&title=Translations:Test-Übersetzung/2/en I get a proper json but the mt array is always empty. When I activate debug logs I get an error message (by Yandex I guess “Unsupported Media Type” see https://tech.yandex.com/market/partner/doc/dg/concepts/error-codes-docpage/):

…
[translationservices] Translation service Yandex problem: Unsupported Media Type
[DBPerformance] Expectation (writes <= 0) by ApiMain::setRequestExpectations not met:
query-m: REPLACE INTO `objectcache` (keyname,value,exptime) VALUES ('X')
#0 /usr/share/mediawiki/includes/libs/rdbms/TransactionProfiler.php(215): TransactionProfiler->reportExpectationViolated('writes', 'query-m: REPLAC...')
#1 /usr/share/mediawiki/includes/libs/rdbms/database/Database.php(959): TransactionProfiler->recordQueryCompletion('query-m: REPLAC...', 1508407232.3874, true, 1)
#2 /usr/share/mediawiki/includes/libs/rdbms/database/Database.php(870): Database->doProfiledQuery('REPLACE INTO `o...', 'REPLACE /* SqlB...', true, 'SqlBagOStuff::s...')
#3 /usr/share/mediawiki/includes/libs/rdbms/database/Database.php(2162): Database->query('REPLACE INTO `o...', 'SqlBagOStuff::s...')
#4 /usr/share/mediawiki/includes/libs/rdbms/database/DatabaseMysqlBase.php(486): Database->nativeReplace('objectcache', Array, 'SqlBagOStuff::s...')
#5 /usr/share/mediawiki/includes/objectcache/SqlBagOStuff.php(367): DatabaseMysqlBase->replace('objectcache', Array, Array, 'SqlBagOStuff::s...')
#6 /usr/share/mediawiki/includes/objectcache/SqlBagOStuff.php(381): SqlBagOStuff->setMulti(Array, 4500)
#7 /var/lib/mediawiki/webroot/extensions/Translate/webservices/TranslationWebService.php(324): SqlBagOStuff->set('my_wiki:transla...', '1|1508407232', 4500)
#8 /var/lib/mediawiki/webroot/extensions/Translate/webservices/TranslationWebService.php(109): TranslationWebService->reportTranslationServiceFailure('Unsupported Med...')
#9 /var/lib/mediawiki/webroot/extensions/Translate/translationaids/MachineTranslationAid.php(71): TranslationWebService->getResultData(Object(TranslationQueryResponse))
#10 /var/lib/mediawiki/webroot/extensions/Translate/translationaids/MachineTranslationAid.php(55): MachineTranslationAid->formatSuggestion(Array)
#11 /var/lib/mediawiki/webroot/extensions/Translate/api/ApiQueryTranslationAids.php(101): MachineTranslationAid->getData()
#12 /usr/share/mediawiki/includes/api/ApiMain.php(1435): ApiTranslationAids->execute()
#13 /usr/share/mediawiki/includes/api/ApiMain.php(510): ApiMain->executeAction()
#14 /usr/share/mediawiki/includes/api/ApiMain.php(481): ApiMain->executeActionWithErrorHandling()
#15 /usr/share/mediawiki/api.php(83): ApiMain->execute()
#16 {main}

Any proposal what I can do to resolve the error ?

Andreas Plank (talkcontribs)

Nobody has an idea? Related to “unsupported media type”, how can I check that the outgoing request to yandex has the proper file type? I have just guessed it could be related to mime-type definition/configuration of my server setup. The FireFox debugger console does not show any request other than localhost.

How can I check that Yandex request in detail when it is not showing up in debugger console?

Nikerabbit (talkcontribs)

I am not using Yandex myself currently. It is possible that they have changed the API and the current code needs to be updated.

Nikerabbit (talkcontribs)

The code in YandexWebService::getQuery() looks okay though.

Andreas Plank (talkcontribs)

Debugging the TranslationQueryResponse object in TranslationWebService::getResultData I figured out that in webservices/YandexWebService.php that return TranslationQuery::factory is somewhat mis-coded. Now I get it working by using queryParamaters() instead of postWithData() like so:

protected function getQuery( $text, $from, $to ) {
// ... clipped code
return TranslationQuery::factory( $this->config['url'] )
  ->timeout( $this->config['timeout'] )
  ->queryParamaters(
    [
      'key' => $this->config['key'],
      'text' => $text,
      'lang' => "$from-$to",
      'format' => 'html',
    ]
  );
}

It needs no 'body' but 'parameters' were not set at all. Do you agree? There is also a misspelled typo: queryParamaters ;-)

Perhaps other webservices have the same code issues.

Andreas Plank (talkcontribs)
Reply to "Debug machine translation services, translation aids (Yandex mt service)"