diff --git a/README.md b/README.md index 9359db42..0bcb2c8d 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This fork of original [matheuss/google-translate-api](https://github.com/matheus - Removed unsecure `unsafe-eval` dependency (See [#2](https://github.com/vitalets/google-translate-api/pull/2)) - Added [ddaily CI tests](https://travis-ci.org/vitalets/google-translate-api/builds) to get notified if Google API changes - Added support for custom `tld` (especially to support `translate.google.cn`, see [#7](https://github.com/vitalets/google-translate-api/pull/7)) +- Added support for outputting pronunciation (See [#17](https://github.com/vitalets/google-translate-api/pull/17)) ## Install diff --git a/index.js b/index.js index 06ed03bb..614bd04e 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, @@ -75,6 +76,9 @@ function translate(text, opts) { if (obj[0]) { result.text += obj[0]; } + if (obj[2]) { + result.pronunciation += obj[2]; + } }); if (body[2] === body[8][0][0]) { diff --git a/test.js b/test.js index 3db0b25b..cbd66206 100644 --- a/test.js +++ b/test.js @@ -31,6 +31,12 @@ test('translate from auto to dutch', async t => { t.false(res.from.text.didYouMean); }); +test('test pronunciation', async t => { + const res = await translate('translator', {from: 'auto', to: 'zh-CN'}); + + t.is(res.pronunciation, 'Fānyì zhě'); +}); + test('translate some english text setting the source language as portuguese', async t => { const res = await translate('translator', {from: 'pt', to: 'nl'});