From cc2d116e47e27eccc00ec215c3fe3ef1f65f13cb Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 25 Jun 2012 17:35:45 +0200 Subject: [PATCH] [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 --- addons/web/i18n/fr.po | 44 +++++++++++++++++++ .../lib/jquery.timeago/jquery.timeago.js | 23 +++++++--- addons/web/static/src/js/coresetup.js | 7 +-- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/addons/web/i18n/fr.po b/addons/web/i18n/fr.po index 134f1d4c05b..7d61f70f7ef 100644 --- a/addons/web/i18n/fr.po +++ b/addons/web/i18n/fr.po @@ -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" diff --git a/addons/web/static/lib/jquery.timeago/jquery.timeago.js b/addons/web/static/lib/jquery.timeago/jquery.timeago.js index 7e138c9d328..3ee5f20ac88 100644 --- a/addons/web/static/lib/jquery.timeago/jquery.timeago.js +++ b/addons/web/static/lib/jquery.timeago/jquery.timeago.js @@ -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); diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 99e134e7bd4..ace41234e0c 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -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);