From fc2ace1215b838f4eafc4133e4d9e3d3a83e0881 Mon Sep 17 00:00:00 2001 From: Andrew Stromme Date: Mon, 19 Mar 2018 21:19:13 -0700 Subject: [PATCH] Expose the pronunciation from the response --- index.js | 3 +++ test.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/index.js b/index.js index d1427339..25bb31a0 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,7 @@ function translate(text, opts) { return got(url).then(function (res) { var result = { text: '', + pronunciation: '', from: { language: { didYouMean: false, @@ -74,6 +75,8 @@ function translate(text, opts) { body[0].forEach(function (obj) { if (obj[0]) { result.text += obj[0]; + } else if (obj[2]) { + result.pronunciation += obj[2]; } }); diff --git a/test.js b/test.js index 622a731d..563ebdf1 100644 --- a/test.js +++ b/test.js @@ -33,6 +33,16 @@ test('translate from auto to dutch', async t => { } }); +test('test pronunciation', async t => { + try { + const res = await translate('translator', {from: 'auto', to: 'zh-CN'}); + + t.is(res.pronunciation, 'Fānyì zhě'); + } catch (err) { + t.fail(err.code); + } +}); + test('translate some english text setting the source language as portuguese', async t => { try { const res = await translate('translator', {from: 'pt', to: 'nl'});