Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions public/openapi/components/schemas/PostObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ PostObject:
For posts received via ActivityPub, it is the url of the original piece of content.
content:
type: string
isEnglish:
type: boolean
translatedContent:
type: string
sourceContent:
type: string
nullable: true
Expand Down Expand Up @@ -170,6 +174,10 @@ PostDataObject:
description: A topic identifier
content:
type: string
isEnglish:
type: boolean
translatedContent:
type: string
timestamp:
type: number
votes:
Expand Down
8 changes: 8 additions & 0 deletions public/openapi/read/categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ get:
type: number
content:
type: string
isEnglish:
type: boolean
translatedContent:
type: string
timestampISO:
type: string
description: An ISO 8601 formatted date string (complementing `timestamp`)
Expand Down Expand Up @@ -142,6 +146,10 @@ get:
type: number
content:
type: string
isEnglish:
type: boolean
translatedContent:
type: string
sourceContent:
type: string
nullable: true
Expand Down
8 changes: 8 additions & 0 deletions public/openapi/read/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ get:
type: number
content:
type: string
isEnglish:
type: boolean
translatedContent:
type: string
timestampISO:
type: string
description: An ISO 8601 formatted date string (complementing `timestamp`)
Expand Down Expand Up @@ -144,6 +148,10 @@ get:
type: number
content:
type: string
isEnglish:
type: boolean
translatedContent:
type: string
sourceContent:
type: string
nullable: true
Expand Down
4 changes: 4 additions & 0 deletions public/openapi/write/posts/pid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ get:
description: A topic identifier
content:
type: string
isEnglish:
type: boolean
translatedContent:
type: string
timestamp:
type: number
flagId:
Expand Down
16 changes: 16 additions & 0 deletions public/src/client/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,28 @@ 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) {
Expand Down
4 changes: 3 additions & 1 deletion src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const groups = require('../groups');
const privileges = require('../privileges');
const activitypub = require('../activitypub');
const utils = require('../utils');
const translate = require('../translate');

module.exports = function (Posts) {
Posts.create = async function (data) {
Expand All @@ -18,6 +19,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]]');
Expand All @@ -28,7 +30,7 @@ module.exports = function (Posts) {
}

const pid = data.pid || await db.incrObjectField('global', 'nextPid');
let postData = { pid, uid, tid, content, sourceContent, timestamp };
let postData = { pid, uid, tid, content, sourceContent, timestamp, isEnglish, translatedContent };

if (data.toPid) {
postData.toPid = data.toPid;
Expand Down
6 changes: 6 additions & 0 deletions src/posts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,11 @@ function modifyPost(post, fields) {
if (!fields.length || fields.includes('attachments')) {
post.attachments = (post.attachments || '').split(',').filter(Boolean);
}
// Mark post as "English" if decided by translator service or if it has no info
post.isEnglish = post.isEnglish == 'true' || post.isEnglish === undefined;
// If translatedContent is undefined, default to empty string (no translation needed for English posts)
if (post.translatedContent === undefined) {
post.translatedContent = '';
}
}
}
2 changes: 1 addition & 1 deletion src/posts/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (Posts) {
options.escape = options.hasOwnProperty('escape') ? options.escape : false;
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];

const fields = ['pid', 'tid', 'toPid', 'url', 'content', 'sourceContent', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
const fields = ['pid', 'tid', 'toPid', 'url', 'content', 'sourceContent', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle', 'isEnglish', 'translatedContent'].concat(options.extraFields);

let posts = await Posts.getPostsFields(pids, fields);
posts = posts.filter(Boolean);
Expand Down
17 changes: 17 additions & 0 deletions src/translate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

/* eslint-disable strict */
//var request = require('request');

const translatorApi = module.exports;

translatorApi.translate = function (postData) {
return ['is_english',postData];
};

// translatorApi.translate = async function (postData) {
// Edit the translator URL below
// const TRANSLATOR_API = "TODO"
// const response = await fetch(TRANSLATOR_API+'/?content='+postData.content);
// const data = await response.json();
// return ['is_english','translated_content'];
// };
4 changes: 1 addition & 3 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ describe('API', async () => {
required.forEach((prop) => {
if (schema.hasOwnProperty(prop)) {
assert(response.hasOwnProperty(prop), `"${prop}" is a required property (path: ${method} ${path}, context: ${context}), ${JSON.stringify(response)}`);

// Don't proceed with type-check if the value could possibly be unset (nullable: true, in spec)
if (response[prop] === null && schema[prop].nullable === true) {
return;
Expand Down Expand Up @@ -685,7 +684,6 @@ describe('API', async () => {
return;
}

assert(schema[prop], `"${prop}" was found in response, but is not defined in schema (path: ${method} ${path}, context: ${context}), SCHEMA ${JSON.stringify(response)}`);
});
assert(schema[prop], `"${prop}" was found in response, but is not defined in schema (path: ${method} ${path}, context: ${context}), SCHEMA ${JSON.stringify(schema)}`);});
}
});
1 change: 0 additions & 1 deletion vendor/nodebb-theme-harmony-2.1.23/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ async function buildSkins() {
const plugins = require.main.require('./src/plugins');
await plugins.prepareForBuild(['client side styles']);
for (const skin of meta.css.supportedSkins) {

await meta.css.buildBundle(`client-${skin}`, true);
}
require.main.require('./src/meta/minifier').killAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@
</div>

<div class="content text-break" component="post/content" itemprop="text">
{posts.content}
{posts.content}
{{{if !posts.isEnglish }}}
<div class="sensitive-content-message">
<a class="btn btn-sm btn-primary view-translated-btn">Click here to view the translated message.</a>
</div>
<div class="translated-content" style="display:none;">
{posts.translatedContent}
</div>
{{{end}}}
</div>

<div component="post/footer" class="post-footer border-bottom pb-2">
Expand Down