Export (0) Print
Expand All

AddTranslation Method

Adds a translation to the translation memory.

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

URI parameters
Parameter Description
appId

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

originalText

Required. A string containing the text to translate from. The string has a maximum length of 1000 characters.

translatedText

Required. A string containing translated text in the target language. The string has a maximum length of 2000 characters.

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.

rating

Optional. An int representing the quality rating for this string. Value between -10 and 10. Defaults to 1.

contentType

Optional. The format of the text being translated. The supported formats are "text/plain" and "text/html". Any HTML needs to be well-formed.

category

Optional. A string containing the category (domain) of the translation. Defaults to "general".

user

Required. A string used to track the originator of the submission.

uri

Optional. A string containing the content location of this translation.


Ff512393.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 runat="server">
    <title></title>
    <script type="text/javascript">
        var originalText = encodeURIComponent("una importante contribución a la rentabilidad de la empresa.");
        var translatedText = encodeURIComponent("an important contribution to the company profitability.");
        function addTranslation() {
            PageMethods.GetAccessToken(OnSucceeded, OnFailed);
        }
        function OnSucceeded(result, usercontext, methodName) {

            var s = document.createElement("script");
            s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/AddTranslation?appId=Bearer " + encodeURIComponent(result.access_token) + "&originalText="
            + originalText + "&translatedText=" + translatedText + "&from=es&to=en&user=TestUserId";
            document.getElementsByTagName("head")[0].appendChild(s);
            alert("Translation 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="buttonAddTrans" runat="server" Text="Add Translation" OnClientClick="addTranslation();return false;" />
    </div>
    </form>
</body>
</html>

      
Show:
© 2014 Microsoft