locked
single quotes in string to translate RRS feed

  • Question

  • I'm using the HTTP api. 

    I have a string to translate that has single quotes in it. when the translated text is returned:

    - sometimes the single quotes are changed to escaped double quotes (with a backslash before each).

    - sometimes the single quotes are removed.

    - sometimes the text inside the single quotes is not translated.

    - when there's a single letter inside the single quotes (e.g. 'S') one quote and the letter is removed and the 2nd quote remains.


    I want the single quotes left alone (especially since this string will be used in javascript). can i escape them before passing. 

    examples and code are below. thanks for helping.

    some examples:

    original: Look at the 'Big Bird' in the sky

    translated: "Mire el Big Bird en el cielo."

    original: "Look at the 'Big Bird' in the 'S' sky."

    translated: "Mirar el 'Big Bird' el ' cielo."

    here's my code. langCode happens to be "ES" but i've seen this with other languages, too.

    var serviceRootUri = new Uri("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/");

    TranslatorContainer tc = new TranslatorContainer(serviceRootUri);

    tc.Credentials = new NetworkCredential(accountKey, accountKey);

    var translationQuery = tc.Translate (original, langCode, "EN");

    var translationResults = translationQuery.Execute ().ToList ();

    string translated = translationResults.First ().Text;

    Thursday, June 6, 2013 8:13 PM

All replies

  • Hi Bill,

    the quotes are interpreted as is customary in the source language, and applied in translation as is customary in the target language. You have no control over the behavior.

    I recommend using HTML mode (contentType="text/html), and tags to represent the position of special tokens (in your case the quotes), and escaping an unescaping the tokens in your own pre- and post-processing.

    http://api.microsofttranslator.com

    Chris Wendt
    Microsoft Translator

    Sunday, June 23, 2013 4:06 AM
  • thanks for you reply. 

    in the doc for the GetTranslations Method the choices for the options argument says, "ContentType: The only supported, and the default, option is "text/plain".  is this out of date?

    could you provide a simple example of tags i would use to translate a string like:

    I recommend using HTML mode (contentType="text/html), and tags to represent the position of special tokens.


    Monday, June 24, 2013 2:28 PM
  • Hi Bill,

    it is correct that AddTranslation and GetTranslations methods only take plain text.

    The Translate and TranslateArray methods take contentType text/plain or text/HTML.

    I recommend using a tag name that is composed of a single letter plus integer, like <D1></D1>.

    Chris Wendt
    Microsoft Translator

    Monday, June 24, 2013 2:37 PM
  • thank you for pointing out the Translate method. 

    since there's no example about this in the doc, i have a few questions:

    - can i use any tag in angle brackets for my own use? 

    - will text inside these tags NOT be translated?

    thanks.

    Monday, June 24, 2013 3:00 PM
  • >- can i use any tag in angle brackets for my own use? 

    No, only HTML tags and the tag format I described: Single letter+digit.

    >- will text inside these tags NOT be translated?

    Text inside HTML elements as well as these single letter+digit elements will be translated, unless you use the translate="no" attribute.

    You cannot use other tags, because their sentence breaking behavior is undefined. The location of sentence breaks is important in translation.

    Monday, June 24, 2013 3:11 PM
  • so, if i pass something like,

    I recommend using HTML mode (contentType=<D1 translate="no">'</D1>text/html<D1 translate="no">'</D1>), and tags to represent the position of special tokens.

    into the Translate method, would the single quotes inside the D1 tags would be left alone? 

    a code example would answer all these questions.

    Monday, June 24, 2013 3:41 PM