jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/373178 )

Change subject: Remove hardcoded cxserver /translate API url
......................................................................


Remove hardcoded cxserver /translate API url

Use the sitemapper module for doing cxserver request.

Change-Id: Idf2bd169f2bd9b890472c8615fb0a775469e60b4
---
M modules/mw.cx.MachineTranslationService.js
M modules/ui/mw.cx.ui.TranslationView.js
2 files changed, 14 insertions(+), 18 deletions(-)

Approvals:
  Divec: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/mw.cx.MachineTranslationService.js 
b/modules/mw.cx.MachineTranslationService.js
index d8dfe0d..b72a330 100644
--- a/modules/mw.cx.MachineTranslationService.js
+++ b/modules/mw.cx.MachineTranslationService.js
@@ -32,14 +32,8 @@
  * @return {jQuery.Promise} Returns the translated HTML as a string.
  */
 mw.cx.MachineTranslationService.prototype.translate = function ( text, 
provider ) {
-       return this.validateProvider( provider )
-               .then( this.getCXServerToken.bind( this ) )
-               .then( this.fetchTranslation.bind( this, text, provider ) )
-               .then( function ( output ) {
-                       // Some hacks around the fact that cxserver always wraps
-                       // everything in a div (it shouldn't)
-                       return $( output )[ 0 ].innerHTML;
-               } );
+       return this.getCXServerToken()
+               .then( this.fetchTranslation.bind( this, text, provider ) );
 };
 
 /**
@@ -163,10 +157,10 @@
 mw.cx.MachineTranslationService.prototype.fetchTranslation = function ( text, 
provider, token ) {
        var request, mtURL;
 
-       mtURL = this.siteMapper.getCXServerUrl( '/mt/$from/$to/$provider', {
+       mtURL = this.siteMapper.getCXServerUrl( 
'/translate/$from/$to/$provider', {
                $from: this.sourceLanguage,
                $to: this.targetLanguage,
-               $provider: provider
+               $provider: provider || ''
        } );
 
        request = {
diff --git a/modules/ui/mw.cx.ui.TranslationView.js 
b/modules/ui/mw.cx.ui.TranslationView.js
index 59e04c0..e25c151 100644
--- a/modules/ui/mw.cx.ui.TranslationView.js
+++ b/modules/ui/mw.cx.ui.TranslationView.js
@@ -1,4 +1,5 @@
 'use strict';
+
 /**
  * TranslationView
  *
@@ -350,7 +351,7 @@
                doc = modelSurface.documentModel,
                pRange = placeholder.getModel().getOuterRange();
 
-       pasteDoc = ve.dm.converter.getModelFromDom( ve.createDocumentFromHtml( 
data.contents ) );
+       pasteDoc = ve.dm.converter.getModelFromDom( ve.createDocumentFromHtml( 
data ) );
        tx1 = ve.dm.TransactionBuilder.static.newFromRemoval( doc, pRange );
        tx2 = ve.dm.TransactionBuilder.static.newFromDocumentInsertion(
                doc,
@@ -366,14 +367,15 @@
 
 };
 
+/**
+ * Translate and adapt the given source section
+ * @param {string} source Source html content
+ * @return {jQuery.Promise}
+ */
 mw.cx.ui.TranslationView.prototype.translate = function ( source ) {
-       return $.ajax( {
-               method: 'POST',
-               contentType: 'application/x-www-form-urlencoded',
-               // TODO hardcoded
-               url: 'http://localhost:8080/v1/translate/en/es/Apertium',
-               data: { html: source }
-       } );
+       return this.config.MTService.getSuggestedDefaultProvider().then( 
function ( provider ) {
+               return this.config.MTService.translate( source, provider );
+       }.bind( this ) );
 };
 
 mw.cx.ui.TranslationView.prototype.showCategories = function () {

-- 
To view, visit https://gerrit.wikimedia.org/r/373178
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idf2bd169f2bd9b890472c8615fb0a775469e60b4
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: KartikMistry <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to