Simplify MemberEventListSummary by using pluralization provided by the i18n library

Signed-off-by: Stefan Parviainen <pafcu@iki.fi>
pull/21833/head
Stefan Parviainen 2017-10-17 23:46:23 +02:00
parent fc860c66bc
commit 7eeed3e093
1 changed files with 40 additions and 114 deletions

View File

@ -86,7 +86,6 @@ module.exports = React.createClass({
const summaries = orderedTransitionSequences.map((transitions) => { const summaries = orderedTransitionSequences.map((transitions) => {
const userNames = eventAggregates[transitions]; const userNames = eventAggregates[transitions];
const nameList = this._renderNameList(userNames); const nameList = this._renderNameList(userNames);
const plural = userNames.length > 1;
const splitTransitions = transitions.split(','); const splitTransitions = transitions.split(',');
@ -101,7 +100,7 @@ module.exports = React.createClass({
const descs = coalescedTransitions.map((t) => { const descs = coalescedTransitions.map((t) => {
return this._getDescriptionForTransition( return this._getDescriptionForTransition(
t.transitionType, plural, t.repeats, t.transitionType, userNames.length, t.repeats,
); );
}); });
@ -208,148 +207,75 @@ module.exports = React.createClass({
* For a certain transition, t, describe what happened to the users that * For a certain transition, t, describe what happened to the users that
* underwent the transition. * underwent the transition.
* @param {string} t the transition type. * @param {string} t the transition type.
* @param {boolean} plural whether there were multiple users undergoing the same * @param {integer} userCount number of usernames
* transition.
* @param {number} repeats the number of times the transition was repeated in a row. * @param {number} repeats the number of times the transition was repeated in a row.
* @returns {string} the written Human Readable equivalent of the transition. * @returns {string} the written Human Readable equivalent of the transition.
*/ */
_getDescriptionForTransition(t, plural, repeats) { _getDescriptionForTransition(t, userCount, repeats) {
// The empty interpolations 'severalUsers' and 'oneUser' // The empty interpolations 'severalUsers' and 'oneUser'
// are there only to show translators to non-English languages // are there only to show translators to non-English languages
// that the verb is conjugated to plural or singular Subject. // that the verb is conjugated to plural or singular Subject.
let res = null; let res = null;
switch(t) { switch(t) {
case "joined": case "joined":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)sjoined %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)sjoined %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)sjoined %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)sjoined %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)sjoined", { severalUsers: "" })
: _t("%(oneUser)sjoined", { oneUser: "" });
}
break; break;
case "left": case "left":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)sleft %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)sleft %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)sleft %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)sleft %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)sleft", { severalUsers: "" })
: _t("%(oneUser)sleft", { oneUser: "" });
}
break; break;
case "joined_and_left": case "joined_and_left":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)sjoined and left %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)sjoined and left %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)sjoined and left %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)sjoined and left %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)sjoined and left", { severalUsers: "" })
: _t("%(oneUser)sjoined and left", { oneUser: "" });
}
break; break;
case "left_and_joined": case "left_and_joined":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)sleft and rejoined %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)sleft and rejoined %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)sleft and rejoined %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)sleft and rejoined %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)sleft and rejoined", { severalUsers: "" })
: _t("%(oneUser)sleft and rejoined", { oneUser: "" });
}
break; break;
case "invite_reject": case "invite_reject":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)srejected their invitations %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)srejected their invitations %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)srejected their invitation %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)srejected their invitation %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)srejected their invitations", { severalUsers: "" })
: _t("%(oneUser)srejected their invitation", { oneUser: "" });
}
break; break;
case "invite_withdrawal": case "invite_withdrawal":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)shad their invitations withdrawn %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)shad their invitations withdrawn %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)shad their invitation withdrawn %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)shad their invitation withdrawn %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)shad their invitations withdrawn", { severalUsers: "" })
: _t("%(oneUser)shad their invitation withdrawn", { oneUser: "" });
}
break; break;
case "invited": case "invited":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("were invited %(count)s times", { count: repeats })
? _t("were invited %(repeats)s times", { repeats: repeats }) : _t("was invited %(count)s times", { count: repeats });
: _t("was invited %(repeats)s times", { repeats: repeats });
} else {
res = (plural)
? _t("were invited")
: _t("was invited");
}
break; break;
case "banned": case "banned":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("were banned %(count)s times", { count: repeats })
? _t("were banned %(repeats)s times", { repeats: repeats }) : _t("was banned %(count)s times", { count: repeats });
: _t("was banned %(repeats)s times", { repeats: repeats });
} else {
res = (plural)
? _t("were banned")
: _t("was banned");
}
break; break;
case "unbanned": case "unbanned":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("were unbanned %(count)s times", { count: repeats })
? _t("were unbanned %(repeats)s times", { repeats: repeats }) : _t("was unbanned %(count)s times", { count: repeats });
: _t("was unbanned %(repeats)s times", { repeats: repeats });
} else {
res = (plural)
? _t("were unbanned")
: _t("was unbanned");
}
break; break;
case "kicked": case "kicked":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("were kicked %(count)s times", { count: repeats })
? _t("were kicked %(repeats)s times", { repeats: repeats }) : _t("was kicked %(count)s times", { count: repeats });
: _t("was kicked %(repeats)s times", { repeats: repeats });
} else {
res = (plural)
? _t("were kicked")
: _t("was kicked");
}
break; break;
case "changed_name": case "changed_name":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)schanged their name %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)schanged their name %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)schanged their name %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)schanged their name %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)schanged their name", { severalUsers: "" })
: _t("%(oneUser)schanged their name", { oneUser: "" });
}
break; break;
case "changed_avatar": case "changed_avatar":
if (repeats > 1) { res = (userCount > 1)
res = (plural) ? _t("%(severalUsers)schanged their avatar %(count)s times", { severalUsers: "", count: repeats })
? _t("%(severalUsers)schanged their avatar %(repeats)s times", { severalUsers: "", repeats: repeats }) : _t("%(oneUser)schanged their avatar %(count)s times", { oneUser: "", count: repeats });
: _t("%(oneUser)schanged their avatar %(repeats)s times", { oneUser: "", repeats: repeats });
} else {
res = (plural)
? _t("%(severalUsers)schanged their avatar", { severalUsers: "" })
: _t("%(oneUser)schanged their avatar", { oneUser: "" });
}
break; break;
} }