From 547897bd6225dcb628a660c7cb2d45ab18bbb418 Mon Sep 17 00:00:00 2001 From: Helmi Akermi <70575401+hakermi@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:26:42 +0100 Subject: [PATCH] feat: Update note auto translation extension - EXO-73673 - Meeds-io/MIPs#128 (#89) Update note auto translation extension --- .../components/NoteAutomaticTranslation.vue | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/webapps/src/main/webapp/vue-apps/automatic-translation-extensions/notes-extension/components/NoteAutomaticTranslation.vue b/webapps/src/main/webapp/vue-apps/automatic-translation-extensions/notes-extension/components/NoteAutomaticTranslation.vue index 171e3a95..de190906 100644 --- a/webapps/src/main/webapp/vue-apps/automatic-translation-extensions/notes-extension/components/NoteAutomaticTranslation.vue +++ b/webapps/src/main/webapp/vue-apps/automatic-translation-extensions/notes-extension/components/NoteAutomaticTranslation.vue @@ -43,7 +43,7 @@ export default { previouslyTranslatedVersion: null, autoTranslatedContent: null, autoTranslatedTitle: null, - hasContent: false + autoTranslatedSummary: null, }; }, props: { @@ -80,23 +80,32 @@ export default { this.isAutoTranslating = true; this.$automaticTranslationExtensionsService.fetchAutoTranslation(this.note.title).then(translated => { this.handleTranslatedTitle(translated.translation); - if (this.note?.content) { - this.hasContent = true; - const content = this.excludeHtmlSpaceEntities(this.note.content); - this.$automaticTranslationExtensionsService.fetchAutoTranslation(content).then(translated => { - this.handleTranslatedContent(translated.translation); - this.setAutoTranslationSelected(); - this.previouslyTranslatedVersion = this.selectedTranslation; - this.isAutoTranslating = false; - }).catch(() => this.isAutoTranslating = false); + const summary = this.note?.properties?.summary; + if (summary) { + this.$automaticTranslationExtensionsService.fetchAutoTranslation(summary).then(translated => { + this.handleTranslatedSummary(translated.translation); + if (this.note?.content) { + this.fetchContentTranslation(); + } + }); + } else if (this.note?.content) { + this.fetchContentTranslation(); } else { - this.hasContent = false; this.setAutoTranslationSelected(); this.isAutoTranslating = false; } }).catch(() => this.isAutoTranslating = false); } }, + fetchContentTranslation() { + const content = this.excludeHtmlSpaceEntities(this.note.content); + this.$automaticTranslationExtensionsService.fetchAutoTranslation(content).then(translated => { + this.handleTranslatedContent(translated.translation); + this.setAutoTranslationSelected(); + this.previouslyTranslatedVersion = this.selectedTranslation; + this.isAutoTranslating = false; + }).catch(() => this.isAutoTranslating = false); + }, excludeHtmlSpaceEntities(content) { return content.replace(/ /gi, ' '); }, @@ -113,6 +122,9 @@ export default { if (this.autoTranslatedContent) { this.handleTranslatedContent(this.autoTranslatedContent); } + if (this.autoTranslatedSummary) { + this.handleTranslatedSummary(this.autoTranslatedSummary); + } this.updateSelectedTranslation(this.autoTranslation); }, updateNoteContent(content) { @@ -121,6 +133,9 @@ export default { updateNoteTitle(title) { this.$root.$emit('update-note-title', title); }, + updateNoteSummary(summary) { + this.$root.$emit('update-note-summary', summary); + }, updateSelectedTranslation(translation) { this.$root.$emit('update-selected-translation', translation); }, @@ -129,6 +144,7 @@ export default { this.autoTranslatedContent = this.autoTranslatedTitle = null; this.updateNoteTitle(this.note.title); this.updateNoteContent(this.note.content); + this.updateNoteSummary(this.note?.properties?.summary); this.updateSelectedTranslation(this.previouslyTranslatedVersion); this.isResetAutoTranslating = false; }, @@ -136,6 +152,10 @@ export default { this.autoTranslatedTitle = translatedText; this.updateNoteTitle(translatedText); }, + handleTranslatedSummary(translatedText) { + this.autoTranslatedSummary = translatedText; + this.updateNoteSummary(translatedText); + }, handleTranslatedContent(translatedText) { this.autoTranslatedContent = this.restoreHtmlSpaceEntities(translatedText); this.updateNoteContent(this.autoTranslatedContent);