Translate text box data dynamically using google translate and jquery in c# asp.net

2.8k Views Asked by At

I have a web site which is in English. I have used google translate in order to convert it to arabic language.So now I have 2 options for my web site I can choose English or Arabic. Now the problem which I have is whenever I enter data inside text box i want it to translate dynamically in arabic and show it inside text box using ajax or jquery.?And site is built in asp.net

1

There are 1 best solutions below

1
On

Here is some idea what you can do if you want

$('#txtId').focusOut(function() {

    //Call the Google API
    $.ajax({
        type : "GET",
        url : "https://ajax.googleapis.com/ajax/services/language/translate",
        dataType : 'jsonp',
        cache: false,
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        data : "v=1.0&q="+  $('#txtId').val()+"&langpair=en|es",
        success : function(iData){
            //update the value
             $('#txtId').val(iData["responseData"]["translatedText"]);      
        },
        error:function (xhr, ajaxOptions, thrownError){ }
    });
});

this is just an idea change it according your requirement.