Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 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 @@ -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]) {
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