From 4d4f0e34e66aac3d86b7978ed1eb58b11fcf8c74 Mon Sep 17 00:00:00 2001 From: Tasnim1147 <87118828+Tasnim1147@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:45:24 +0000 Subject: [PATCH 1/6] Change workflow --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 82397772c4..da6bbaeade 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,6 +7,7 @@ on: pull_request: branches: - f24 + # - f24-p4 workflow_call: # Usually called from deploy defaults: From 17a6eed98aba66a575af75d4e9e13ab5d1629c5f Mon Sep 17 00:00:00 2001 From: Tasnim1147 <87118828+Tasnim1147@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:48:59 +0000 Subject: [PATCH 2/6] Integrating translator service --- public/src/client/topic.js | 15 +++++++++++++++ src/posts/create.js | 4 ++++ src/posts/data.js | 2 ++ src/translate/index.js | 11 +++++++++++ 4 files changed, 32 insertions(+) create mode 100644 src/translate/index.js diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 7e65cbeb4f..b1193bba03 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -71,12 +71,27 @@ define('forum/topic', [ handleThumbs(); $(window).on('scroll', utils.debounce(updateTopicTitle, 250)); + configurePostToggle(); handleTopicSearch(); hooks.fire('action:topic.loaded', ajaxify.data); }; + function configurePostToggle() { + $(".topic").on("click", ".view-translated-btn", function () { + // Toggle the visibility of the next .translated-content div + $(this).closest('.sensitive-content-message').next('.translated-content').toggle(); + // Optionally, change the button text based on visibility + var isVisible = $(this).closest('.sensitive-content-message').next('.translated-content').is(':visible'); + if (isVisible) { + $(this).text('Hide the translated message.'); + } else { + $(this).text('Click here to view the translated message.'); + } + }); + } + function handleTopicSearch() { require(['mousetrap'], (mousetrap) => { if (config.topicSearchEnabled) { diff --git a/src/posts/create.js b/src/posts/create.js index a9ff9de98a..9a07811e45 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -10,6 +10,7 @@ const topics = require('../topics'); const categories = require('../categories'); const groups = require('../groups'); const privileges = require('../privileges'); +const translate = require('../translate'); module.exports = function (Posts) { Posts.create = async function (data) { @@ -19,6 +20,7 @@ module.exports = function (Posts) { const content = data.content.toString(); const timestamp = data.timestamp || Date.now(); const isMain = data.isMain || false; + const [isEnglish, translatedContent] = await translate.translate(data) const { isApproved } = data; const { annonymousType } = data; @@ -37,6 +39,8 @@ module.exports = function (Posts) { tid: tid, content: content, timestamp: timestamp, + translatedContent: translatedContent, + isEnglish: isEnglish, isApproved: isApproved, annonymousType: annonymousType, }; diff --git a/src/posts/data.js b/src/posts/data.js index 3a4d303ff5..5f92b3c1f7 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -67,5 +67,7 @@ function modifyPost(post, fields) { if (post.hasOwnProperty('edited')) { post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; } + // Mark post as "English" if decided by translator service or if it has no info + post.isEnglish = post.isEnglish == "true" || post.isEnglish === undefined; } } diff --git a/src/translate/index.js b/src/translate/index.js new file mode 100644 index 0000000000..b32dcf4343 --- /dev/null +++ b/src/translate/index.js @@ -0,0 +1,11 @@ +var request = require('request'); + +const translatorApi = module.exports; + +translatorApi.translate = async function (postData) { + // Edit the translator URL below + const TRANSLATOR_API = "https://nodebb-f24-translator.azurewebsites.net/" + const response = await fetch(TRANSLATOR_API+'/?content='+postData.content); + const data = await response.json(); + return [data["is_english"], data["translated_content"]] +} \ No newline at end of file From 75d03f37d186f1c10d0ec269fef5af5fa8423544 Mon Sep 17 00:00:00 2001 From: Tasnim1147 <87118828+Tasnim1147@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:54:46 +0000 Subject: [PATCH 3/6] Complete the UI --- src/meta/src/post.tpl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/meta/src/post.tpl b/src/meta/src/post.tpl index 6356cf7e7b..501e2e51db 100644 --- a/src/meta/src/post.tpl +++ b/src/meta/src/post.tpl @@ -79,6 +79,14 @@
{posts.content} + {{{if !posts.isEnglish }}} +
+ Click here to view the translated message. +
+ + {{{end}}}
From 16b7c821359eef1d51a617547410b5388ab27442 Mon Sep 17 00:00:00 2001 From: Tasnim1147 <87118828+Tasnim1147@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:57:23 +0000 Subject: [PATCH 4/6] Add translator service repo --- translator-service | 1 + 1 file changed, 1 insertion(+) create mode 160000 translator-service diff --git a/translator-service b/translator-service new file mode 160000 index 0000000000..4cc71d3173 --- /dev/null +++ b/translator-service @@ -0,0 +1 @@ +Subproject commit 4cc71d3173556c6571b410d12687672fc25c1924 From 1a939d851816070cf23c96e87720fee80574948c Mon Sep 17 00:00:00 2001 From: Tasnim1147 <87118828+Tasnim1147@users.noreply.github.com> Date: Thu, 14 Nov 2024 04:51:52 +0000 Subject: [PATCH 5/6] Fix bug in topic.js --- public/src/client/topic.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index b1193bba03..905f44d221 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -66,12 +66,14 @@ define('forum/topic', [ addParentHandler(); addRepliesHandler(); addPostsPreviewHandler(); + configurePostToggle(); setupQuickReply(); handleBookmark(tid); handleThumbs(); $(window).on('scroll', utils.debounce(updateTopicTitle, 250)); - configurePostToggle(); + + handleTopicSearch(); @@ -82,6 +84,7 @@ define('forum/topic', [ $(".topic").on("click", ".view-translated-btn", function () { // Toggle the visibility of the next .translated-content div $(this).closest('.sensitive-content-message').next('.translated-content').toggle(); + console.log("Toggle btn clicked"); // Optionally, change the button text based on visibility var isVisible = $(this).closest('.sensitive-content-message').next('.translated-content').is(':visible'); if (isVisible) { From 260aca7dd341334ed069f731cd4db0332000b693 Mon Sep 17 00:00:00 2001 From: Tasnim1147 <87118828+Tasnim1147@users.noreply.github.com> Date: Thu, 14 Nov 2024 05:05:57 +0000 Subject: [PATCH 6/6] Remove translator service --- translator-service | 1 - 1 file changed, 1 deletion(-) delete mode 160000 translator-service diff --git a/translator-service b/translator-service deleted file mode 160000 index 4cc71d3173..0000000000 --- a/translator-service +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4cc71d3173556c6571b410d12687672fc25c1924