Translate large texts using the google-translate-api for NodeJS!
The google-translate-api uses query string in a GET method to send the text to be translated to the translation service. This limits the amount a characters you can translate at once. This package chops the texts into smaller, coherent sentences, translates them and mount them back together into the text. This is all done asynchronously, so it won't block your code midway!
It return an object with a single method: translate. Couldn't be simpler!
Simply run
$ npm install limitless-google-translate
Import it into you project
var limitless = require('limitless-google-translate')
And use it at will!
limitless.translate(VERY_LARGE_TEXT_HERE, {to: 'pt'})
.then( (result) => {
console.log( result.text )
})
.catch( (err) => {
console.log( new Error(err) )
})
Do you wish to use the regular and limited google-translate-api? Just do:
limitless.legacy(BORING_SMALL_TEXT_HERE, {to: 'pt'})
.then( (result) => {
console.log( result.text )
})
.catch( (err) => {
console.log( new Error(err) )
})
The legacy object is a direct import from the regular api, so to use it just refer to here
result: {
text:, // Fully translated text
response: [][] //Ordered 2D array in sequence with all the
//sentences translated. The object inside
//each element of the array is the as describe here:
//https://github.com/matheuss/google-translate-api#returns-an-object
}
Feel free to contact me or submit a pull request. I will be thrilled to help you!