From 351c44a988be936d05db60076ff7426fe40774d9 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 12 Feb 2019 14:12:08 -0200 Subject: [PATCH 1/2] Fix misspelled language setting name --- .../server/functions/saveRoomType.js | 4 ++-- .../rocketchat-lib/server/functions/notifications/email.js | 2 +- .../rocketchat-lib/server/functions/notifications/index.js | 4 ++-- packages/rocketchat-livechat/lib/messageTypes.js | 2 +- packages/rocketchat-livechat/server/api/v1/room.js | 2 +- packages/rocketchat-livechat/server/lib/Livechat.js | 2 +- packages/rocketchat-livechat/server/methods/closeByVisitor.js | 2 +- packages/rocketchat-livechat/server/startup.js | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/rocketchat-channel-settings/server/functions/saveRoomType.js b/packages/rocketchat-channel-settings/server/functions/saveRoomType.js index a495c2b270b8..a89df13c0551 100644 --- a/packages/rocketchat-channel-settings/server/functions/saveRoomType.js +++ b/packages/rocketchat-channel-settings/server/functions/saveRoomType.js @@ -32,11 +32,11 @@ RocketChat.saveRoomType = function(rid, roomType, user, sendMessage = true) { let message; if (roomType === 'c') { message = TAPi18n.__('Channel', { - lng: (user && user.language) || RocketChat.settings.get('language') || 'en', + lng: (user && user.language) || RocketChat.settings.get('Language') || 'en', }); } else { message = TAPi18n.__('Private_Group', { - lng: (user && user.language) || RocketChat.settings.get('language') || 'en', + lng: (user && user.language) || RocketChat.settings.get('Language') || 'en', }); } RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser('room_changed_privacy', rid, message, user); diff --git a/packages/rocketchat-lib/server/functions/notifications/email.js b/packages/rocketchat-lib/server/functions/notifications/email.js index 98abcff2b18a..e96e56a135a4 100644 --- a/packages/rocketchat-lib/server/functions/notifications/email.js +++ b/packages/rocketchat-lib/server/functions/notifications/email.js @@ -15,7 +15,7 @@ Meteor.startup(() => { }); function getEmailContent({ message, user, room }) { - const lng = (user && user.language) || RocketChat.settings.get('language') || 'en'; + const lng = (user && user.language) || RocketChat.settings.get('Language') || 'en'; const roomName = s.escapeHTML(`#${ RocketChat.roomTypes.getRoomName(room.t, room) }`); const userName = s.escapeHTML(RocketChat.settings.get('UI_Use_Real_Name') ? message.u.name || message.u.username : message.u.username); diff --git a/packages/rocketchat-lib/server/functions/notifications/index.js b/packages/rocketchat-lib/server/functions/notifications/index.js index e2316590a351..125875d64f13 100644 --- a/packages/rocketchat-lib/server/functions/notifications/index.js +++ b/packages/rocketchat-lib/server/functions/notifications/index.js @@ -9,13 +9,13 @@ import s from 'underscore.string'; */ export function parseMessageTextPerUser(messageText, message, receiver) { if (!message.msg && message.attachments && message.attachments[0]) { - const lng = receiver.language || RocketChat.settings.get('language') || 'en'; + const lng = receiver.language || RocketChat.settings.get('Language') || 'en'; return message.attachments[0].image_type ? TAPi18n.__('User_uploaded_image', { lng }) : TAPi18n.__('User_uploaded_file', { lng }); } if (message.msg && message.t === 'e2e') { - const lng = receiver.language || RocketChat.settings.get('language') || 'en'; + const lng = receiver.language || RocketChat.settings.get('Language') || 'en'; return TAPi18n.__('Encrypted_message', { lng }); } diff --git a/packages/rocketchat-livechat/lib/messageTypes.js b/packages/rocketchat-livechat/lib/messageTypes.js index f57bbf721c4c..b76b7508fe09 100644 --- a/packages/rocketchat-livechat/lib/messageTypes.js +++ b/packages/rocketchat-livechat/lib/messageTypes.js @@ -35,7 +35,7 @@ RocketChat.actionLinks.register('denyLivechatCall', function(message/* , params* RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('command', message.rid, 'endCall', user); RocketChat.Notifications.notifyRoom(message.rid, 'deleteMessage', { _id: message._id }); - const language = user.language || RocketChat.settings.get('language') || 'en'; + const language = user.language || RocketChat.settings.get('Language') || 'en'; RocketChat.Livechat.closeRoom({ user, diff --git a/packages/rocketchat-livechat/server/api/v1/room.js b/packages/rocketchat-livechat/server/api/v1/room.js index 246f9451af11..36f395849583 100644 --- a/packages/rocketchat-livechat/server/api/v1/room.js +++ b/packages/rocketchat-livechat/server/api/v1/room.js @@ -53,7 +53,7 @@ RocketChat.API.v1.addRoute('livechat/room.close', { throw new Meteor.Error('room-closed'); } - const language = RocketChat.settings.get('language') || 'en'; + const language = RocketChat.settings.get('Language') || 'en'; const comment = TAPi18n.__('Closed_by_visitor', { lng: language }); if (!RocketChat.Livechat.closeRoom({ visitor, room, comment })) { diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index d689dce6d5db..8eb195f915c3 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -814,7 +814,7 @@ RocketChat.Livechat = { const room = RocketChat.models.Rooms.findOneById(rid); const visitor = LivechatVisitors.getVisitorByToken(token); - const userLanguage = (visitor && visitor.language) || RocketChat.settings.get('language') || 'en'; + const userLanguage = (visitor && visitor.language) || RocketChat.settings.get('Language') || 'en'; // allow to only user to send transcripts from their own chats if (!room || room.t !== 'l' || !room.v || room.v.token !== token) { diff --git a/packages/rocketchat-livechat/server/methods/closeByVisitor.js b/packages/rocketchat-livechat/server/methods/closeByVisitor.js index b29ddec75b58..3d2541e43f92 100644 --- a/packages/rocketchat-livechat/server/methods/closeByVisitor.js +++ b/packages/rocketchat-livechat/server/methods/closeByVisitor.js @@ -7,7 +7,7 @@ Meteor.methods({ 'livechat:closeByVisitor'({ roomId, token }) { const visitor = LivechatVisitors.getVisitorByToken(token); - const language = (visitor && visitor.language) || RocketChat.settings.get('language') || 'en'; + const language = (visitor && visitor.language) || RocketChat.settings.get('Language') || 'en'; return RocketChat.Livechat.closeRoom({ visitor, diff --git a/packages/rocketchat-livechat/server/startup.js b/packages/rocketchat-livechat/server/startup.js index bf196a7fe158..ea7b0f02239b 100644 --- a/packages/rocketchat-livechat/server/startup.js +++ b/packages/rocketchat-livechat/server/startup.js @@ -21,7 +21,7 @@ Meteor.startup(() => { return user; } throw new Meteor.Error(TAPi18n.__('You_cant_leave_a_livechat_room_Please_use_the_close_button', { - lng: user.language || RocketChat.settings.get('language') || 'en', + lng: user.language || RocketChat.settings.get('Language') || 'en', })); }, RocketChat.callbacks.priority.LOW, 'cant-leave-room'); }); From 3d15fb210b5779d838f0b2139ad763a18c8816d9 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 12 Feb 2019 14:14:05 -0200 Subject: [PATCH 2/2] Fix emails translations not using server's language --- packages/rocketchat-mailer/server/api.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-mailer/server/api.js b/packages/rocketchat-mailer/server/api.js index c43830c276ea..55d35af21caf 100644 --- a/packages/rocketchat-mailer/server/api.js +++ b/packages/rocketchat-mailer/server/api.js @@ -13,9 +13,15 @@ let Settings = { get: () => {}, }; -export const replacekey = (str, key, value = '') => str.replace(new RegExp(`(\\[${ key }\\]|__${ key }__)`, 'igm'), value); +// define server language for email translations +// @TODO: change TAPi18n.__ function to use the server language by default +let lng = 'en'; +settings.get('Language', (key, value) => { + lng = value || 'en'; +}); -export const translate = (str) => str.replace(/\{ ?([^\} ]+)(( ([^\}]+))+)? ?\}/gmi, (match, key) => TAPi18n.__(key)); +export const replacekey = (str, key, value = '') => str.replace(new RegExp(`(\\[${ key }\\]|__${ key }__)`, 'igm'), value); +export const translate = (str) => { console.log({ lng, str }); return str.replace(/\{ ?([^\} ]+)(( ([^\}]+))+)? ?\}/gmi, (match, key) => TAPi18n.__(key, { lng })); }; export const replace = function replace(str, data = {}) { if (!str) { return '';