Commit a83e2c70 by Greg Price

Modify jquery.timeago to better support i18n

Use string interpolation instead of concatenation of prefix, content,
and suffix. This is motivated by the fact that Transifex does not accept
empty strings for translation (even when pgettext is used to provide
context).
parent de548fbf
jQuery.timeago.settings.strings = { jQuery.timeago.settings.strings = {
prefixAgo: pgettext("Prefix indicating time ago", ""), formatAgo: gettext("%s ago"),
prefixFromNow: pgettext("Prefix indicating time from now", ""), formatFromNow: gettext("%s from now"),
suffixAgo: pgettext("Suffix indicating time ago", "ago"),
suffixFromNow: pgettext("Suffix indicating time from now", "from now"),
seconds: gettext("less than a minute"), seconds: gettext("less than a minute"),
minute: gettext("about a minute"), minute: gettext("about a minute"),
minutes: function(value) { return ngettext("%d minute", "%d minutes", value)}, minutes: function(value) { return ngettext("%d minute", "%d minutes", value)},
...@@ -14,6 +12,5 @@ jQuery.timeago.settings.strings = { ...@@ -14,6 +12,5 @@ jQuery.timeago.settings.strings = {
months: function(value) { return ngettext("%d month", "%d months", value) }, months: function(value) { return ngettext("%d month", "%d months", value) },
year: gettext("about a year"), year: gettext("about a year"),
years: function(value) { return ngettext("%d year", "%d years", value) }, years: function(value) { return ngettext("%d year", "%d years", value) },
wordSeparator: pgettext("Word separator", " "),
numbers: [] numbers: []
}; };
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
* @version 0.11.4 * @version 0.11.4
* @requires jQuery v1.2.3+ * @requires jQuery v1.2.3+
* @author Ryan McGeary * @author Ryan McGeary
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
* *
* For usage and examples, visit: * For usage and examples, visit:
* http://timeago.yarp.com/ * http://timeago.yarp.com/
* *
* Copyright (c) 2008-2012, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org) * Portions copyright (c) 2008-2012, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
* and licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
*/ */
(function($) { (function($) {
$.timeago = function(timestamp) { $.timeago = function(timestamp) {
...@@ -32,10 +32,8 @@ ...@@ -32,10 +32,8 @@
refreshMillis: 60000, refreshMillis: 60000,
allowFuture: false, allowFuture: false,
strings: { strings: {
prefixAgo: null, formatAgo: "%s ago",
prefixFromNow: null, formatFromNow: "%s from now",
suffixAgo: "ago",
suffixFromNow: "from now",
seconds: "less than a minute", seconds: "less than a minute",
minute: "about a minute", minute: "about a minute",
minutes: "%d minutes", minutes: "%d minutes",
...@@ -47,18 +45,15 @@ ...@@ -47,18 +45,15 @@
months: "%d months", months: "%d months",
year: "about a year", year: "about a year",
years: "%d years", years: "%d years",
wordSeparator: " ",
numbers: [] numbers: []
} }
}, },
inWords: function(distanceMillis) { inWords: function(distanceMillis) {
var $l = this.settings.strings; var $l = this.settings.strings;
var prefix = $l.prefixAgo; var format = $l.formatAgo;
var suffix = $l.suffixAgo;
if (this.settings.allowFuture) { if (this.settings.allowFuture) {
if (distanceMillis < 0) { if (distanceMillis < 0) {
prefix = $l.prefixFromNow; format = $l.formatFromNow;
suffix = $l.suffixFromNow;
} }
} }
...@@ -86,8 +81,7 @@ ...@@ -86,8 +81,7 @@
years < 1.5 && substitute($l.year, 1) || years < 1.5 && substitute($l.year, 1) ||
substitute($l.years, Math.round(years)); substitute($l.years, Math.round(years));
var separator = $l.wordSeparator === undefined ? " " : $l.wordSeparator; return $.trim(format.replace(/%s/i, words));
return $.trim([prefix, words, suffix].join(separator));
}, },
parse: function(iso8601) { parse: function(iso8601) {
var s = $.trim(iso8601); var s = $.trim(iso8601);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment