GetLanguagesForTranslate Method
Obtain a list of language codes representing languages that are supported by the Translation Service. Translate() and TranslateArray() can translate between any of these languages.
| Request URI |
|---|
| http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguagesForTranslate |
| Parameter | Description |
|---|---|
|
appId |
Required. A string containing "Bearer" + " " + access token. |
| Return value |
|---|
| A string array containing the language codes supported by the Translator Services. |
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;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var languageCodes = "[\"de\", \"fr\", \"it\"]";
function getLanguagesForTranslate() {
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] + "<br />";
}
document.getElementById('<%= lblResult.ClientID %>').innerHTML = languageNames;
}
var s = document.createElement("script");
s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguagesForTranslate?oncomplete=mycallback&appId=Bearer " + encodeURIComponent(result.access_token);
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="buttonLangSpeak" runat="server" Text="Get Language names" OnClientClick="getLanguagesForTranslate();return false;" />
<br />
<asp:Label ID="lblResult" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Note