Export (0) Print
Expand All

AddTranslationArray Method

Adds an array of translations to add translation memory. This is an array version of AddTranslation().

Request
Request URI
http://api.microsofttranslator.com/V2/Ajax.svc/AddTranslationArray

URI parameters
Parameter Description

appId

Required. A string containing "Bearer" + " " + access token.

translations

Required. An array of translations to add to translation memory. Each translation must contain: originalText, translatedText, rating. The size of each originalText and translatedText is limited to 1000 chars. The total of all the originalText(s) and translatedText(s) must not exceed 10000 characters. The maximum number of array elements is 100.

from

Required. A string containing the language code of the source language. Must be a valid culture name.

to

Required. A string containing the language code of the target language. Must be a valid culture name.

options

A set of options. TranslateOptions contain: uri, category, contentType, user.

User is required. Category, ContentType and Uri are optional.

Ff512394.alert_note(en-us,MSDN.10).gif Note

Bing App ID is deprecated and is no longer supported.   Please obtain an access token to use the Microsoft Translator API. For details, go here.


Example

Obtain an Access Token on the server-side

                                               
[System.Web.Services.WebMethod]
public static AdmAccessToken GetAccessToken()
{
    AdmAccessToken admToken;
    string headerValue;
    //Get Client Id and Client Secret from https://datamarket.azure.com/developer/applications/
    AdmAuthentication admAuth = new AdmAuthentication("clientid", "clientsecret");

    admToken = admAuth.GetAccessToken();
    // Create a header with the access_token property of the returned token
    headerValue = "Bearer" + " " + HttpUtility.UrlEncode(admToken.access_token);

    return admToken;
} 
                                            
Invoke the AJAX method on the client-side

                                            
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript">
        var originalText1 = encodeURIComponent("una importante contribución a la rentabilidad de la empresa.");
        var translatedText1 = encodeURIComponent("an important contribution to the company profitability.");
        var originalText2 = encodeURIComponent("a veces los errores son divertidos");
        var translatedText2 = encodeURIComponent("in some cases errors are fun");
        function addTranslationArray() {
            PageMethods.GetAccessToken(OnSucceeded, OnFailed);
        }
        function OnSucceeded(result, usercontext, methodName) {

            var languageFrom = "es";
            var languageTo = "en";

            var firstText = "{"
                       + "\"OriginalText\": \"" + originalText1 + "\""
                       + ", \"TranslatedText\": \"" + translatedText1 + "\""
                       + ", \"Rating\": \"" + "5" + "\""
                       + "}";


            var secondText = "{"
                       + "\"OriginalText\": \"" + originalText2 + "\""
                       + ", \"TranslatedText\": \"" + translatedText2 + "\""
                       + ", \"Rating\": \"" + "8" + "\""
                       + "}";

            var arrayText = "[" + firstText + ", " + secondText +  "]";
            var options = "{\"User\":\"TestUserId\"}";

            var s = document.createElement("script");
            s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/AddTranslationArray?"
                    + "appId=Bearer " + encodeURIComponent(result.access_token)
                    + "&translations=" + arrayText
                    + "&from=" + languageFrom
                    + "&to=" + languageTo
                    + "&options=" + options;
            document.getElementsByTagName("head")[0].appendChild(s);
            alert("Translations have been submitted.");
        }
        function OnFailed(error, userContext, methodName) {
            alert("Error");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
        <br />
        <asp:Button ID="buttonAddTransArray" runat="server" Text="Add Translation array"
            OnClientClick="addTranslationArray();return false;" />
    </div>
    </form>
</body>
</html>
                                            
Show:
© 2014 Microsoft