google-translate-api icon indicating copy to clipboard operation
google-translate-api copied to clipboard

Autocorrect example provides different output

Open funnel20 opened this issue 1 year ago • 1 comments

The documentation example from https://github.com/AidanWelch/google-translate-api?tab=readme-ov-file#autocorrect shows different output than the API.

Documentation

const res = await translate('I spea Dutch!', { from: 'en', to: 'nl', autoCorrect: true });

console.log(res.from.text.didYouMean); // => false
console.log(res.from.text.autoCorrected); // => true
console.log(res.from.text.value); // => 'I [speak] Dutch!'

console.log(res.text); // => 'Ik spreek Nederlands!'

Output of version 10.6.8

const res = await translate('I spea Dutch!', { from: 'en', to: 'nl', autoCorrect: true });

console.log(res.from.text.didYouMean); // => true
console.log(res.from.text.autoCorrected); // => false
console.log(res.from.text.value); // => 'I [speak] Dutch!'

console.log(res.text); // => 'Ik speed Nederlands!'

So the flags didYouMean and autoCorrected are exactly opposite, and the res.text is not corrected, despite autoCorrect: true.

UPDATE

It did autocorrect while using "Card gaame" as English source text with a typo:

const res = await translate('Card gaame', { from: 'en', to: 'nl', autoCorrect: true });

console.log(res.from.text.didYouMean); // => false
console.log(res.from.text.autoCorrected); // => true
console.log(res.from.text.value); // => 'Card [game]'

console.log(res.text); // => 'Kaartspel'

After reading the description of the returned parameters more thoroughly, it's important to realise that although autoCorrect: true is requested, Google might not be able to correct it. In that case it will return res.from.text.autoCorrected = false and a possibly incorrect translation in res.text.

Maybe it's an idea to update the example in the docu, since it does not reflect the API output.

funnel20 avatar Jun 13 '24 09:06 funnel20

That's a good idea! That part of the docs is legacy from a much older version of this package, and unfortunately the Google Translate API responses must've changed since then

AidanWelch avatar Jun 23 '24 03:06 AidanWelch