Skip to content
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]) {
Comment thread
rawr51919 marked this conversation as resolved.
Outdated
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