Charles Yeung Charles Yeung - 1 year ago 106
Javascript Question

JavaScript/jQuery - Get text and translate it

Is it possible to use jQuery to get a text from an element and translate it to other languages?





Answer Source

Use Google translation API. Easy to use. The following translates Spanish to English. To translate from and to other languages, simply change 'es' and 'en'

<div id="content"></div>

google.load("language", "1");

function initialize() {
    var content = document.getElementById('content');
    content.innerHTML = '<div id="text">Hola, me alegro mucho de verte.<\/div><div id="translation"/>';
    var text = document.getElementById("text").innerHTML;
    google.language.translate(text, 'es', 'en', function(result) {
        var translated = document.getElementById("translation");
        if (result.translation) {
            translated.innerHTML = result.translation;

Check working example at

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download