0

我有一个英文网站。我使用谷歌翻译将其转换为阿拉伯语。所以现在我的网站有 2 个选项,我可以选择英语或阿拉伯语。现在我遇到的问题是,每当我在文本框中输入数据时,我希望它以阿拉伯语动态翻译并使用 ajax 或 jquery 在文本框中显示它。站点是在 asp.net 中构建的

4

1 回答 1

1

这里有一些想法,如果你愿意,你可以做什么

$('#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){ }
    });
});

这只是一个想法,根据您的要求进行更改。

于 2014-01-28T06:37:32.130 回答