mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
Translate messages only after serialization
This commit is contained in:
@@ -777,8 +777,9 @@ describe('Group Model', () => {
|
||||
quest: 'basilist',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate boss_damage', () => {
|
||||
@@ -792,8 +793,9 @@ describe('Group Model', () => {
|
||||
bossDamage: 3.7,
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate boss_dont_attack', () => {
|
||||
@@ -806,8 +808,9 @@ describe('Group Model', () => {
|
||||
userDamage: 15.3,
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate boss_rage', () => {
|
||||
@@ -818,8 +821,9 @@ describe('Group Model', () => {
|
||||
quest: 'lostMasterclasser3',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate boss_defeated', () => {
|
||||
@@ -830,8 +834,9 @@ describe('Group Model', () => {
|
||||
quest: 'lostMasterclasser3',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate user_found_items', () => {
|
||||
@@ -848,8 +853,9 @@ describe('Group Model', () => {
|
||||
},
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate all_items_found', () => {
|
||||
@@ -859,8 +865,9 @@ describe('Group Model', () => {
|
||||
type: 'all_items_found',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate spell_cast_party', () => {
|
||||
@@ -873,8 +880,9 @@ describe('Group Model', () => {
|
||||
spell: 'earth',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate spell_cast_user', () => {
|
||||
@@ -888,8 +896,9 @@ describe('Group Model', () => {
|
||||
target: participatingMember.profile.name,
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate quest_cancel', () => {
|
||||
@@ -901,8 +910,9 @@ describe('Group Model', () => {
|
||||
quest: 'basilist',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate quest_abort', () => {
|
||||
@@ -914,8 +924,9 @@ describe('Group Model', () => {
|
||||
quest: 'basilist',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate tavern_quest_completed', () => {
|
||||
@@ -926,8 +937,9 @@ describe('Group Model', () => {
|
||||
quest: 'stressbeast',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate tavern_boss_rage_tired', () => {
|
||||
@@ -938,8 +950,9 @@ describe('Group Model', () => {
|
||||
quest: 'stressbeast',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate tavern_boss_rage', () => {
|
||||
@@ -951,8 +964,9 @@ describe('Group Model', () => {
|
||||
scene: 'market',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate tavern_boss_desperation', () => {
|
||||
@@ -963,8 +977,9 @@ describe('Group Model', () => {
|
||||
quest: 'stressbeast',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
|
||||
it('translate claim_task', () => {
|
||||
@@ -976,8 +991,9 @@ describe('Group Model', () => {
|
||||
task: 'Feed the pet',
|
||||
},
|
||||
}];
|
||||
party.translateSystemMessages(questLeader);
|
||||
translationCheck(party.chat[0].text);
|
||||
let toJSON = party.toJSON();
|
||||
Group.translateSystemMessages(toJSON, questLeader);
|
||||
translationCheck(toJSON.chat[0].text);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -333,6 +333,19 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
||||
return groupsArray;
|
||||
};
|
||||
|
||||
function _translateSystemMessages (toJSON, user) {
|
||||
let lang = user.preferences ? user.preferences.language : 'en';
|
||||
|
||||
toJSON.chat.map(chat => {
|
||||
if (!_.isEmpty(chat.info)) {
|
||||
chat.text = translateMessage(lang, chat.info);
|
||||
}
|
||||
return chat;
|
||||
});
|
||||
}
|
||||
|
||||
schema.statics.translateSystemMessages = _translateSystemMessages;
|
||||
|
||||
// When converting to json remove chat messages with more than 1 flag and remove all flags info
|
||||
// unless the user is an admin or said chat is posted by that user
|
||||
// Not putting into toJSON because there we can't access user
|
||||
@@ -344,9 +357,8 @@ schema.statics.toJSONCleanChat = async function groupToJSONCleanChat (group, use
|
||||
await getGroupChat(group);
|
||||
}
|
||||
|
||||
group.translateSystemMessages(user);
|
||||
|
||||
let toJSON = group.toJSON();
|
||||
_translateSystemMessages(toJSON, user);
|
||||
|
||||
if (!user.contributor.admin) {
|
||||
_.remove(toJSON.chat, chatMsg => {
|
||||
@@ -452,16 +464,6 @@ schema.statics.validateInvitations = async function getInvitationError (invites,
|
||||
}
|
||||
};
|
||||
|
||||
schema.methods.translateSystemMessages = function translateSystemMessages (user) {
|
||||
let lang = user.preferences ? user.preferences.language : 'en';
|
||||
|
||||
this.chat.forEach((chat, i, chatArray) => {
|
||||
if (!_.isEmpty(chat.info)) {
|
||||
chatArray[i].text = translateMessage(lang, chat.info);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
schema.methods.getParticipatingQuestMembers = function getParticipatingQuestMembers () {
|
||||
return Object.keys(this.quest.members).filter(member => this.quest.members[member]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user