deepl-node icon indicating copy to clipboard operation
deepl-node copied to clipboard

Translating HTML with English text to French adds HTML Tags and full sentence that is not in the input text

Open wilhelmberghammer opened this issue 1 year ago • 1 comments

Describe the bug When translating a English text with HTML elements to French, the response contains unexpected additional HTML Tags and often a full sentence that was not in the input.

To Reproduce Minimal JS Script to reproduce the Error (last tested on March 9th 2024 6PM CET)

const deepl = require('deepl-node')
const authKey = "<authkey>"
const translator = new deepl.Translator(authKey)

async function translate(targetLang) {
	const result = await translator.translateText('<p><strong>Testing the system</strong></p>', 'en', targetLang, tag_handling = 'html')
	console.log(result)
}

translate('de')
translate('fr')

This results in the following responses:

{
  text: '<p><strong>Test des Systems</strong></p>',
  detectedSourceLang: 'en'
}
{
  text: "</p><strong>Tester le système</strong></p><strong></p><strong>La mise en place d'un système de gestion de l'information est une priorité.",
  detectedSourceLang: 'en'
}

The German translation is correct but the French translation has <strong></p><strong>La mise en place d'un système de gestion de l'information est une priorité. appended to a seemingly correct result.

I've noticed that without the <strong> Tag it does not happen but I have not tested that exhaustively.

Thank you very much.

wilhelmberghammer avatar Mar 09 '24 17:03 wilhelmberghammer

@wilhelmberghammer I think your syntax is a bit off from the documentation. Try this, where tag_handling is converted to camelCase and passed inside of an "options" object.

const result = await translator.translateText(
  '<p><strong>Testing the system</strong></p>', 
  'en',
  targetLang, 
  {tagHandling: 'html'}
);

macleanweb avatar Mar 25 '24 16:03 macleanweb

Thank you. Sorry for the oversight.

wilhelmberghammer avatar May 30 '24 12:05 wilhelmberghammer