@vitalets/google-translate-api
Advanced tools
Comparing version 5.1.0 to 7.0.0
14
index.js
@@ -94,7 +94,11 @@ var querystring = require('querystring'); | ||
} else { | ||
json[1][0][0][5].forEach(function (obj) { | ||
if (obj[0]) { | ||
result.text += obj[0]; | ||
} | ||
}); | ||
result.text = json[1][0][0][5] | ||
.map(function (obj) { | ||
return obj[0]; | ||
}) | ||
.filter(Boolean) | ||
// Google api seems to split text per sentences by <dot><space> | ||
// So we join text back with spaces. | ||
// See: https://github.com/vitalets/google-translate-api/issues/73 | ||
.join(' '); | ||
} | ||
@@ -101,0 +105,0 @@ result.pronunciation = json[1][0][0][1]; |
{ | ||
"name": "@vitalets/google-translate-api", | ||
"version": "5.1.0", | ||
"version": "7.0.0", | ||
"description": "A free and unlimited API for Google Translate", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
16
test.js
@@ -30,10 +30,20 @@ var test = require('ava'); | ||
t.false(res.from.text.autoCorrected); | ||
t.is(res.from.text.value, ''); | ||
t.false(res.from.text.didYouMean); | ||
t.is(res.from.text.value, '[translate]'); | ||
t.true(res.from.text.didYouMean); | ||
}); | ||
test('translate several sentences with spaces (#73)', async t => { | ||
const res = await translate( | ||
'translator, translator. translator! translator? translator,translator.translator!translator?', | ||
{from: 'auto', to: 'nl'} | ||
); | ||
t.is(res.text, 'vertaler, vertaler. vertaler! vertaler? Vertaler, vertaler.translator! Vertaler?'); | ||
}); | ||
test('test pronunciation', async t => { | ||
const res = await translate('translator', {from: 'auto', to: 'zh-CN'}); | ||
t.is(res.pronunciation, 'Yì zhě'); | ||
// here can be 2 variants: 'Yì zhě', 'Fānyì' | ||
t.regex(res.pronunciation, /^(Yì zhě)|(Fānyì)$/); | ||
}); | ||
@@ -40,0 +50,0 @@ |
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
29255
598