I'm trying to use Google Translate to translate text from a text box in javascript. I don't want to translate my entire web page but just the text within the text box.
this is my error: 'Uncaught TypeError: Cannot read property 'translate' of undefined'
this is my code:
function translate(lang) {
var text = document.getElementById('textArea').value
google.load('language', '1');
function initialize(text) {
google.language.translate(text, 'en', 'es', function (result) {
var translated = document.getElementById('textArea2');
if (result.translation) {
translated.innerHTML = result.translation;
}
});
}
google.setOnLoadCallback(initialize(text));
}