From b7cec6ca1dc12daa0837dc45d440f383f91f0070 Mon Sep 17 00:00:00 2001 From: Helmi Akermi <70575401+hakermi@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:03:17 +0100 Subject: [PATCH] feat: Add automatic translation extension for news - EXO-65764 (#48) Add automatic translation extension for news --- .../components/NewsAutomaticTranslation.vue | 120 ++++++++++++++++++ .../components/NoteAutomaticTranslation.vue | 24 +--- .../automatic-translation/extensions.js | 10 +- .../automatic-translation/initComponents.js | 4 +- .../automaticTranslationServices.js | 16 +++ 5 files changed, 154 insertions(+), 20 deletions(-) create mode 100644 webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue diff --git a/webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue b/webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue new file mode 100644 index 00000000..7e6dfbcb --- /dev/null +++ b/webapps/src/main/webapp/javascript/automatic-translation/components/NewsAutomaticTranslation.vue @@ -0,0 +1,120 @@ + + + \ No newline at end of file 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 19781567..a516a31e 100644 --- a/webapps/src/main/webapp/javascript/automatic-translation/components/NoteAutomaticTranslation.vue +++ b/webapps/src/main/webapp/javascript/automatic-translation/components/NoteAutomaticTranslation.vue @@ -22,6 +22,10 @@ diff --git a/webapps/src/main/webapp/javascript/automatic-translation/extensions.js b/webapps/src/main/webapp/javascript/automatic-translation/extensions.js index eebe144d..5a8b0ca0 100644 --- a/webapps/src/main/webapp/javascript/automatic-translation/extensions.js +++ b/webapps/src/main/webapp/javascript/automatic-translation/extensions.js @@ -100,13 +100,21 @@ }); extensionRegistry.registerExtension('notes', 'translation-menu-extension', { - id: 'auto-translate', + id: 'notes-auto-translate', rank: 1000, componentOptions: { vueComponent: Vue.options.components['note-automatic-translation'], }, }); + extensionRegistry.registerExtension('news', 'translation-menu-extension', { + id: 'news-auto-translate', + rank: 1000, + componentOptions: { + vueComponent: Vue.options.components['news-automatic-translation'], + }, + }); + extensionRegistry.registerComponent('ActivityContent', 'activity-content-extensions', { id: 'translatedBody', vueComponent: Vue.options.components['activity-translated-body'], diff --git a/webapps/src/main/webapp/javascript/automatic-translation/initComponents.js b/webapps/src/main/webapp/javascript/automatic-translation/initComponents.js index 22e07bd4..9b237758 100644 --- a/webapps/src/main/webapp/javascript/automatic-translation/initComponents.js +++ b/webapps/src/main/webapp/javascript/automatic-translation/initComponents.js @@ -17,11 +17,13 @@ import ActivityTranslatedBody from './components/ActivityTranslatedBody.vue'; import ActivityCommentTranslatedBody from './components/ActivityCommentTranslatedBody.vue'; import NoteAutomaticTranslation from './components/NoteAutomaticTranslation.vue'; +import NewsAutomaticTranslation from './components/NewsAutomaticTranslation.vue'; const components = { 'activity-translated-body': ActivityTranslatedBody, 'activity-comment-translated-body': ActivityCommentTranslatedBody, - 'note-automatic-translation': NoteAutomaticTranslation + 'note-automatic-translation': NoteAutomaticTranslation, + 'news-automatic-translation': NewsAutomaticTranslation }; for (const key in components) { diff --git a/webapps/src/main/webapp/vue-apps/automatic-translation-administration/automaticTranslationServices.js b/webapps/src/main/webapp/vue-apps/automatic-translation-administration/automaticTranslationServices.js index b8049c90..5ea5a253 100644 --- a/webapps/src/main/webapp/vue-apps/automatic-translation-administration/automaticTranslationServices.js +++ b/webapps/src/main/webapp/vue-apps/automatic-translation-administration/automaticTranslationServices.js @@ -48,3 +48,19 @@ export function setApiKey(connector,apikey) { }); } +export function fetchAutoTranslation(content) { + const data = `message=${ encodeURIComponent(content) }&locale=${ eXo.env.portal.language}`; + return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/automatic-translation/translate`, { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + method: 'POST', + body: data + }).then(resp => { + if (resp?.ok) { + return resp.json(); + } else { + throw new Error('Unable to get automatic translation result'); + } + }); +}