asksuite-translate-json-object
Advanced tools
Comparing version 0.0.5-development to 0.0.6-development
@@ -6,2 +6,3 @@ var translateService; | ||
var client; | ||
var map | ||
@@ -11,23 +12,46 @@ | ||
client = request.createClient(url.url); | ||
map = new Map(); | ||
} | ||
// eslint-disable-next-line max-params | ||
function translateObject(language, key, destObj, keysArray, valuesArray) { | ||
return new Promise(function (resolve, reject) { | ||
client.post('translate/' + language, valuesArray) | ||
.then(function (result) { | ||
if (map.get(JSON.stringify(valuesArray))){ | ||
var res = result.body; | ||
console.log("entrei aqui no repedido") | ||
var res = map.get(JSON.stringify(valuesArray)) | ||
for (var i = 0; i < keysArray.length; i++) { | ||
destObj[key][keysArray[i]] = res[i]; | ||
} | ||
for (var i = 0; i < keysArray.length; i++) { | ||
destObj[key][keysArray[i]] = res[i]; | ||
} | ||
resolve(destObj); | ||
resolve(destObj); | ||
}).catch(function (err) { | ||
reject(err); | ||
}) | ||
}else{ | ||
client.post('translate/' + language, valuesArray) | ||
.then(function (result) { | ||
var res = result.body; | ||
map.set(JSON.stringify(valuesArray), res) | ||
for (var i = 0; i < keysArray.length; i++) { | ||
destObj[key][keysArray[i]] = res[i]; | ||
} | ||
resolve(destObj); | ||
}).catch(function (err) { | ||
console.log("deu erro", err); | ||
reject(err); | ||
}) | ||
} | ||
}); | ||
@@ -34,0 +58,0 @@ |
var _ = require('lodash'); | ||
var Promise = require('promise'); | ||
var Promise = require('bluebird'); | ||
var constant = require('./util/constant'); | ||
@@ -134,3 +134,3 @@ var isValidLang = require('./util/valid-lang'); | ||
if (valuesArray.length !== 0) { | ||
promises.push(translateSrv.object(language, key, dest, keysArray, valuesArray)); | ||
promises.push({language: language, key: key, dest: dest, keysArray: keysArray, valuesArray: valuesArray}); | ||
} | ||
@@ -145,3 +145,6 @@ } | ||
return new Promise(function (resolve, reject) { | ||
Promise.all(promises).then(function () { | ||
Promise.map(promises, function(promise) { | ||
// Promise.map awaits for returned promises as well. | ||
return translateSrv.object(promise.language, promise.key, promise.dest, promise.keysArray, promise.valuesArray) | ||
}, {concurrency: 12}).then(function(res) { | ||
if (ARRAY_ROOT_TYPE) { | ||
@@ -152,4 +155,12 @@ resolve(destObj.ROOT.arrayType); | ||
} | ||
}).catch(reject); | ||
}).catch(error => { | ||
console.log(error) | ||
console.log("deu erro ao traduri") | ||
}) | ||
}); | ||
} | ||
@@ -156,0 +167,0 @@ |
{ | ||
"name": "asksuite-translate-json-object", | ||
"version": "0.0.5-development", | ||
"version": "0.0.6-development", | ||
"description": "Translate a JSON object to any language via google or yandex translate API", | ||
@@ -16,2 +16,3 @@ "main": "lib/translate-json-object.js", | ||
"dependencies": { | ||
"bluebird": "^3.5.1", | ||
"google-translate": "2.0.5", | ||
@@ -18,0 +19,0 @@ "lodash": "4.17.3", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28400
594
8
+ Addedbluebird@^3.5.1
+ Addedbluebird@3.7.2(transitive)