From 734f33233346bc671be2755a8ddcc687a8a5495f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Sun, 24 Jul 2016 17:40:06 +0200 Subject: [PATCH] Properly support pluralization in timeago strings --- app/assets/javascripts/widgets/timeago.js | 17 ++++++++++++----- config/locales/javascript/javascript.en.yml | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/widgets/timeago.js b/app/assets/javascripts/widgets/timeago.js index dcb680864..4d159818f 100644 --- a/app/assets/javascripts/widgets/timeago.js +++ b/app/assets/javascripts/widgets/timeago.js @@ -7,14 +7,21 @@ (function() { Diaspora.Widgets.TimeAgo = function() { this.subscribe("widget/ready", function() { - if(Diaspora.I18n.language !== "en") { + if (Diaspora.I18n.language !== "en") { $.timeago.settings.lang = Diaspora.I18n.language; $.timeago.settings.strings[Diaspora.I18n.language] = {}; - $.each($.timeago.settings.strings["en"], function(index) { - if(index === "numbers") { + $.each($.timeago.settings.strings.en, function(index) { + if (index === "numbers") { $.timeago.settings.strings[Diaspora.I18n.language][index] = []; - } - else { + } else if (index === "minutes" || + index === "hours" || + index === "days" || + index === "months" || + index === "years") { + $.timeago.settings.strings[Diaspora.I18n.language][index] = function(value) { + return Diaspora.I18n.t("timeago." + index, {count: value}); + }; + } else { $.timeago.settings.strings[Diaspora.I18n.language][index] = Diaspora.I18n.t("timeago." + index); } }); diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index 370e45480..7a40c7322 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -95,15 +95,25 @@ en: inPast: "any moment now" seconds: "less than a minute" minute: "about a minute" - minutes: "%d minutes" + minutes: + one: "1 minute" + other: "%d minutes" hour: "about an hour" - hours: "about %d hours" + hours: + one: "about 1 hour" + other: "about %d hours" day: "a day" - days: "%d days" + days: + one: "1 day" + other: "%d days" month: "about a month" - months: "%d months" + months: + one: "1 month" + other: "%d months" year: "about a year" - years: "%d years" + years: + one: "1 year" + other: "%d years" wordSeparator: " " contacts: