Windows Translator:“ArgumentOutOfRangeException:'to'必须是有效的语言

时间:2015-08-11 15:45:57

标签: javascript c# asp.net asp.net-mvc translation

我正在尝试使用Bing Translator ...

已经有一个令牌(我认为),但是当试图获得翻译时,总会弹出相同的错误:

"ArgumentOutOfRangeException: 'to' must be a valid language\u000d\u000aParameter name: to : ID=5217.V2_Json.Translate.5FEAF805"

接下来是我正在使用的网址,我不知道错误在哪里......

https://api.microsofttranslator.com/V2/Ajax.svc/Translate?
&appId=Bearer%20http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=TranslateHelper000&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&Audience=http%3a%2f%2fapi.microsofttranslator.com&ExpiresOn=1439307776&Issuer=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&HMACSHA256=xGQ7LMehBDHJLY2Xq7jN8PXOhRCYqs%2boUb2V4Ic4XLI%3d
&from=en
&to=pt
&text=Home
&oncomplete=mycallback

(pt被定义为翻译中的语言......它与to = en ...

无关

我的问题是,如果你可以帮助我: 这是正常的令牌吗? 2.这是正常的,代码有什么问题? (我没有更多的头发可以脱掉......)

这是我用来发送网址的代码(mycallback也没有被调用):

$.ajax({
        type: "POST",
        url: 'getTranslatorToken',
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    }).done(function (token) {


        var languageFrom = "en";
        var languageTo = "pt";
        var textToTranslate = "Home";

        var strToken = token["access_token"];
        var s = document.createElement("script");
        //s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=mycallback&appId=Bearer " + token + "&from=" + languageFrom + "&to=" + languageTo + "&text=" + $('#txtMsg').val();
         s.src = "https://api.microsofttranslator.com/V2/Ajax.svc/Translate?&appId=Bearer " + strToken +
            "&from=" + encodeURIComponent(languageFrom) +
            "&to=" + encodeURIComponent(languageTo) +
            "&text=" + encodeURIComponent(textToTranslate) +
            "&oncomplete=mycallback";


        document.getElementsByTagName("head")[0].appendChild(s);
        console.log(s)
    }).fail(function (xhr, ajaxOptions, thrownError) {
        alert("Error:"+xhr.responseText);
        console.log(xhr.responseText);
        //$("#msg").text('Error');
    });

感谢

1 个答案:

答案 0 :(得分:-1)

这个问题在这里得到解答(在C#中):

.get_text()

此处的工作示例(PHP):How to translate specific content in website