<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<div>
<asp:updatepanel id="UpdatePanel12" runat="server">
<ContentTemplate>
<div style="position: relative;width: 324px; margin-left: 20px; margin-top:20px;
margin-bottom:20px;">
<asp:Label ID="lblInstructions" runat="server" Width="359px" Text="Enter some text for the language
you want detected:"></asp:Label>
</div>
<!-- Input for the text we want detected -->
<div style="position: relative; width: 324px; margin-left: 20px; margin-bottom:10px;">
<asp:TextBox ID="txtInput" runat="server" Width="359px" Height="200px"
TextMode="MultiLine"></asp:TextBox>
</div>
<!-- Button and click event to get the language culture codes via the SOAP API -->
<div style="position: relative;width: 167px; margin-left: 20px; margin-bottom:20px;">
<asp:Button ID="btnDetect" runat="server" Text="Detect Language"
onclick="btnDetect_Click" />
</div>
<!-- Label to output the detected culture code -->
<div style="position: relative;width: 324px; margin-left: 20px; margin-bottom:20px;">
<asp:Label ID="lblOutput" runat="server" Width="602px"></asp:Label>
</div>
<fieldset>
<legend>Results</legend>
<table>
<tr>
<td>
Easily use the Microsoft Translator SOAP API to detect the language of specific
text by parsing text to the Detect funtion which then returns the culture code
of the entered text.
</td>
</tr>
<tr>
<td>
Enter some text in the box above and click the 'Detect Language' button and the
detected culture code will be displayed. Click the Code-Behind tab above to see
exactly how this is done in c#.
</td>
</tr>
</table>
</fieldset>
</ContentTemplate>
</asp:updatepanel>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
namespace InteractiveSDK.SOAP
{
public partial class SOAPDemo1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// Click event for the button to detect culture code
protected void btnDetect_Click(object sender, EventArgs e)
{
try
{
// Create an instance of the translator service
TranslatorService.LanguageServiceClient client =
new TranslatorService.LanguageServiceClient();
// Call the detect method and parse the appId and input from the textbox
// Results are stored in the locale string
string locale = client.Detect("yourAppId", txtInput.Text);
// Output the result to the label
lblOutput.Text = "The detected language is: " + locale;
}
catch
{
// Catch any errors in detecting the langauge
lblOutput.Text = "The entered text is not valid.";
}
}
}
}