Topic on Extension talk:Translate

Microsoft Translate API v2 don't work with Translate extension

18
Tuxxic (talkcontribs)

Hi,

I wish to use Microsoft Translator API for translation suggestions. Unfortunately, I can't seem to use it.

The source code to extensions\Translate\webservices\MicrosoftWebService.php says it should work, but it doesn't.

- New Microsoft API needs 2 information to request a token : clientID and clientSecret, then you get an Access Token.

Those are not implemented in the current MicrosoftWebService.php and therefore I can't use it ...

There are a few help topics (and PHP examples) on https://msdn.microsoft.com/en-us/library/hh454950.aspx#phpexample - my skill in PHP are very shallow, and I can't figure out how to convert the PHP samples to MediaWiki code.

Can someone either help me doing it, or give me the name of a machine translation service that works out of the box ?

Jdforrester (WMF) (talkcontribs)
Tuxxic (talkcontribs)

Hi,

Thanks for the link !

I got the patch set 7 from https://gerrit.wikimedia.org/r/243427 and manage to make it work flawlessly, I don't know why this was reverted ?

I just had to modify file MicrosoftWebService.php and add in the getMSTokens function the following line :

$options['sslVerifyCert'] = false;

LocalSettings.php does works by using the following :

$wgTranslateTranslationServices['Microsoft'] = array(
     'url' => 'http://api.microsofttranslator.com/V2/Http.svc/Translate',
     'timeout' => 3,
     'clientId' => "your_client_id",
     'clientSecret' => "your_client_secret",
     'type' => 'microsoft',
);

@Nikerabbit maybe can you give a look at the functions and update them ? I am sorry I don't know how to use the patch system :(

I could update the docs if you need, though.

Nikerabbit (talkcontribs)

I am curious why ssl check needs to be disabled? That is very bad for security.

The patch is not reverted, it is just stuck on review queue waiting for some improvements.

Tuxxic (talkcontribs)

Oh sorry.

In fact, I used this policy because I saw a SSL warning , and wanted to test.

I checked using this page : https://msdn.microsoft.com/en-us/library/hh454950.aspx#phpexample

There is a parameter in the test script :

//CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

You can set it to true, but I don't know (yet) how to configure SSL for this, so here I go.

Tuxxic (talkcontribs)

Hello, I found why I didn't manage to get this to work : in fact, it was my PHP configuration which was not set up correctly.

Here's how to configure SSL verification in cURL PHP extension.

I found this website : https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/

Which made me think that I never configured anything in cURL in my PHP installation. So I went to this page : https://curl.haxx.se/docs/caextract.html, downloaded the cacert.pem, and then configured it in my php.ini : curl.cainfo=c:\php\cacert.pem

Et voilà !

Tuxxic (talkcontribs)

Hi,

I managed to make it work with the patch set 7, but there is something I don't know how to figure out, if someone can help :

I have to modify then save everyday the LocalSettings.php file in order to have the Microsoft Web Service to connect and give suggestions : even if I don't modify anything in the file, it is mandatory to have the suggestions.

What can be wrong ? Is there a file caching of LocalSettings.php ?

Nikerabbit (talkcontribs)

Could you describe what are the symptoms of the failure if you do not save LocalSettings.php every day?

Tuxxic (talkcontribs)

Yes, the translation aid windows looks like this : http://imgur.com/a/fg5Cr

To the right, I don't have any suggestions.

When I touch the file, I have "Loading ..." then Suggestions and I begin to translate.

Nikerabbit (talkcontribs)
Tuxxic (talkcontribs)

Yes ! It works. I was using the previous version, and didn't update. I'm not still familiar with how to update MediaWiki modules all at once.

Thanks a lot for your help.

Nikerabbit (talkcontribs)

My plan is to review the open patch during this quarter.

Tuxxic (talkcontribs)

@Nikerabbit, just to notify you, I can't use Microsoft + TTMServer along.

My configuration is the following :

$wgTranslateTranslationServices = array();

$wgTranslateTranslationServices['TTMServer'] = array(
     'database' => false, // Passed to wfGetDB
     'cutoff' => 0.75,
     'type' => 'ttmserver',
     'public' => false,
);

$wgTranslateTranslationServices['Microsoft'] = array(
     'url' => 'http://api.microsofttranslator.com/V2/Http.svc/Translate',
     'clientId' => "myclientid",
     'clientSecret' => "mysecret",
     'type' => 'microsoft',
);

I only used the patch files to use MS v2 translate API, but in order to have the service to work, I have to disable TTMServer.

Not a very big problem per se, since I used it only a few times, but in case, I can investigate with you if you need.

Nikerabbit (talkcontribs)

I am not sure what could be the problem with TTMServer. Perhaps you could open a new discussion thread with some more details?

Tuxxic (talkcontribs)

Hi @Nikerabbit - I couldn't reproduce. It might be a misconfiguration from me, because I just updated MW to 1.27 - sorry for inconvenience !

Tuxxic (talkcontribs)

Hi, I downloaded MLEB 2016.08 and the patch still is not present. Can we hope for it to be in the next MLEB ?

Nikerabbit (talkcontribs)

It will be present in MLEB 2016.10 coming soon.

Reply to "Microsoft Translate API v2 don't work with Translate extension"