0

I have a for loop to translate text of every index in loop but when I pass variable in translate function it get random index value and does not follow 0 to x index values .

var arr=['bad','school','teacher'];
for (var i = 0; i < arr.length; i++) {
var txt=arr[i];
console.log(txt);

translate(txt, {from: 'en', to: 'ur'}).then(res => {
  console.log(res.text);
});
}

Result
bad shcool teacher برا استاد سکول In translated text translate function does arr[0] first then arr[2] and then arr[1] . why it does not follow arr[0],arr[1],arr[2] pattern

Ghost
  • 49
  • 1
  • 10

1 Answers1

0

I can give you only some ideas about the issue, I hope this will help you.

First you have to call you function with like this:

function translate(txt, {from: 'en', to: 'url'}).then(res => {
console.log(res.text);
});

But there is still an error and I don't know where you are stuck in. So please look through this links which I found for you.

https://cloud.google.com/translate/docs/ https://cloud.google.com/translate/docs/quickstart

How to get the browser to navigate to URL in JavaScript

Please let me know whether this is what you want to do.

Best regards, Patrick

Patrick
  • 11
  • 1