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.]
Translates a string into a different language.
Syntax
URI
https://api.microsofttranslator.com/V1/Http.svc/Translate
Parameters
| Parameter | Description |
|---|---|
appId |
A string representing the identifier of the calling application. |
text |
A string representing the text to translate. |
from |
A string representing the language code of the translation text. |
to |
A string representing the language code to translate the text into. |
Return Value
The text translated into the desired language.
Example
C#
string translateUri = "https://api.microsofttranslator.com/V1/Http.svc/Translate?appId=myAppId&from=en&to=es";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(translateUri);
// Request must be HTTP POST to include translation text
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "text/plain";
byte[] bytes = Encoding.ASCII.GetBytes("Translate 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
// An error may be thrown if the from and to parameters are the same
output = "Error - " + ex.Message;
}
Console.WriteLine("Result: " + output);