Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion about translateBatch() #11

Open
pasagedev opened this issue Oct 31, 2021 · 4 comments
Open

suggestion about translateBatch() #11

pasagedev opened this issue Oct 31, 2021 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers Hacktoberfest hacktoberfest label

Comments

@pasagedev
Copy link
Contributor

For now translateBatch works well if all elements of array works for translateText(). For instance, the next one:

const texts = ["bonsoir le monde", "Hallo Welt", "guten morgen"];
  google
    .translateBatch(texts)
    .then(res => console.log("batch translation: ", res));

But fails if some element doesn't work properly, For instance this:

const texts = ["", "Hallo Welt", "guten morgen"];
  google
    .translateBatch(texts)
    .then(res => console.log("batch translation: ", res));

It could be interesting if the translation continues if some translation fails for some elements and function return an array with errors messages also.

@nidhaloff
Copy link
Owner

@pasagedev hmm I agree. Maybe It would be better to continue the execution. Would you like to add/work on this

@pasagedev
Copy link
Contributor Author

Sure, I could like works on that 👍

@nidhaloff nidhaloff added enhancement New feature or request good first issue Good for newcomers Hacktoberfest hacktoberfest label labels Oct 31, 2021
@SinaElahimanesh
Copy link

SinaElahimanesh commented Feb 3, 2022

Hello,
I solved it by adding a new function, alternativeBatchTranslation, in batchTrans.js file.
In case of error, it catches the error and by finding the error reason, translates all the words and also returns the error type.
So in case of
const texts = ["", "Hallo Welt", "guten morgen"]; google .translateBatch(texts) .then(res => console.log("batch translation: ", res));
The result will be like bellow:
[ 'ERROR: error translating batch: The input text length must be of type string between 1 and 5000 characters', 'Hello World', 'Good morning' ]
As it can be seen the first box has an error, and the second and third element is translated successfully =)

I am eagerly waiting for you to merge my pull request and accept it.
Thanks a lot.
Sina Elahimanesh

@nithintejesh
Copy link

i would like to work on this if nobody's working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Hacktoberfest hacktoberfest label
Projects
None yet
Development

No branches or pull requests

4 participants