Quest started translation support

This commit is contained in:
Mateus Etto
2018-02-17 17:15:14 +09:00
parent b0ae0ef4da
commit bd21933cea
2 changed files with 25 additions and 4 deletions

View File

@@ -429,5 +429,6 @@
"worldBossBullet1": "Complete tasks to damage the World Boss", "worldBossBullet1": "Complete tasks to damage the World Boss",
"worldBossBullet2": "The World Boss wont damage you for missed tasks, but its Rage meter will go up. If the bar fills up, the Boss will attack one of Habiticas shopkeepers!", "worldBossBullet2": "The World Boss wont damage you for missed tasks, but its Rage meter will go up. If the bar fills up, the Boss will attack one of Habiticas shopkeepers!",
"worldBossBullet3": "You can continue with normal Quest Bosses, damage will apply to both", "worldBossBullet3": "You can continue with normal Quest Bosses, damage will apply to both",
"worldBossBullet4": "Check the Tavern regularly to see World Boss progress and Rage attacks" "worldBossBullet4": "Check the Tavern regularly to see World Boss progress and Rage attacks",
"chatQuestStarted": "Your quest, <%= questName %>, has started."
} }

View File

@@ -317,11 +317,27 @@ schema.statics.getGroups = async function getGroups (options = {}) {
return groupsArray; return groupsArray;
}; };
function translateSystemMessages(group, user) {
for (let i = 0; i < group.chat.length; i++) {
if (_.isEmpty(group.chat[i].info)) {
continue;
}
switch (group.chat[i].info.type) {
case 'quest_start':
group.chat[i].text = '`' + shared.i18n.t('chatQuestStarted', {'questName': questScrolls[group.chat[i].info.quest].text(user.preferences.language)}, user.preferences.language) + '`';
break;
}
}
return group;
}
// 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
// It also removes the _meta field that can be stored inside a chat message // It also removes the _meta field that can be stored inside a chat message
schema.statics.toJSONCleanChat = function groupToJSONCleanChat (group, user) { schema.statics.toJSONCleanChat = function groupToJSONCleanChat (group, user) {
group = translateSystemMessages(group, user);
let toJSON = group.toJSON(); let toJSON = group.toJSON();
if (!user.contributor.admin) { if (!user.contributor.admin) {
@@ -442,10 +458,11 @@ schema.methods.isMember = function isGroupMember (user) {
} }
}; };
export function chatDefaults (msg, user) { export function chatDefaults (msg, user, info={}) {
let message = { let message = {
id: shared.uuid(), id: shared.uuid(),
text: msg, text: msg,
info: info,
timestamp: Number(new Date()), timestamp: Number(new Date()),
likes: {}, likes: {},
flags: {}, flags: {},
@@ -509,8 +526,8 @@ function setUserStyles (newMessage, user) {
newMessage.userStyles = userStyles; newMessage.userStyles = userStyles;
} }
schema.methods.sendChat = function sendChat (message, user, metaData) { schema.methods.sendChat = function sendChat (message, user, metaData, info={}) {
let newMessage = chatDefaults(message, user); let newMessage = chatDefaults(message, user, info);
if (user) setUserStyles(newMessage, user); if (user) setUserStyles(newMessage, user);
@@ -696,6 +713,9 @@ schema.methods.startQuest = async function startQuest (user) {
}); });
this.sendChat(`\`Your quest, ${quest.text('en')}, has started.\``, null, { this.sendChat(`\`Your quest, ${quest.text('en')}, has started.\``, null, {
participatingMembers: this.getParticipatingQuestMembers().join(', '), participatingMembers: this.getParticipatingQuestMembers().join(', '),
}, {
'type': 'quest_start',
'quest': quest.key,
}); });
}; };