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

Multiple Words Look-up #10

Open
hossein1376 opened this issue Dec 13, 2021 · 3 comments
Open

Multiple Words Look-up #10

hossein1376 opened this issue Dec 13, 2021 · 3 comments

Comments

@hossein1376
Copy link

Hello, thank you for the awesome work. May I ask if is it possible to receive translation for multiple words at the same time? If so, how should the code look like?
Appreciate it. (I'm new at coding, sorry if this is a basic issue)

@FreddieDeWitt
Copy link
Owner

Hi!

If I understood correctly, you want the request to be processed simultaneously.

The easiest way to do that is to use Promise.all:

const translate = require('extended-google-translate-api');

Promise.all([
    translate("parlous", "en", "de"), 
    translate("chivalrous", "en", "de"), 
    translate("promiscuous", "en", "de")]).then((wordsObjects) => {
    for (wordData of wordsObjects)
        console.log(JSON.stringify(wordData, undefined, 2));
}).catch(console.log);

@hossein1376
Copy link
Author

Excellent, it works beautifully!
If I may bother you with one more question, how can I save the translations into a text file?

@FreddieDeWitt
Copy link
Owner

FreddieDeWitt commented Dec 14, 2021

JSON.stringify returns you a string that you can easily write to a file. E.g. here it is explained, how to write to a text file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants