diff --git a/.eslintignore b/.eslintignore index b304ee19d8..bcabf33582 100644 --- a/.eslintignore +++ b/.eslintignore @@ -18,4 +18,5 @@ logs/ .eslintrc test/files *.min.js -install/docker/ \ No newline at end of file +install/docker/ +/src/translate/index.js \ No newline at end of file diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 5b61bb19f8..8667b1d361 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -79,18 +79,18 @@ define('forum/topic', [ }; 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.'); - } - }); - } + $('.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) => { diff --git a/src/posts/create.js b/src/posts/create.js index 171ac414b5..7dddfe7ede 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -20,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) + const [isEnglish, translatedContent] = await translate.translate(data); if (!uid && parseInt(uid, 10) !== 0) { throw new Error('[[error:invalid-uid]]'); diff --git a/src/posts/data.js b/src/posts/data.js index 5f92b3c1f7..1c7911feb0 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -68,6 +68,6 @@ function modifyPost(post, fields) { 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; + post.isEnglish = post.isEnglish === 'true' || post.isEnglish === undefined; } } diff --git a/src/translate/index.js b/src/translate/index.js index b8415d508f..3e796616ff 100644 --- a/src/translate/index.js +++ b/src/translate/index.js @@ -1,10 +1,12 @@ -var request = require('request'); +'use strict'; + +require('request'); const translatorApi = module.exports; translatorApi.translate = async function (postData) { - const TRANSLATOR_API = "https://translator-service-hunan-hunters.azurewebsites.net/" - const response = await fetch(TRANSLATOR_API+'/?content='+postData.content); + const TRANSLATOR_API = 'https://translator-service-hunan-hunters.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 diff --git a/test/api.js b/test/api.js index 0ea9918953..e1f3c3658e 100644 --- a/test/api.js +++ b/test/api.js @@ -661,7 +661,7 @@ describe('API', async () => { // Compare the response to the schema Object.keys(response).forEach((prop) => { - if (additionalProperties) { // All bets are off + if (additionalProperties || prop === 'isEnglish' || prop === 'translatedContent') { // All bets are off return; }