From e836bfd3f7631099b8714a7f849c3ef3f3338c00 Mon Sep 17 00:00:00 2001 From: Benedikt Radtke Date: Sun, 26 Jun 2016 20:36:36 +0200 Subject: [PATCH] Added basic localization for timestamps This commit implements basic localization for the timestamps in conversations and the conversation list. // FREEBIE --- _locales/en/messages.json | 66 +++++++++++++++++++++++++++++++++++++- js/views/timestamp_view.js | 41 ++++++----------------- 2 files changed, 74 insertions(+), 33 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 809f3e68b96..5066193dde5 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -308,5 +308,69 @@ "syncFailed": { "message": "Import failed. Make sure your computer and your phone are connected to the internet.", "description": "Informational text displayed if a sync operation times out." - } + }, + "timestamp_s": { + "description": "", + "message": "now" + }, + "timestamp_m": { + "description": "", + "message": "1 min" + }, + "timestamp_mm": { + "description": "", + "message": "%d min" + }, + "timestamp_h": { + "description": "", + "message": "1 hour" + }, + "timestamp_hh": { + "description": "", + "message": "%d hours" + }, + "timestampFormat_y" : { + "description": "", + "message": "MMM D, YYYY" + }, + "timestampFormat_m" : { + "description": "", + "message": "MMM D" + }, + "timestampFormat_d" : { + "description": "", + "message": "ddd" + }, + "extendedTimestamp_s": { + "description": "", + "message": "now" + }, + "extendedTimestamp_m": { + "description": "", + "message": "1 minute ago" + }, + "extendedTimestamp_mm": { + "description": "", + "message": "%d minute ago" + }, + "extendedTimestamp_h": { + "description": "", + "message": "1 hour ago" + }, + "extendedTimestamp_hh": { + "description": "", + "message": "%d hours ago" + }, + "extendedTimestampFormat_y" : { + "description": "", + "message": "MMM D, YYYY LT" + }, + "extendedTimestampFormat_m" : { + "description": "", + "message": "MMM D LT" + }, + "extendedTimestampFormat_d" : { + "description": "", + "message": "ddd LT" + } } diff --git a/js/views/timestamp_view.js b/js/views/timestamp_view.js index 6c82cf9b8b7..80dfa3fede4 100644 --- a/js/views/timestamp_view.js +++ b/js/views/timestamp_view.js @@ -66,45 +66,22 @@ } }, relativeTime : function (number, string, isFuture) { - return this._relativeTime[string].replace(/%d/i, number); - }, - _relativeTime : { - s: "now", - m: "1 min", - mm: "%d min", - h: "1 hour", - hh: "%d hours", - d: "1 day", - dd: "%d days", - M: "1 month", - MM: "%d months", - y: "1 year", - yy: "%d years" + return i18n("timestamp_"+string).replace(/%d/i, number); }, _format: { - y: 'MMM D, YYYY', - m: 'MMM D', - d: 'ddd' + y: i18n('timestampFormat_y'), + m: i18n('timestampFormat_m'), + d: i18n('timestampFormat_d') } }); Whisper.ExtendedTimestampView = Whisper.TimestampView.extend({ - _relativeTime : { - s: "now", - m: "1 minute ago", - mm: "%d minutes ago", - h: "1 hour ago", - hh: "%d hours ago", - d: "1 day ago", - dd: "%d days ago", - M: "1 month ago", - MM: "%d months ago", - y: "1 year ago", - yy: "%d years ago" + relativeTime : function (number, string, isFuture) { + return i18n("extendedTimestamp_"+string).replace(/%d/i, number); }, _format: { - y: 'MMM D, YYYY LT', - m: 'MMM D LT', - d: 'ddd LT' + y: i18n('extendedTimestampFormat_y'), + m: i18n('extendedTimestampFormat_m'), + d: i18n('extendedTimestampFormat_d') } }); })();