Why does it need to be a JavaScript API?
Why not just use the lang= attribute as it was intended, then let the user select text to translate as they wish?
replies(2):
Why not just use the lang= attribute as it was intended, then let the user select text to translate as they wish?
Instead, a JS API gives more flexibility and control.
Besides, I think the "lang" attribute is supposed to signal what the language of the text inside that element is, not what it could/should be. So even if going with attributes would be the way forward, a new one would need to be created.