mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
all notifications are translated now closes #1388
This commit is contained in:
@@ -9,5 +9,13 @@
|
|||||||
"continue_to": "Continue to",
|
"continue_to": "Continue to",
|
||||||
"return_to": "Return to ",
|
"return_to": "Return to ",
|
||||||
"new_notification": "New Notification",
|
"new_notification": "New Notification",
|
||||||
"you_have_unread_notifications": "You have unread notifications."
|
"you_have_unread_notifications": "You have unread notifications.",
|
||||||
|
|
||||||
|
"user_made_post": "<strong>%1</strong> made a new post",
|
||||||
|
"new_message_from": "New message from <strong>%1</strong>",
|
||||||
|
"upvoted_your_post": "<strong>%1</strong> has upvoted your post.",
|
||||||
|
"favourited_your_post": "<strong>%1</strong> has favourited your post.",
|
||||||
|
"user_flagged_post": "<strong>%1</strong> flagged a post.",
|
||||||
|
"user_posted_to" : "<strong>%1</strong> has posted a reply to: <strong>%2</strong>"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* globals define, socket, translator, utils, config, app, ajaxify, Tinycon*/
|
||||||
|
|
||||||
|
|
||||||
define(['sounds'], function(sound) {
|
define(['sounds'], function(sound) {
|
||||||
var Notifications = {};
|
var Notifications = {};
|
||||||
|
|
||||||
@@ -13,50 +18,44 @@ define(['sounds'], function(sound) {
|
|||||||
|
|
||||||
socket.emit('notifications.get', null, function(err, data) {
|
socket.emit('notifications.get', null, function(err, data) {
|
||||||
|
|
||||||
var numRead = data.read.length,
|
function createNotification(notification, callback) {
|
||||||
numUnread = data.unread.length,
|
if (notification.image) {
|
||||||
x;
|
image = '<img class="image" src="' + notification.image + '" />';
|
||||||
|
} else {
|
||||||
|
image = '';
|
||||||
|
}
|
||||||
|
|
||||||
var html = '';
|
return '<li class="' + (notification.readClass || '') + '"><a href="' + notification.path + '">' + image + '<span class="pull-right relTime">' + utils.relativeTime(notification.datetime, true) + '</span><span class="text">' + notification.text + '</span></a></li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
var x, html = '';
|
||||||
|
|
||||||
if (!err && (data.read.length + data.unread.length) > 0) {
|
if (!err && (data.read.length + data.unread.length) > 0) {
|
||||||
var image = '';
|
var image = '';
|
||||||
for (x = 0; x < numUnread; x++) {
|
for (x = 0; x < data.unread.length; x++) {
|
||||||
if (data.unread[x].image) {
|
html += createNotification(data.unread[x]);
|
||||||
image = '<img class="image" src="' + data.unread[x].image + '" />';
|
|
||||||
} else {
|
|
||||||
image = '';
|
|
||||||
}
|
|
||||||
html += '<li class="' + (data.unread[x].readClass || '') + '"><a href="' + data.unread[x].path + '">' + image + '<span class="pull-right relTime">' + utils.relativeTime(data.unread[x].datetime, true) + '</span><span class="text">' + data.unread[x].text + '</span></a></li>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0; x < numRead; x++) {
|
for (x = 0; x < data.read.length; x++) {
|
||||||
if (data.read[x].image) {
|
html += createNotification(data.read[x]);
|
||||||
image = '<img src="' + data.read[x].image + '" />';
|
|
||||||
} else {
|
|
||||||
image = '';
|
|
||||||
}
|
}
|
||||||
html += '<li class="' + data.read[x].readClass + '"><a href="' + data.read[x].path + '">' + image + '<span class="pull-right relTime">' + utils.relativeTime(data.read[x].datetime, true) + '</span><span class="text">' + data.read[x].text + '</span></a></li>';
|
|
||||||
}
|
addSeeAllLink();
|
||||||
addSeeAllLink(replaceHtml);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
translator.translate('<li class="no-notifs"><a>[[notifications:no_notifs]]</a></li>', function(translated) {
|
html += '<li class="no-notifs"><a>[[notifications:no_notifs]]</a></li>';
|
||||||
html += translated;
|
addSeeAllLink();
|
||||||
addSeeAllLink(replaceHtml);
|
}
|
||||||
|
|
||||||
|
function addSeeAllLink() {
|
||||||
|
html += '<li class="pagelink"><a href="' + config.relative_path + '/notifications">[[notifications:see_all]]</a></li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
translator.translate(html, function(translated) {
|
||||||
|
notifList.html(translated);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function addSeeAllLink(callback) {
|
|
||||||
translator.translate('<li class="pagelink"><a href="' + RELATIVE_PATH + '/notifications">[[notifications:see_all]]</a></li>', function(translated) {
|
|
||||||
html += translated;
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceHtml() {
|
|
||||||
notifList.html(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateNotifCount(data.unread.length);
|
updateNotifCount(data.unread.length);
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ SocketModules.chats.send = function(socket, data, callback) {
|
|||||||
|
|
||||||
function sendChatNotification(fromuid, touid, username) {
|
function sendChatNotification(fromuid, touid, username) {
|
||||||
if (!module.parent.exports.isUserOnline(touid)) {
|
if (!module.parent.exports.isUserOnline(touid)) {
|
||||||
var notifText = 'New message from <strong>' + username + '</strong>';
|
var notifText = '[[notifications:new_message_from,' + username + ']]';
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: notifText,
|
text: notifText,
|
||||||
path: 'javascript:app.openChat('' + username + '', ' + fromuid + ');',
|
path: 'javascript:app.openChat('' + username + '', ' + fromuid + ');',
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ SocketPosts.reply = function(socket, data, callback) {
|
|||||||
|
|
||||||
SocketPosts.upvote = function(socket, data, callback) {
|
SocketPosts.upvote = function(socket, data, callback) {
|
||||||
favouriteCommand('upvote', 'voted', socket, data, callback);
|
favouriteCommand('upvote', 'voted', socket, data, callback);
|
||||||
sendNotificationToPostOwner(data, socket.uid, 'has upvoted your post');
|
sendNotificationToPostOwner(data, socket.uid, 'notifications:upvoted_your_post');
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.downvote = function(socket, data, callback) {
|
SocketPosts.downvote = function(socket, data, callback) {
|
||||||
@@ -62,7 +62,7 @@ SocketPosts.unvote = function(socket, data, callback) {
|
|||||||
|
|
||||||
SocketPosts.favourite = function(socket, data, callback) {
|
SocketPosts.favourite = function(socket, data, callback) {
|
||||||
favouriteCommand('favourite', 'favourited', socket, data, callback);
|
favouriteCommand('favourite', 'favourited', socket, data, callback);
|
||||||
sendNotificationToPostOwner(data, socket.uid, 'has favourited your post');
|
sendNotificationToPostOwner(data, socket.uid, 'notifications:favourited_your_post');
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.unfavourite = function(socket, data, callback) {
|
SocketPosts.unfavourite = function(socket, data, callback) {
|
||||||
@@ -87,7 +87,7 @@ function favouriteCommand(command, eventName, socket, data, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendNotificationToPostOwner(data, uid, message) {
|
function sendNotificationToPostOwner(data, uid, notification) {
|
||||||
if(data && data.pid && uid) {
|
if(data && data.pid && uid) {
|
||||||
posts.getPostFields(data.pid, ['tid', 'uid'], function(err, postData) {
|
posts.getPostFields(data.pid, ['tid', 'uid'], function(err, postData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -109,8 +109,9 @@ function sendNotificationToPostOwner(data, uid, message) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: '<strong>' + results.username + '</strong> ' + message,
|
text: '[[' + notification + ', ' + results.username + ']]',
|
||||||
path: nconf.get('relative_path') + '/topic/' + results.slug + '#' + data.pid,
|
path: nconf.get('relative_path') + '/topic/' + results.slug + '#' + data.pid,
|
||||||
uniqueId: 'post:' + data.pid,
|
uniqueId: 'post:' + data.pid,
|
||||||
from: uid
|
from: uid
|
||||||
@@ -258,7 +259,7 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
user.getUserField(socket.uid, 'username', next);
|
user.getUserField(socket.uid, 'username', next);
|
||||||
},
|
},
|
||||||
function(username, next) {
|
function(username, next) {
|
||||||
message = '<strong>' + username + '</strong> flagged a post.';
|
message = '[[notifications:user_flagged_post, ' + username + ']]';
|
||||||
posts.getPostField(pid, 'tid', next);
|
posts.getPostField(pid, 'tid', next);
|
||||||
},
|
},
|
||||||
function(tid, next) {
|
function(tid, next) {
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ var winston = require('winston'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: '<strong>' + username + '</strong> has posted a reply to: "<strong>' + topicData.title + '</strong>"',
|
text: '[[notifications:user_posted_to, ' + username + ', ' + topicData.title + ']]',
|
||||||
path: nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid,
|
path: nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid,
|
||||||
uniqueId: 'topic:' + tid,
|
uniqueId: 'topic:' + tid,
|
||||||
from: exceptUid
|
from: exceptUid
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ module.exports = function(User) {
|
|||||||
}
|
}
|
||||||
if (exists) {
|
if (exists) {
|
||||||
async.forever(function(next) {
|
async.forever(function(next) {
|
||||||
// Append a random number to the username
|
|
||||||
var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);
|
var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);
|
||||||
User.exists(newUsername, function(err, exists) {
|
User.exists(newUsername, function(err, exists) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
@@ -87,10 +86,11 @@ module.exports = function(User) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
userData = results[results.length - 1];
|
|
||||||
|
|
||||||
|
userData = results[results.length - 1];
|
||||||
|
var userNameChanged = !!results[3];
|
||||||
// If a new username was picked...
|
// If a new username was picked...
|
||||||
if (results[3]) {
|
if (userNameChanged) {
|
||||||
userData.username = results[3];
|
userData.username = results[3];
|
||||||
userData.userslug = utils.slugify(results[3]);
|
userData.userslug = utils.slugify(results[3]);
|
||||||
}
|
}
|
||||||
@@ -149,17 +149,14 @@ module.exports = function(User) {
|
|||||||
|
|
||||||
groups.join('registered-users', uid);
|
groups.join('registered-users', uid);
|
||||||
|
|
||||||
// If their username was automatically changed...
|
if (userNameChanged) {
|
||||||
if (results[3]) {
|
|
||||||
translator.translate('[[user:username_taken_workaround, ' + userData.username + ']]', function(notifText) {
|
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: notifText,
|
text: '[[user:username_taken_workaround, ' + userData.username + ']]',
|
||||||
picture: 'brand:logo',
|
picture: 'brand:logo',
|
||||||
datetime: Date.now()
|
datetime: Date.now()
|
||||||
}, function(nid) {
|
}, function(nid) {
|
||||||
notifications.push(nid, uid);
|
notifications.push(nid, uid);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password) {
|
if (password) {
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ var async = require('async'),
|
|||||||
db.getSetMembers('followers:' + uid, function(err, followers) {
|
db.getSetMembers('followers:' + uid, function(err, followers) {
|
||||||
if (followers && followers.length) {
|
if (followers && followers.length) {
|
||||||
topics.getTopicField(tid, 'slug', function(err, slug) {
|
topics.getTopicField(tid, 'slug', function(err, slug) {
|
||||||
var message = '<strong>' + username + '</strong> made a new post';
|
var message = '[[notifications:user_made_post, ' + username + ']]';
|
||||||
|
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: message,
|
text: message,
|
||||||
|
|||||||
Reference in New Issue
Block a user