jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/382111 )
Change subject: Matxin MT: Use an API key to access the service
..
Matxin MT: Use an API key to access the service
As Matxin maintainers suggested, the API is adding a key to
control the usage of service.
Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a
---
M config.dev.yaml
M lib/mt/Matxin.js
2 files changed, 29 insertions(+), 1 deletion(-)
Approvals:
jenkins-bot: Verified
Nikerabbit: Looks good to me, approved
diff --git a/config.dev.yaml b/config.dev.yaml
index 38625ac..39fe097 100644
--- a/config.dev.yaml
+++ b/config.dev.yaml
@@ -86,6 +86,7 @@
Matxin:
api: http://matxin.elhuyar.eus/API
languages: config/Matxin.yaml
+ key: null
dictionary:
Dictd:
languages: config/Dictd.yaml
diff --git a/lib/mt/Matxin.js b/lib/mt/Matxin.js
index c48959d..c39e7dd 100644
--- a/lib/mt/Matxin.js
+++ b/lib/mt/Matxin.js
@@ -23,10 +23,37 @@
return preq.post( {
uri: this.conf.mt.Matxin.api,
body: {
+ key: this.conf.mt.Matxin.key,
direction: sourceLang + '-' + targetLang,
text: sourceText
}
- } ).then( ( response ) => response.body.translation.replace(
/\. ॥ ॥\. /g, '.॥॥.' ) );
+ } ).then( ( response ) => response.body.translation.replace(
/\. ॥ ॥\. /g, '.॥॥.' ) )
+ .catch( ( response ) => {
+ throw new Error( 'Translation with Matxin
failed. Error: ' +
+ this.getErrorName( response.status ) +
' ' + sourceLang + '-' + targetLang );
+ } );
+ }
+
+ /**
+* Returns error name from error code.
+*
+* @param {number} code Error code
+* @return {string}
+*/
+ getErrorName( code ) {
+ const errormap = {
+ 403: 'Invalid api key'
+ };
+
+ if ( code in errormap ) {
+ return errormap[ code ];
+ }
+
+ return `Unknown error: ${code}`;
+ }
+
+ requiresAuthorization() {
+ return true;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/382111
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh
Gerrit-Reviewer: Catrope
Gerrit-Reviewer: KartikMistry
Gerrit-Reviewer: Nikerabbit
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits