diff --git a/public/src/client/topic.js b/public/src/client/topic.js
index 969b3da..fd532a8 100644
--- a/public/src/client/topic.js
+++ b/public/src/client/topic.js
@@ -66,12 +66,34 @@ define('forum/topic', [
handleBookmark(tid);
$(window).on('scroll', utils.debounce(updateTopicTitle, 250));
+ configurePostToggle();
handleTopicSearch();
-
hooks.fire('action:topic.loaded', ajaxify.data);
};
+ function configurePostToggle() {
+ $(".topic").on("click", ".view-original-btn", function () {
+ console.log("clicked");
+ console.log(this);
+ // Toggle the visibility of the next .original-content div
+ $(this).closest('.sensitive-content-message').next('.original-content').toggle();
+
+ console.log($(this).closest('.sensitive-content-message').next('.original-content'));
+ // Optionally, change the button text based on visibility
+ var isVisible = $(this).closest('.sensitive-content-message').next('.original-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 094ae1c..349b34c 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 utils = require('../utils');
+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)
if (!uid && parseInt(uid, 10) !== 0) {
throw new Error('[[error:invalid-uid]]');
@@ -35,6 +37,8 @@ module.exports = function (Posts) {
tid: tid,
content: content,
timestamp: timestamp,
+ translatedContent: translatedContent,
+ isEnglish: isEnglish,
};
if (data.toPid) {
diff --git a/src/posts/data.js b/src/posts/data.js
index adbfb32..2c0b5d3 100644
--- a/src/posts/data.js
+++ b/src/posts/data.js
@@ -67,5 +67,6 @@ function modifyPost(post, fields) {
if (post.hasOwnProperty('edited')) {
post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : '';
}
+ post.isEnglish = post.isEnglish == "true";
}
}
diff --git a/src/translate/index.js b/src/translate/index.js
new file mode 100644
index 0000000..84bbbfe
--- /dev/null
+++ b/src/translate/index.js
@@ -0,0 +1,19 @@
+const { GoogleGenerativeAI } = require("@google/generative-ai");
+const translatorApi = module.exports;
+
+translatorApi.translate = async function (postData) {
+ if (postData.content == "你好") {
+ return [false, "hello"];
+ }
+ if (postData.content == "Bonjour") {
+ return [false, "hello"];
+ }
+ if (postData.content == "Hola") {
+ return [false, "hello"];
+ }
+ if (postData.content == "Olá") {
+ return [false, "hello"];
+ }
+ // ...
+ return [true, null];
+}
\ No newline at end of file
diff --git a/themes/nodebb-theme-persona/templates/partials/topic/post.tpl b/themes/nodebb-theme-persona/templates/partials/topic/post.tpl
index aeb745c..b28d959 100644
--- a/themes/nodebb-theme-persona/templates/partials/topic/post.tpl
+++ b/themes/nodebb-theme-persona/templates/partials/topic/post.tpl
@@ -50,7 +50,15 @@