Markdown/html translation preserving elements without breaking sentence for translation

i’m working on a blogging/site generation engine in php. it currently already supports multi-language for both integrated strings/template strings and whole markdown pages but the user has to provide those translations.

in the prerelease version, i have integrated connecting to the libretranslate api on a local server or out on the internet with authentication. it works perfectly for existing strings even when they contain placeholders like {p1}, {p2}, etc. these are all plain text.

of course, i am aware libretranslate doesn’t support markdown so, sending markdown content as plain text, i get back some unpredictable results. i wasn’t expecting that to work, though it does work surprisingly well, i must say, to congratulate the devs on the project.

the suggested solution everywhere appears to be converting markdown to html, sending for translation as html then converting back to html. that certainly works and the results are parsed back into markdown without any code problems. what doesn’t work with it, however, is that inline html elements break the flow of translation, which leads to incomprehensible results in the target language.

here’s an example.

english (original) –

we have stopped asking real questions or listening to answers.

french (target) –

nous avons arrêté demandant vraies questions ou écouter aux réponses.

but…

english (source) –

we have stopped asking real questions or listening to answers.

french (target) –

nous avons cessé de poser de vraies questions ou d'écouter des réponses.

while not a perfect translation, it’s comprehensible and grammatically ok french. this isn’t specific to french. i have tried it in spanish, japanese and korean with similar results.

i have tried it with whole test sites worth of text and the issue remains predictable.

i am open to suggestions. if anyone is working on a markdown-friendly solution within the api, i would be happy to offer help testing and an already-working platform integrating it with markdown.

if nobody is already working on it, i’ll likely have to give a shot to writing some custom integration, though i have limited python experience so i hope someone else might already be working on it.

LibreTranslate doesn’t support markdown, but supports html. I would convert markdown to html, translate, then back to markdown. Simply pass the format: html option to the translate request.