Exclude HTML tags when translating with Google Translate API
Asked Answered
J

1

11

Currently I know that <span class="e;notranslate"e;> </span> is used to omit out text to translate between the span.

I am looking out for sending content with HTML tag to Translate API and let it return without translating the tags. Is there anyway that tags could be omitted out before translating and putting them back when the JSON returns with the translated text or is there any syntax to exclude Translate API from translating the HTML tags?

Doing some research before I decide to whether code in JS or Java.

Read this before : Temporary removal of HTML from string for Google Translate API to reduce cost

Josefina answered 24/11, 2015 at 2:25 Comment(0)
J
11

Google have a optional parameter format.

•This optional parameter allows you to indicate that the text to be translated is either plain-text or HTML. A value of "html" indicates HTML and a value of "text" indicates plain-text.

•Default: format=html.

https://cloud.google.com/translate/v2/using_rest

Josefina answered 24/11, 2015 at 3:31 Comment(4)
Will this reduce the cost? Google bill translations per character, but it is not clear if this is translated characterUnshroud
@PlamenVasilev the cost won't be reduced at all cloud.google.com/translate/pricing#charged-charactersJosefina
It clears html tags and returns pure text. How can I maintain html tags?Brucie
The format parameters does nothing for me. No matter whether I set it to "text" or "html", all html tags are removed in the translation.Impolitic

© 2022 - 2024 — McMap. All rights reserved.