How do I tell Cloud Translation API to NOT translate something?
You can use the following HTML tags:
<span translate="no"> </span>
<span class="notranslate"> </span>
This functionality requires the source text to be submitted in HTML.
Why was a style attribute added to the translated text with text-align and direction CSS properties?
This occurs when you include HTML with the requested text to be translated, and you are translating from a right-to-left to a left-to-right language, or from a left-to-right to a right-to-left language. The translation includes the HTML style attribute with the text-align and direction CSS properties to ensure that the translated text is oriented in the proper direction. For example, translating
from English to Hebrew returns the following JSON:
"translatedText": "\u003ch2 style=\";text-align:right;direction:rtl\"\u003e טקסט לדוגמה (דברים) \u003c/h2\u003e"
According to Google instructions, setting class=”notranslate” prevents Google translation. This appears to work, though using it inline (e.g., for a single word) may imply some confusion, so you need to check out what happens.
Welcome to the <span class="notranslate">Cool</span> company website!
translates into Spanish as “Bienvenido a la Coolweb de la compañía!”, which isn’t that cool, though it demonstrates that “Cool” has been taken as a proper name; without the markup, the text would translate as “Bienvenido a la fresca web de la empresa!”.
Reformulating the text as
Welcome to the website of <span class="notranslate">Cool</span>!