Merge pull request #1616 from pafcu/fix-presence-i18n
Make PresenceLabel more easily translatable
This commit is contained in:
commit
c002d3ff99
2 changed files with 35 additions and 31 deletions
|
@ -44,6 +44,8 @@ module.exports = React.createClass({
|
|||
};
|
||||
},
|
||||
|
||||
// Return duration as a string using appropriate time units
|
||||
// XXX: This would be better handled using a culture-aware library, but we don't use one yet.
|
||||
getDuration: function(time) {
|
||||
if (!time) return;
|
||||
const t = parseInt(time / 1000);
|
||||
|
@ -53,41 +55,39 @@ module.exports = React.createClass({
|
|||
const d = parseInt(t / (60 * 60 * 24));
|
||||
if (t < 60) {
|
||||
if (t < 0) {
|
||||
return _t("for %(amount)ss", {amount: 0});
|
||||
return _t("%(duration)ss", {duration: 0});
|
||||
}
|
||||
return _t("for %(amount)ss", {amount: s});
|
||||
return _t("%(duration)ss", {duration: s});
|
||||
}
|
||||
if (t < 60 * 60) {
|
||||
return _t("for %(amount)sm", {amount: m});
|
||||
return _t("%(duration)sm", {duration: m});
|
||||
}
|
||||
if (t < 24 * 60 * 60) {
|
||||
return _t("for %(amount)sh", {amount: h});
|
||||
return _t("%(duration)sh", {duration: h});
|
||||
}
|
||||
return _t("for %(amount)sd", {amount: d});
|
||||
return _t("%(duration)sd", {duration: d});
|
||||
},
|
||||
|
||||
getPrettyPresence: function(presence) {
|
||||
if (presence === "online") return _t("Online");
|
||||
if (presence === "unavailable") return _t("Idle"); // XXX: is this actually right?
|
||||
if (presence === "offline") return _t("Offline");
|
||||
return _t("Unknown");
|
||||
getPrettyPresence: function(presence, activeAgo, currentlyActive) {
|
||||
if (!currentlyActive && activeAgo !== undefined && activeAgo > 0) {
|
||||
const duration = this.getDuration(activeAgo);
|
||||
if (presence === "online") return _t("Online for %(duration)s", { duration: duration });
|
||||
if (presence === "unavailable") return _t("Idle for %(duration)s", { duration: duration }); // XXX: is this actually right?
|
||||
if (presence === "offline") return _t("Offline for %(duration)s", { duration: duration });
|
||||
return _t("Unknown for %(duration)s", { duration: duration });
|
||||
} else {
|
||||
if (presence === "online") return _t("Online");
|
||||
if (presence === "unavailable") return _t("Idle"); // XXX: is this actually right?
|
||||
if (presence === "offline") return _t("Offline");
|
||||
return _t("Unknown");
|
||||
}
|
||||
},
|
||||
|
||||
render: function() {
|
||||
if (this.props.activeAgo >= 0) {
|
||||
const duration = this.getDuration(this.props.activeAgo);
|
||||
const ago = this.props.currentlyActive || !duration ? "" : duration;
|
||||
return (
|
||||
<div className="mx_PresenceLabel">
|
||||
{ this.getPrettyPresence(this.props.presenceState) } { ago }
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div className="mx_PresenceLabel">
|
||||
{ this.getPrettyPresence(this.props.presenceState) }
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="mx_PresenceLabel">
|
||||
{ this.getPrettyPresence(this.props.presenceState, this.props.activeAgo, this.props.currentlyActive) }
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue