Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.js and test.js to add pronunciation support #17

Merged
merged 4 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function translate(text, opts) {
return got(url).then(function (res) {
var result = {
text: '',
pronunciation: '',
from: {
language: {
didYouMean: false,
Expand All @@ -74,6 +75,8 @@ function translate(text, opts) {
body[0].forEach(function (obj) {
if (obj[0]) {
result.text += obj[0];
} else if (obj[2]) {
rawr51919 marked this conversation as resolved.
Show resolved Hide resolved
result.pronunciation += obj[2];
}
});

Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});

Expand Down