[IMP] better integration of openerp's i18n in timeago.js

a suggestion for easier third party i18n integration will be made on the original project's git repo: https://github.com/rmm5t/jquery-timeago

bzr revid: abo@openerp.com-20120625153545-zca7qljrizugxntk
This commit is contained in:
Antonin Bourguignon 2012-06-25 17:35:45 +02:00
parent 5fc38ee41d
commit cc2d116e47
3 changed files with 63 additions and 11 deletions

View File

@ -1556,3 +1556,47 @@ msgstr "Pour plus d'informations veuillez consulter"
#: addons/web/static/src/xml/base.xml:1823
msgid "OpenERP.com"
msgstr "OpenERP.com"
#. openerp-web
msgid "less than a minute ago"
msgstr "Il y a moins d'une minute"
#. openerp-web
msgid "about a minute ago"
msgstr "Il y a une minute"
#. openerp-web
msgid "%d minutes ago"
msgstr "Il y a %d minutes"
#. openerp-web
msgid "about an hour ago"
msgstr "Il y a une heure"
#. openerp-web
msgid "%d hours ago"
msgstr "Il y a %d heures"
#. openerp-web
msgid "a day ago"
msgstr "Il y a un jour"
#. openerp-web
msgid "%d days ago"
msgstr "Il y a %d jours"
#. openerp-web
msgid "about a month ago"
msgstr "Il y a un mois"
#. openerp-web
msgid "%d months ago"
msgstr "Il y a %d mois"
#. openerp-web
msgid "about a year ago"
msgstr "Il y a un an"
#. openerp-web
msgid "%d years ago"
msgstr "Il y a %d ans"

View File

@ -1,6 +1,9 @@
/**
* Timeago is a jQuery plugin that makes it easy to support automatically
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
*
* Please note that the library has been slightly modified for i18n's sake.
*
*
* @name timeago
* @version 0.11.3
@ -50,7 +53,7 @@
wordSeparator: " ",
numbers: []
},
translator: function(str) {}
translator: null
},
inWords: function(distanceMillis) {
var $l = this.settings.strings;
@ -71,8 +74,9 @@
function substitute(stringOrFunction, number) {
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
var value = ($l.numbers && $l.numbers[number]) || number;
return string.replace(/%d/i, value);
// return the proper string and the numeric value that goes in it
return stringAndNumber = {'string': string, 'value': ($l.numbers && $l.numbers[number]) || number};
}
var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
@ -86,9 +90,18 @@
days < 365 && substitute($l.months, Math.round(days / 30)) ||
years < 1.5 && substitute($l.year, 1) ||
substitute($l.years, Math.round(years));
var string = stringAndNumber.string;
var value = stringAndNumber.value;
var separator = $l.wordSeparator === undefined ? " " : $l.wordSeparator;
return $.trim([prefix, words, suffix].join(separator));
// compose and translate the final string
var fullString = $.trim([prefix, string, suffix].join(separator));
var translatedString = $t.settings.translator ?
$t.settings.translator(fullString) :
fullString;
return translatedString.replace(/%d/i, value);
},
parse: function(iso8601) {
var s = $.trim(iso8601);

View File

@ -606,12 +606,7 @@ instance.web.qweb.preprocess_node = function() {
/** Setup jQuery timeago */
var timeago_setup = function () {
var s = $.timeago.settings.strings;
_.each(s, function(v,k) {
if(_.isString(v)) {
s[k] = instance.web._t(v);
}
});
$.timeago.settings.translator = instance.web._t;
}
instance.connection.on('module_loaded', this, timeago_setup);