Export (0) Print
Expand All

GetLanguageNames Method

Retrieves friendly names for the languages passed in as the parameter languageCodes, and localized using the passed locale language.

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

URI parameters
Parameter Description

appId

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

locale

Required. A string representing a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code to localize the language names or a ISO 639 lowercase culture code by itself.

languageCodes

Required. A string array representing the ISO 639-1 language codes to retrieve the friendly name for.


Response
Return value
A string array containing the friendly language names of the passed languageCodes.

Ff512399.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 languageCodes = "[\"de\", \"fr\", \"it\"]";
        function getLanguageNames() {
            PageMethods.GetAccessToken(OnSucceeded, OnFailed);

        }
        function OnSucceeded(result, usercontext, methodName) {

            window.mycallback = function (response) {
                var array = response;
                var languageNames = "";
                for (var i = 0; i < array.length; i++) {
                    languageNames = languageNames + array[i] + "\n";
                }
                alert(languageNames);
            }

            var s = document.createElement("script");
            s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguageNames?oncomplete=mycallback&appId=Bearer " + encodeURIComponent(result.access_token) + "&locale=en&languageCodes=" + languageCodes;
            document.getElementsByTagName("head")[0].appendChild(s);
        }
        function OnFailed(error, userContext, methodName) {
            alert("Error");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
        <asp:Button ID="buttonLangName" runat="server" Text="Get Language names" OnClientClick="getLanguageNames();return false;" />
    </div>
    </form>
</body>
</html>
                                            
Show:
© 2014 Microsoft