From df921438f375184f8d5c67b45584a37ab5dd2d13 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Thu, 16 Nov 2017 18:36:54 +0100 Subject: [PATCH 1/2] Make PresenceLabel more easily translatable Signed-off-by: Stefan Parviainen --- src/components/views/rooms/PresenceLabel.js | 50 ++++++++++----------- src/i18n/strings/en_EN.json | 16 ++++--- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/components/views/rooms/PresenceLabel.js b/src/components/views/rooms/PresenceLabel.js index 69ba7c39c3..bcedb0e467 100644 --- a/src/components/views/rooms/PresenceLabel.js +++ b/src/components/views/rooms/PresenceLabel.js @@ -44,6 +44,8 @@ module.exports = React.createClass({ }; }, + // Return duration as a sting 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 ( -
- { this.getPrettyPresence(this.props.presenceState) } { ago } -
- ); - } else { - return ( -
- { this.getPrettyPresence(this.props.presenceState) } -
- ); - } + return ( +
+ { this.getPrettyPresence(this.props.presenceState, this.props.activeAgo, this.props.currentlyActive) } +
+ ); }, }); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 128a07bc15..93030269ad 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -227,8 +227,6 @@ "Delete": "Delete", "Disable Notifications": "Disable Notifications", "Enable Notifications": "Enable Notifications", - "URL previews are enabled by default for participants in this room.": "URL previews are enabled by default for participants in this room.", - "URL previews are disabled by default for participants in this room.": "URL previews are disabled by default for participants in this room.", "Cannot add any more widgets": "Cannot add any more widgets", "The maximum permitted number of widgets have already been added to this room.": "The maximum permitted number of widgets have already been added to this room.", "Add a widget": "Add a widget", @@ -321,10 +319,14 @@ "No pinned messages.": "No pinned messages.", "Loading...": "Loading...", "Pinned Messages": "Pinned Messages", - "for %(amount)ss": "for %(amount)ss", - "for %(amount)sm": "for %(amount)sm", - "for %(amount)sh": "for %(amount)sh", - "for %(amount)sd": "for %(amount)sd", + "%(duration)ss": "%(duration)ss", + "%(duration)sm": "%(duration)sm", + "%(duration)sh": "%(duration)sh", + "%(duration)sd": "%(duration)sd", + "Online for %(duration)s": "Online for %(duration)s", + "Idle for %(duration)s": "Idle for %(duration)s", + "Offline for %(duration)s": "Offline for %(duration)s", + "Unknown for %(duration)s": "Unknown for %(duration)s", "Online": "Online", "Idle": "Idle", "Offline": "Offline", @@ -456,6 +458,8 @@ "New community ID (e.g. +foo:%(localDomain)s)": "New community ID (e.g. +foo:%(localDomain)s)", "You have enabled URL previews by default.": "You have enabled URL previews by default.", "You have disabled URL previews by default.": "You have disabled URL previews by default.", + "URL previews are enabled by default for participants in this room.": "URL previews are enabled by default for participants in this room.", + "URL previews are disabled by default for participants in this room.": "URL previews are disabled by default for participants in this room.", "URL Previews": "URL Previews", "Error decrypting audio": "Error decrypting audio", "Error decrypting attachment": "Error decrypting attachment", From a784abd57f10fa013ccfa2d0ca99ccebf0ff5d5f Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 22 Nov 2017 17:13:18 +0000 Subject: [PATCH 2/2] Comment typo --- src/components/views/rooms/PresenceLabel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/PresenceLabel.js b/src/components/views/rooms/PresenceLabel.js index bcedb0e467..b6e171100b 100644 --- a/src/components/views/rooms/PresenceLabel.js +++ b/src/components/views/rooms/PresenceLabel.js @@ -44,7 +44,7 @@ module.exports = React.createClass({ }; }, - // Return duration as a sting using appropriate time units + // 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;