services/language_translator/v3.js
function doTranslate(language_translator, msg, model_id) {
      var p = new Promise(function resolver(resolve, reject){
        // Please be careful when reading the below. The first parameter is
        // a structure, and the tabbing enforced by codeacy imho obfuscates
        // the code, rather than making it clearer. I would have liked an
        // extra couple of spaces.
        language_translator.translate({
          text: msg.payload,
          model_id: model_id
        },
        function (err, response) {
          if (err) {
            reject(err);
          } else {
            msg.translation = {};
            msg.translation.response = response;
            msg.payload = response.translations[0].translation;
            resolve();
          }
        });

      });
      return p;
    }
function doTranslate(language_translator, msg, model_id) {
      var p = new Promise(function resolver(resolve, reject){
        // Please be careful when reading the below. The first parameter is
        // a structure, and the tabbing enforced by codeacy imho obfuscates
        // the code, rather than making it clearer. I would have liked an
        // extra couple of spaces.
        language_translator.translate({
          text: msg.payload,
          model_id: model_id
        },
        function (err, response) {
          if (err) {
            reject(err);
          } else {
            msg.translation = {};
            msg.translation.response = response;
            msg.payload = response.translations[0].translation;
            resolve();
          }
        });

      });
      return p;
    }
function doTranslate ( language_translator , msg , model_id ) { var p = new Promise ( function resolver ( resolve , reject ) { // Please be careful when reading the below. The first parameter is // a structure, and the tabbing enforced by codeacy imho obfuscates // the code, rather than making it clearer. I would have liked an // extra couple of spaces. language_translator . translate ( { text : msg . payload , model_id : model_id } , function ( err , response ) { if ( err ) { reject ( err ) ; } else { msg . translation = { } ; msg . translation . response = response ; msg . payload = response . translations [ 0 ] . translation ; resolve ( ) ; } } ) ; } ) ; return p ; }
If a translation is requested, then the model id will have been built by the calling function based on source, target and domain.
If a translation is requested then the model id will have been built by the calling function based on source target and domain .