mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Translate messages only after serialization
This commit is contained in:
@@ -777,8 +777,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'basilist',
|
quest: 'basilist',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate boss_damage', () => {
|
it('translate boss_damage', () => {
|
||||||
@@ -792,8 +793,9 @@ describe('Group Model', () => {
|
|||||||
bossDamage: 3.7,
|
bossDamage: 3.7,
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate boss_dont_attack', () => {
|
it('translate boss_dont_attack', () => {
|
||||||
@@ -806,8 +808,9 @@ describe('Group Model', () => {
|
|||||||
userDamage: 15.3,
|
userDamage: 15.3,
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate boss_rage', () => {
|
it('translate boss_rage', () => {
|
||||||
@@ -818,8 +821,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'lostMasterclasser3',
|
quest: 'lostMasterclasser3',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate boss_defeated', () => {
|
it('translate boss_defeated', () => {
|
||||||
@@ -830,8 +834,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'lostMasterclasser3',
|
quest: 'lostMasterclasser3',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate user_found_items', () => {
|
it('translate user_found_items', () => {
|
||||||
@@ -848,8 +853,9 @@ describe('Group Model', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate all_items_found', () => {
|
it('translate all_items_found', () => {
|
||||||
@@ -859,8 +865,9 @@ describe('Group Model', () => {
|
|||||||
type: 'all_items_found',
|
type: 'all_items_found',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate spell_cast_party', () => {
|
it('translate spell_cast_party', () => {
|
||||||
@@ -873,8 +880,9 @@ describe('Group Model', () => {
|
|||||||
spell: 'earth',
|
spell: 'earth',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate spell_cast_user', () => {
|
it('translate spell_cast_user', () => {
|
||||||
@@ -888,8 +896,9 @@ describe('Group Model', () => {
|
|||||||
target: participatingMember.profile.name,
|
target: participatingMember.profile.name,
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate quest_cancel', () => {
|
it('translate quest_cancel', () => {
|
||||||
@@ -901,8 +910,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'basilist',
|
quest: 'basilist',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate quest_abort', () => {
|
it('translate quest_abort', () => {
|
||||||
@@ -914,8 +924,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'basilist',
|
quest: 'basilist',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate tavern_quest_completed', () => {
|
it('translate tavern_quest_completed', () => {
|
||||||
@@ -926,8 +937,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'stressbeast',
|
quest: 'stressbeast',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate tavern_boss_rage_tired', () => {
|
it('translate tavern_boss_rage_tired', () => {
|
||||||
@@ -938,8 +950,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'stressbeast',
|
quest: 'stressbeast',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate tavern_boss_rage', () => {
|
it('translate tavern_boss_rage', () => {
|
||||||
@@ -951,8 +964,9 @@ describe('Group Model', () => {
|
|||||||
scene: 'market',
|
scene: 'market',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate tavern_boss_desperation', () => {
|
it('translate tavern_boss_desperation', () => {
|
||||||
@@ -963,8 +977,9 @@ describe('Group Model', () => {
|
|||||||
quest: 'stressbeast',
|
quest: 'stressbeast',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('translate claim_task', () => {
|
it('translate claim_task', () => {
|
||||||
@@ -976,8 +991,9 @@ describe('Group Model', () => {
|
|||||||
task: 'Feed the pet',
|
task: 'Feed the pet',
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
party.translateSystemMessages(questLeader);
|
let toJSON = party.toJSON();
|
||||||
translationCheck(party.chat[0].text);
|
Group.translateSystemMessages(toJSON, questLeader);
|
||||||
|
translationCheck(toJSON.chat[0].text);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -333,6 +333,19 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
|||||||
return groupsArray;
|
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
|
// 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
|
// 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
|
// 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);
|
await getGroupChat(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
group.translateSystemMessages(user);
|
|
||||||
|
|
||||||
let toJSON = group.toJSON();
|
let toJSON = group.toJSON();
|
||||||
|
_translateSystemMessages(toJSON, user);
|
||||||
|
|
||||||
if (!user.contributor.admin) {
|
if (!user.contributor.admin) {
|
||||||
_.remove(toJSON.chat, chatMsg => {
|
_.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 () {
|
schema.methods.getParticipatingQuestMembers = function getParticipatingQuestMembers () {
|
||||||
return Object.keys(this.quest.members).filter(member => this.quest.members[member]);
|
return Object.keys(this.quest.members).filter(member => this.quest.members[member]);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user