Page MenuHomePhabricator

Microsoft Translator not working with new authorisation model
Closed, ResolvedPublic

Description

Microsoft has changed their authorisation model and there is also a quota now limiting the free translations to 2,000,000 characters per month. The idea is that, first you subscribe to the Microsoft Translator API on Azure Marketplace and then you register your wiki with it. Then you get a Client ID and a Client secret which, according to documentation, are both needed to access the service. So Translate as it is now, cannot use Microsoft Translator service (unless one has an older Bing API Key - like for example in translatewiki.net).

The registration process and how to obtain access token (with sample php code) is described here: http://msdn.microsoft.com/en-us/library/hh454950.aspx

See Also: T43435: Microsoft Translator translation service errors

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:35 AM
bzimport set Reference to bz44679.
bzimport added a subscriber: Unknown Object (MLST).

Thanks for testing and filing this bug, I was quite confused too when I looked at this for bug 41435.

slboat wrote:

i use chinese so the other just not work for me.i see translate.net is work fine with bing api,but the source not,even trunk,so i try to fix it by my self,here is what i do: http://see.sl088.com/wiki/%E6%89%A9%E5%B1%95:Translate/%E5%BE%AE%E8%BD%AF%E8%BE%85%E5%8A%A9%E6%94%AF%E6%8C%81%E4%BF%AE%E6%94%B9
and i put the mod source to https://code.google.com/p/mediawiki-translate-slboat-mod/
you just need mod one file in it:
/Translate/webservices/MicrosoftWebService.php
and add this three line to localsetting.ini
$wgTranslateTranslationServices['Microsoft']['key'] = "no need anymore" ; just for need it,dont fit anything
$wgTranslateTranslationServices['Microsoft']['clientid'] = "you_ms_id" ;
your appid
$wgTranslateTranslationServices['Microsoft']['clientSecret'] = "yousercrtinhere=" ; //you sercret

Nemo suggestion me to submit the patch...but i still not mush know how..so may be you can review this,and make it as a patch for me...i really love this extension,it's great.

Hi sen, to submit a patch, you are welcome to use Developer access

https://www.mediawiki.org/wiki/Developer_access

to submit a patch as a Git branch directly into Gerrit:

https://www.mediawiki.org/wiki/Git/Tutorial

Putting your branch in Git makes it easier to review it quickly.
Thanks again! Your contribution is appreciated!

(In reply to sen from comment #2)

i use chinese so the other just not work for me.i see translate.net is work
fine with bing api,but the source not,even trunk,so i try to fix it by my
self,here is what i do:
http://see.sl088.com/wiki/%E6%89%A9%E5%B1%95:Translate/
%E5%BE%AE%E8%BD%AF%E8%BE%85%E5%8A%A9%E6%94%AF%E6%8C%81%E4%BF%AE%E6%94%B9
and i put the mod source to
https://code.google.com/p/mediawiki-translate-slboat-mod/
you just need mod one file in it:
/Translate/webservices/MicrosoftWebService.php
and add this three line to localsetting.ini
$wgTranslateTranslationServices['Microsoft']['key'] = "no need anymore" ;
just for need it,dont fit anything
$wgTranslateTranslationServices['Microsoft']['clientid'] = "you_ms_id" ;
your appid
$wgTranslateTranslationServices['Microsoft']['clientSecret'] =
"yousercrtinhere=" ; //you sercret

Nemo suggestion me to submit the patch...but i still not mush know how..so
may be you can review this,and make it as a patch for me...i really love
this extension,it's great.

It looks like your code is quite a bit out of date with master now :(

If you wanted to update it, and then provide us with diff(s) of what changes you actually made ontop of master at a specific point, upstreaming it should be relatively easy

Since I need this for my wiki, I started updating the code to current master

Change 243427 had a related patch set uploaded (by C0nnex):
Update Microsoft Translationservice to accesstoken model

https://gerrit.wikimedia.org/r/243427

Since I need this for my wiki, I started updating the code to current master

I've fixed the minor code style type issues.

The last query is about

$text = str_replace( '! N!', '!N!', $text ); // Cleanup MS specific newline

Is this needed? Is only this needed? A similar reverse transform isn't done before wrapUntranslatable

Overriding the base unwrapUntranslatable, and fixing it as appropriate seems nicer. Is all the code in the parent wrapUntranslatable needed? Or just some of it?

	/**
	 * Some mangling that tries to keep some parts of the message unmangled
	 * by the translation service. Most of them support either class=notranslate
	 * or translate=no.
	 * @param string $text
	 * @return string
	 */
	protected function wrapUntranslatable( $text ) {
		$text = str_replace( "\n", "!N!", $text );
		$pattern = '~%[^% ]+%|\$\d|{VAR:[^}]+}|{?{(PLURAL|GRAMMAR|GENDER):[^|]+\||%(\d\$)?[sd]~';
		$wrap = '<span class="notranslate" translate="no">\0</span>';
		return preg_replace( $pattern, $wrap, $text );
	}

	/**
	 * Undo the hopyfully untouched mangling done by wrapUntranslatable.
	 * @param string $text
	 * @return string
	 */
	protected function unwrapUntranslatable( $text ) {
		$text = str_replace( '!N!', "\n", $text );
		$pattern = '~<span class="notranslate" translate="no">(.*?)</span>~';
		return preg_replace( $pattern, '\1', $text );
	}

Reedy, you can still use the Microsoft key I sent you on 2014-11-04. Let me know if you need me to add more (paid) features to it.

The patch found another tester. https://www.mediawiki.org/wiki/Topic:T68o6opfperawbfs

It's not clear what else is needed for the patch to be merged, apart from working.

I would highly prefer to clean up the newline handling code a bit, or just bypass it if not needed.

Nikerabbit reassigned this task from eranroz to C0nnex.
Nikerabbit updated the task description. (Show Details)
Nikerabbit added a subscriber: eranroz.

Change 243427 merged by jenkins-bot:
Update Microsoft Translationservice to accesstoken model

https://gerrit.wikimedia.org/r/243427

Nikerabbit removed a project: Patch-For-Review.
Nikerabbit moved this task from In Review to Done on the Language-Q1-2016-17 Sprint 4 board.
Nikerabbit added a subscriber: Amire80.

Thanks @Amire80 for review.

Hi,

Sorry to tell that the patch needs to be updated (AGAIN) because Microsoft moved their API model to the Azure platform in 26/10/2016.
So the URLs, models and stuff have changed.
I will be opening an Azure account soon, to keep on using it, but be aware that the patch still won't work :(

URL to the DataMarket telling the date : https://datamarket.azure.com/dataset/bing/microsofttranslator
URL to the Microsoft Translator Business blog that includes an example code : https://translatorbusiness.uservoice.com/knowledgebase/articles/1078534-microsoft-translator-on-azure

Good luck to the coders !

As of now, suggestions still work on twn.

Your current Microsoft Translator API subscription on the Microsoft DataMarket will continue through December 31, 2016, with full subscription functionality

We probably can't wait two years for the next patch.

Microsoft posted this here : https://translatorbusiness.uservoice.com/knowledgebase/articles/1078534-microsoft-translator-on-azure

What you need to know about your subscription
You may subscribe to the Microsoft Translator API in the Azure Portal anytime.
Your current Microsoft Translator API subscription on the Microsoft DataMarket will continue through December 31, 2016, with full subscription functionality.
Service access on Microsoft DataMarket will be limited to the monthly volume plan subscribed, beginning January 1, 2017. As of the new year, you cannot upgrade or downgrade your subscription on the Azure Marketplace, you can only cancel.
Remaining Microsoft Translator API subscriptions will be automatically canceled on April 30, 2017.
You can have two Translator API subscriptions on the two portals at the same time as you migrate from the Microsoft DataMarket portal to the Azure Portal.

I can help testing patches if you wish, I am not a really good PHP coder, so I can't help with code :(

Hi, if it is of any help for the coder who would want to help, I tried unfortunately to do it, but I couldn't manage ...

If it can help the developer who would implement this, Microsoft posted this, which I managed to run on my server : https://github.com/MicrosoftTranslator/HTTP-Code-Samples-Archive/blob/master/PHP/PHPAzureToken.php

By the way, I need to use a proxy to pass XML HTTP requests, so if anyone can be of help for this too, it would be nice :)

Thanks in advance

Hi there,
I am trying to install microsoft o yandex.
I've got the free Translator Text API at azure and even 2 keys.
Now What?
I am not a newie, I am worst.
I know. Be patient. pls. If possible.
Thanx

Change 443559 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/extensions/Translate@master] MicrosoftWebService: update for new API (again)

https://gerrit.wikimedia.org/r/443559

I can provide a key for testing the updated patch.

Change 443559 merged by jenkins-bot:
[mediawiki/extensions/Translate@master] MicrosoftWebService: update for new API (again)

https://gerrit.wikimedia.org/r/443559