diff --git a/webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue b/webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue index 7e6dfbcb..78c6c40e 100644 --- a/webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue +++ b/webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue @@ -66,13 +66,19 @@ export default { this.handleTranslatedTitle(translated.translation); fetchAutoTranslation(this.news.summary).then(translated => { this.handleTranslatedSummary(translated.translation); - fetchAutoTranslation(this.news.body).then(translated => { + const content = this.toHtml(this.news.body).replace(/ /gi, '@nbsp@'); + fetchAutoTranslation(this.toHtml(content)).then(translated => { this.handleTranslatedContent(translated.translation); }); }); }); } }, + toHtml(content) { + const domParser = new DOMParser(); + const docElement = domParser.parseFromString(content, 'text/html').documentElement; + return docElement?.children[1].innerHTML; + }, resetAutoTranslation() { this.isResetAutoTranslating = true; this.autoTranslatedTitle = this.autoTranslatedSummary = this.autoTranslatedContent = null; @@ -90,7 +96,7 @@ export default { this.updateNewsSummary(translatedText); }, handleTranslatedContent(translatedText) { - this.autoTranslatedContent = translatedText.replace('
', ''); + this.autoTranslatedContent = translatedText.replace(/@nbsp@/gi, ' '); this.updateNewsContent(this.autoTranslatedContent); this.checkAutoTranslatedStatus(); }, diff --git a/webapps/src/main/webapp/javascript/automatic-translation/components/NoteAutomaticTranslation.vue b/webapps/src/main/webapp/javascript/automatic-translation/components/NoteAutomaticTranslation.vue index a516a31e..8fb81f1a 100644 --- a/webapps/src/main/webapp/javascript/automatic-translation/components/NoteAutomaticTranslation.vue +++ b/webapps/src/main/webapp/javascript/automatic-translation/components/NoteAutomaticTranslation.vue @@ -65,7 +65,8 @@ export default { this.isAutoTranslating = true; fetchAutoTranslation(this.note.title).then(translated => { this.handleTranslatedTitle(translated.translation); - fetchAutoTranslation(this.note.content).then(translated => { + const content = this.note.content.replace(/ /gi, '@nbsp@'); + fetchAutoTranslation(content).then(translated => { this.handleTranslatedContent(translated.translation); }); }); @@ -100,7 +101,7 @@ export default { this.checkAutoTranslatedStatus(); }, handleTranslatedContent(translatedText) { - this.autoTranslatedContent = translatedText.replace('', '
'); + this.autoTranslatedContent = translatedText.replace(/@nbsp@/gi, ' '); this.updateNoteContent(this.autoTranslatedContent); this.previouslySelectedVersion = this.selectedTranslation; this.updateSelectedTranslation(this.autoTranslation);