Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
[This is preliminary documentation and is subject to change.]
Use the Detect Method to identify the language of a selected piece of text.
Syntax
URI
https://api.microsofttranslator.com/V1/Http.svc/Detect
Parameters
| Parameter | Description |
|---|---|
appId |
A string representing the identifier of the calling application. |
text |
A string representing the text to translate. |
Return Value
The text translated into the desired language.
Example
C#
string detectUri = "https://api.microsofttranslator.com/V1/Http.svc/Detect?appId=myAppId";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(detectUri);
// Request must be HTTP POST to include translation text
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "text/plain";
byte[] bytes = Encoding.ASCII.GetBytes("Detect this text");
Stream os = null;
try
{
// Text is inserted into the body of the request
httpWebRequest.ContentLength = bytes.Length;
os = httpWebRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
}
finally
{
// Close stream if successful
if (os != null)
{
os.Close();
}
}
string output;
try
{
WebResponse response = httpWebRequest.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
output = reader.ReadToEnd();
}
catch (Exception ex)
{
// An error may be thrown if the request body is not recognisable as text
output = "Error - " + ex.Message;
}
Console.WriteLine("Detected Language: " + output);