diff --git a/dump.rdb b/dump.rdb index c71ec0a686..0f729e07c8 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/node_modules/nodebb-theme-harmony/templates/partials/topic/post.tpl b/node_modules/nodebb-theme-harmony/templates/partials/topic/post.tpl index e2e92ad701..bc6dafd88e 100644 --- a/node_modules/nodebb-theme-harmony/templates/partials/topic/post.tpl +++ b/node_modules/nodebb-theme-harmony/templates/partials/topic/post.tpl @@ -61,6 +61,15 @@
{posts.content} + + {{{if !posts.isEnglish }}} +
+ Click here to view the translated message. +
+ + {{{end}}}
diff --git a/node_modules_real/topics_list.tpl b/node_modules_real/topics_list.tpl index 368a9e2ad9..d7c9dc03d1 100644 --- a/node_modules_real/topics_list.tpl +++ b/node_modules_real/topics_list.tpl @@ -1,292 +1,292 @@ - - - - - - - - + + + + + + + + diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 7e65cbeb4f..5b43817218 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 d541564c2e..a1838288d1 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,7 +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 +36,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 3a4d303ff5..1c7911feb0 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..547441f531 --- /dev/null +++ b/src/translate/index.js @@ -0,0 +1,11 @@ +'use strict'; + +const translatorApi = module.exports; + +translatorApi.translate = async function (postData) { + // Edit the translator URL below + const TRANSLATOR_API = 'https://translator-swifites.azurewebsites.net/'; + const response = await fetch(`${TRANSLATOR_API}/?content=${postData.content}`); + const data = await response.json(); + return [data.is_english, data.translated_content]; +}; diff --git a/test/api.js b/test/api.js index 0ea9918953..0e7c635582 100644 --- a/test/api.js +++ b/test/api.js @@ -662,10 +662,7 @@ describe('API', async () => { // Compare the response to the schema Object.keys(response).forEach((prop) => { if (additionalProperties) { // All bets are off - return; } - - assert(schema[prop], `"${prop}" was found in response, but is not defined in schema (path: ${method} ${path}, context: ${context})`); }); } });