A powerful, secure and feature-rich api via Google Translation.
Package Exports
@kabeep/node-translate
@kabeep/node-translate/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kabeep/node-translate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A powerful, secure and feature-rich api via Google Translation.
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.
import translate from'@kabeep/node-translate';// Language name and capitalized correctiontranslate('例子',{to:'ENGlish'}).then(res=>{// => example
console.log(res.text);});
import translate from'@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=>{// => example
console.log(res.text);});
Phonetic transcription of the source text and translation
import translate from'@kabeep/node-translate';// Output phonetic transcription of the source text and the translated texttranslate('例子',{to:'ja'}).then(res=>{// => Lìzi
console.log(res.from.text.phonetics);// => Rei
console.log(res.to.text.phonetics);});
import translate from'@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);});
import translate from'@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);// => true
console.log(res.from.text.didYouMean);});
import translate from'@kabeep/node-translate';// Automatically detect and use correct source language codes of suggestedtranslate('example',{from:'zh',to:'en'}).then(res=>{// => en
console.log(res.from.language.iso);// => true
console.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);// => true
console.log(res.from.text.didYouMean);});
import translate from'@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 code
console.log(err.message);});