Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Not translated emails #13452

Merged
merged 2 commits into from
Feb 12, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/lib/messageTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/server/api/v1/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
10 changes: 8 additions & 2 deletions packages/rocketchat-mailer/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down