You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you to matheuss and iamtraction for writing the
original version of this library. Due to the original authors no longer actively maintaining it, I rewrote the library
using TypeScript and ISO-639-1. This rewrite has made the program more secure, provided richer translation results,
and
resolved program anomalies.
What's New?
Adaptive native language translation.
Synonyms, polysemous explanations, and example sentences.
Timeout and retry parameters in complex networks.
Support for querying language, language code, native language, and adaptive language lists.
Support for ISO-639-1, minority languages, special languages, and the latest changes on Wikipedia.
importtranslatefrom'@kabeep/node-translate';// Language name and capitalized correctiontranslate('例子',{to: 'ENGlish'}).then(res=>{// => exampleconsole.log(res.text);});
importtranslatefrom'@kabeep/node-translate';// Use `auto` or leave the `from` parameter empty to detect language by adativeness// Use `auto` or leave the `to` parameter empty to detect language by os (`en` for example)translate('例子').then(res=>{// => exampleconsole.log(res.text);});
Phonetic transcription of the source text and translation
importtranslatefrom'@kabeep/node-translate';// Output phonetic transcription of the source text and the translated texttranslate('例子',{to: 'ja'}).then(res=>{// => Lìziconsole.log(res.from.text.phonetics);// => Reiconsole.log(res.to.text.phonetics);});
importtranslatefrom'@kabeep/node-translate';// Output example sentence of the source wordtranslate('example',{to: 'zh'}).then(res=>{// => [// "it is vitally important that parents should set an [example]",// "she followed her brother's [example] and deserted her family",// "it's a good [example] of how European action can produce results",// ]console.log(res.from.sentences);});
importtranslatefrom'@kabeep/node-translate';// Automatically detect and use the correct source text of suggestedtranslate('Thunk you',{from: 'en',to: 'zh'}).then(res=>{// => 谢谢你console.log(res.to.text.value);// => trueconsole.log(res.from.text.didYouMean);});
importtranslatefrom'@kabeep/node-translate';// Automatically detect and use correct source language codes of suggestedtranslate('example',{from: 'zh',to: 'en'}).then(res=>{// => enconsole.log(res.from.language.iso);// => trueconsole.log(res.from.language.didYouMean);});// Automatically detect and use the correct source text of suggestedtranslate('Thunk you',{from: 'en',to: 'zh'}).then(res=>{// => 谢谢你console.log(res.to.text.value);// => trueconsole.log(res.from.text.didYouMean);});
importtranslatefrom'@kabeep/node-translate';// Retry attempts for the translation request in case of failure (with a maximum of three requests)translate('例子',{to: 'en',retry: 2,timeout: 100}).catch((err)=>{// => ETIMEDOUT - The timeout limits was reached// => ECONNRESET - The connection was forcibly closed// => EADDRINUSE - Could not bind to any free port// => ECONNREFUSED - The connection was refused by the server// => EPIPE - The remote side of the stream being written has been closed// => ENOTFOUND - Could not resolve the hostname to an IP address// => ENETUNREACH - No internet connection// => EAI_AGAIN - DNS lookup timed out// => EPARSE - Unexpected API response data// => EVALIDATION - Illegal language codeconsole.log(err.message);});