From c43bc8400bef28cee10d6bd11eaf90d54f8518a7 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 25 Jun 2012 13:00:05 +0200 Subject: [PATCH 1/5] [FIX] i18n in timeago lib bzr revid: abo@openerp.com-20120625110005-qabe72k4pipvr4xw --- addons/web/i18n/fr.po | 60 +++++++++++++++++++ .../lib/jquery.timeago/jquery.timeago.js | 8 +-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/addons/web/i18n/fr.po b/addons/web/i18n/fr.po index 134f1d4c05b..d40f49e31e7 100644 --- a/addons/web/i18n/fr.po +++ b/addons/web/i18n/fr.po @@ -1556,3 +1556,63 @@ msgstr "Pour plus d'informations veuillez consulter" #: addons/web/static/src/xml/base.xml:1823 msgid "OpenERP.com" msgstr "OpenERP.com" + +#. openerp-web +msgid "timeago-prefixAgo" +msgstr "Il y a" + +#. openerp-web +msgid "timeago-prefixFromNow" +msgstr " " + +#. openerp-web +msgid "timeago-suffixAgo" +msgstr " " + +#. openerp-web +msgid "timeago-suffixFromNow" +msgstr " " + +#. openerp-web +msgid "less than a minute" +msgstr "moins d'une minute" + +#. openerp-web +msgid "about a minute" +msgstr "environ une minute" + +#. openerp-web +msgid "%d minutes" +msgstr "%d minutes" + +#. openerp-web +msgid "about an hour" +msgstr "environ une heure" + +#. openerp-web +msgid "%d hours" +msgstr "%d heures" + +#. openerp-web +msgid "a days" +msgstr "un jours" + +#. openerp-web +msgid "%d days" +msgstr "%d jours" + +#. openerp-web +msgid "about a month" +msgstr "environ un mois" + +#. openerp-web +msgid "%d mois" +msgstr "%d mois" + +#. openerp-web +msgid "about a year" +msgstr "environ un an" + +#. openerp-web +msgid "%d years" +msgstr "%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 14177473973..341a1841c94 100644 --- a/addons/web/static/lib/jquery.timeago/jquery.timeago.js +++ b/addons/web/static/lib/jquery.timeago/jquery.timeago.js @@ -32,10 +32,10 @@ refreshMillis: 60000, allowFuture: false, strings: { - prefixAgo: null, - prefixFromNow: null, - suffixAgo: "ago", - suffixFromNow: "from now", + prefixAgo: "timeago-prefixAgo", + prefixFromNow: "timeago-prefixFromNow", + suffixAgo: "timeago-suffixAgo", //ago + suffixFromNow: "timeago-suffixFromNow", //from now seconds: "less than a minute", minute: "about a minute", minutes: "%d minutes", From 5fc38ee41d6465d20c6dd7a90da8aed9090d049b Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 25 Jun 2012 15:29:35 +0200 Subject: [PATCH 2/5] [RST] after a talk in the lunch room, back to the drawing board bzr revid: abo@openerp.com-20120625132935-zk6u5l0ifolz0g6y --- addons/web/i18n/fr.po | 60 ------------------- .../lib/jquery.timeago/jquery.timeago.js | 11 ++-- 2 files changed, 6 insertions(+), 65 deletions(-) diff --git a/addons/web/i18n/fr.po b/addons/web/i18n/fr.po index d40f49e31e7..134f1d4c05b 100644 --- a/addons/web/i18n/fr.po +++ b/addons/web/i18n/fr.po @@ -1556,63 +1556,3 @@ msgstr "Pour plus d'informations veuillez consulter" #: addons/web/static/src/xml/base.xml:1823 msgid "OpenERP.com" msgstr "OpenERP.com" - -#. openerp-web -msgid "timeago-prefixAgo" -msgstr "Il y a" - -#. openerp-web -msgid "timeago-prefixFromNow" -msgstr " " - -#. openerp-web -msgid "timeago-suffixAgo" -msgstr " " - -#. openerp-web -msgid "timeago-suffixFromNow" -msgstr " " - -#. openerp-web -msgid "less than a minute" -msgstr "moins d'une minute" - -#. openerp-web -msgid "about a minute" -msgstr "environ une minute" - -#. openerp-web -msgid "%d minutes" -msgstr "%d minutes" - -#. openerp-web -msgid "about an hour" -msgstr "environ une heure" - -#. openerp-web -msgid "%d hours" -msgstr "%d heures" - -#. openerp-web -msgid "a days" -msgstr "un jours" - -#. openerp-web -msgid "%d days" -msgstr "%d jours" - -#. openerp-web -msgid "about a month" -msgstr "environ un mois" - -#. openerp-web -msgid "%d mois" -msgstr "%d mois" - -#. openerp-web -msgid "about a year" -msgstr "environ un an" - -#. openerp-web -msgid "%d years" -msgstr "%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 341a1841c94..7e138c9d328 100644 --- a/addons/web/static/lib/jquery.timeago/jquery.timeago.js +++ b/addons/web/static/lib/jquery.timeago/jquery.timeago.js @@ -32,10 +32,10 @@ refreshMillis: 60000, allowFuture: false, strings: { - prefixAgo: "timeago-prefixAgo", - prefixFromNow: "timeago-prefixFromNow", - suffixAgo: "timeago-suffixAgo", //ago - suffixFromNow: "timeago-suffixFromNow", //from now + prefixAgo: null, + prefixFromNow: null, + suffixAgo: "ago", + suffixFromNow: "from now", seconds: "less than a minute", minute: "about a minute", minutes: "%d minutes", @@ -49,7 +49,8 @@ years: "%d years", wordSeparator: " ", numbers: [] - } + }, + translator: function(str) {} }, inWords: function(distanceMillis) { var $l = this.settings.strings; From cc2d116e47e27eccc00ec215c3fe3ef1f65f13cb Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 25 Jun 2012 17:35:45 +0200 Subject: [PATCH 3/5] [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); From 9112bc7db140935f0c0ec78a5934ad653558cd20 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Mon, 25 Jun 2012 19:20:55 +0200 Subject: [PATCH 4/5] [IMP] continue refactoring timeago.js, following the conversation on this pull request: https://github.com/rmm5t/jquery-timeago/pull/83 - remove bad usage of global variable stringAndNumber - use a consistent name for the substitute() function which was actully not substituing anything anymore bzr revid: abo@openerp.com-20120625172055-5njlig9lukjuf8yd --- .../lib/jquery.timeago/jquery.timeago.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/addons/web/static/lib/jquery.timeago/jquery.timeago.js b/addons/web/static/lib/jquery.timeago/jquery.timeago.js index 3ee5f20ac88..70b1023d9e5 100644 --- a/addons/web/static/lib/jquery.timeago/jquery.timeago.js +++ b/addons/web/static/lib/jquery.timeago/jquery.timeago.js @@ -3,7 +3,6 @@ * 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 @@ -72,24 +71,24 @@ var days = hours / 24; var years = days / 365; - function substitute(stringOrFunction, number) { + function convert(stringOrFunction, number) { var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction; // return the proper string and the numeric value that goes in it - return stringAndNumber = {'string': string, 'value': ($l.numbers && $l.numbers[number]) || number}; + return {'string': string, 'value': ($l.numbers && $l.numbers[number]) || number}; } - var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) || - seconds < 90 && substitute($l.minute, 1) || - minutes < 45 && substitute($l.minutes, Math.round(minutes)) || - minutes < 90 && substitute($l.hour, 1) || - hours < 24 && substitute($l.hours, Math.round(hours)) || - hours < 42 && substitute($l.day, 1) || - days < 30 && substitute($l.days, Math.round(days)) || - days < 45 && substitute($l.month, 1) || - days < 365 && substitute($l.months, Math.round(days / 30)) || - years < 1.5 && substitute($l.year, 1) || - substitute($l.years, Math.round(years)); + var stringAndNumber = seconds < 45 && convert($l.seconds, Math.round(seconds)) || + seconds < 90 && convert($l.minute, 1) || + minutes < 45 && convert($l.minutes, Math.round(minutes)) || + minutes < 90 && convert($l.hour, 1) || + hours < 24 && convert($l.hours, Math.round(hours)) || + hours < 42 && convert($l.day, 1) || + days < 30 && convert($l.days, Math.round(days)) || + days < 45 && convert($l.month, 1) || + days < 365 && convert($l.months, Math.round(days / 30)) || + years < 1.5 && convert($l.year, 1) || + convert($l.years, Math.round(years)); var string = stringAndNumber.string; var value = stringAndNumber.value; From 21cf7115be08aa00ed98bb33e753316737a8a8b6 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Thu, 28 Jun 2012 15:33:53 +0200 Subject: [PATCH 5/5] [IMP] make the strings composed by timeago.js easy to spot for launchpad rosetta by explicitly calling _t() method on them bzr revid: abo@openerp.com-20120628133353-7dx34sktz9eh3xxd --- addons/web/static/src/js/coresetup.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index ace41234e0c..b599a543055 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -606,7 +606,28 @@ instance.web.qweb.preprocess_node = function() { /** Setup jQuery timeago */ var timeago_setup = function () { + // provide timeago.js with our own translator method $.timeago.settings.translator = instance.web._t; + + /* + * Strings in timeago are "composed" with prefixes, words and suffixes. + * This makes their detection by the translating system pretty much + * imposible, so we'll declare those which will be used in a more explicit + * way. + */ + var timeAgoStrings = [ + instance.web._t('less than a minute ago'), + instance.web._t('about a minute ago'), + instance.web._t('%d minutes ago'), + instance.web._t('about an hour ago'), + instance.web._t('%d hours ago'), + instance.web._t('a day ago'), + instance.web._t('%d days ago'), + instance.web._t('about a month ago'), + instance.web._t('%d months ago'), + instance.web._t('about a year ago'), + instance.web._t('%d years ago'), + ]; } instance.connection.on('module_loaded', this, timeago_setup);