Issues with DeepL Api not translating past new line in Axios

816 Views Asked by At

This may not be the correct forum to ask this question, but perhaps some have experience with implementing the DeepL API.

I make a Get request via Axios for a sample letter, containing paragraphs, however while the variable that is passed in contains the correct input, anything past a newline is not returned. I have adjusted the paramters for HTML tag handling, but this makes no difference. Any ideas?

It seems clear that the HTML tags are the issue here (it skips everything between the final paragraph tags.

const text = <p style="margin-left:0px;">Cher Julia,</p><p style="margin-left:0px;">&nbsp;</p><p style="margin-left:0px;">J’ai le plaisir d’écrire cette lettre pour te décrire la ville où je suis allée pour mes vacances. Je pense que tout va bien à New York. Et tes parents, je pense qu’ils se portent bien.</p>

Returned Output:

<p style="margin-left:0px;">Cher Julia,</p><p style="margin-left:0px;">

Get Request:

  returnTranslation(text, source_lang) {
axios.get(`https://api.deepl.com/v2/translate?auth_key=xxxxxxx&text=${text}&target_lang=${source_lang}&tag_handling=html`)
  .then((response) => {
    console.log(text, response.data)
    const translated_text = response.data.translations[0].text;
    return translated_text;
  }).then((translated_text) => {
    this.insertTranslation(translated_text)
  })
}

PS: The tags are a byproduct of pulling comment info from a Zendesk client, when I re-insert this translation they are no longer present/an issue.

1

There are 1 best solutions below

0
On

I am not sure what environment you are using, but if you are using Node.js the official DeepL Node.js client library may help simplify your work.

However, if you need to use Axios directly, regarding your example: I believe the problem is with your query. The text parameter is not URL-encoded, so the &nbsp part is interpreted as a new argument rather than a continuation of the text argument. You should URL-encode the text argument before inserting it into the query.