Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Inconsistent whitespace handling and required to specify undocumented format_

I'm using v2.   I need to translate text like the below, which have important whitespace (leading/trailing, new lines \n, tabs \t).  The API seems to respect the leading whitespace and \n, but drops trailing whitespace and \t.  Furthermore, I have to specify the undocumented format_ parameter to avoid symbols like ' being output as HTML entities.  Is it possible to use the translate API and respect whitespace? 

```
translate_client.translate(" it's a sentence.\n\tAnd here is a new one ", 'fr', format_='text')

```

Result:

```
{'translatedText': " c'est une phrase.\nEt en voici un nouveau",
'detectedSourceLanguage': 'en',
'input': " it's a sentence.\n\tAnd here is a new one "}

```

0 1 787
1 REPLY 1

Hi @kellymarchisio

Welcome and thank you for reaching out to our community.

I understand that you wanted to keep the newline and tab tags in your sentences during and after the translation process. There are a couple of possible options for you; kindly look into the preserve_formatting parameter or the translate_document method.

Here are some resources for your reference.

Hope this helps.