Skip to content

Commit

Permalink
fix(tjo): require language param and fix mocked data
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledMohamedP committed Jul 1, 2017
1 parent 7e0ea9d commit 72be8d2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 16 deletions.
4 changes: 2 additions & 2 deletions __mocks__/mock-data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const mockDataObject = {name: 'name', some: [{name: 'j'}], addressField: ['city', 'state', 'zipdecode'], bool: true, num: 33, badBool: false, nully: null, undefined: undefined};
const transaltedES = {name: 'name-es', some: [{name: 'j-es'}], addressField: ['city-es', 'state-es', 'zipdecode-es'], bool: true, num: 33, badBool: false, nully: null, undfined: undefined};
const mockDataObject = {name: 'name', some: [{name: 'j'}], addressField: ['city', 'state', 'zipdecode'], bool: true, num: 33, badBool: false, nully: null, undefin: undefined};
const transaltedES = {name: 'name-es', some: [{name: 'j-es'}], addressField: ['city-es', 'state-es', 'zipdecode-es'], bool: true, num: 33, badBool: false, nully: null, undefin: undefined};

module.exports = {
mockDataObject,
Expand Down
6 changes: 0 additions & 6 deletions lib/service/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ function translateObject(language, key, destObj) {

function translateString(language, key, destObj, valueStr) {
return new Promise(function (resolve, reject) {
// If empty string don't call google
if (valueStr === '') {
resolve(destObj);
return;
}

translateService.translate(valueStr, language, function (err, res) {
if (err || !res) {
reject(err);
Expand Down
6 changes: 0 additions & 6 deletions lib/service/yandex.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ function translateObject(language, key, destObj) {

function translateString(language, key, destObj, valueStr) {
return new Promise(function (resolve, reject) {
if (valueStr === '') {
// there is nothing to translate, so don't ask Yandex (Yandex will respond with an error)
resolve(destObj);
return;
}

translateService.translate(valueStr, {to: language}, function (err, res) {
if (err || res.code !== 200) {
reject(err || res);
Expand Down
4 changes: 2 additions & 2 deletions lib/translate-json-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function TranslateJSONObject() {
);
}

if (_.isString(language)) {
if (!_.isString(language)) {
return Promise.reject('Please provide a language param [type String] e.g. translate(obj, es)');
}

Expand Down Expand Up @@ -78,7 +78,7 @@ function TranslateJSONObject() {
function handleArrayType(value, key, destObj) {
if (_.isPlainObject(value)) {
translateObjectProps(value, key, destObj);
} else if (_.isString(value)) {
} else if (_.isString(value) && value !== '') {
promises.push(translateSrv.string(language, key, destObj, value));
}
}
Expand Down

0 comments on commit 72be8d2

Please sign in to comment.