[IMP] slightly refactor timeago.js for l18n's sake

bzr revid: abo@openerp.com-20120620174743-s603skiqcisu2yhm
This commit is contained in:
Antonin Bourguignon
2012-06-20 19:47:43 +02:00
parent 688ced2225
commit 86b2f33f71
2 changed files with 62 additions and 23 deletions
+31 -3
View File
@@ -166,17 +166,17 @@ msgstr ""
#. module: mail
#: view:mail.message:0 field:mail.message,state:0
msgid "State"
msgstr ""
msgstr "État"
#. module: mail
#: view:mail.message:0
msgid "Reply"
msgstr ""
msgstr "Répondre"
#. module: mail
#: view:mail.message:0 selection:mail.message,state:0
msgid "Sent"
msgstr ""
msgstr "Envoyé"
#. module: mail
#: help:mail.compose.message,subtype:0 help:mail.message,subtype:0
@@ -514,6 +514,34 @@ msgstr ""
msgid "Preferred response address for the message"
msgstr "Adresse de réponse préférée pour le message"
#. 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 "a day ago"
msgstr "il y a un jour"
#. openerp-web
msgid "%d days ago"
msgstr "il y a %d jours"
#. openerp-web
msgid "a month ago"
msgstr "il y a un mois"
#. openerp-web
msgid "%d months ago"
msgstr "il y a %d mois"
#. openerp-web
msgid "History and Comments"
msgstr "Historique et commentaires"
#~ msgid "Text contents"
#~ msgstr "Contenu du texte"
+31 -20
View File
@@ -841,10 +841,13 @@ openerp.mail = function(session) {
var call_done = this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment', 'html']).then(this.proxy('init_and_fetch_comments'));
},
});
/**
* Compute relative time from a date (ISO format)
* Code from http://timeago.yarp.com/
* Please note that the library has been slightly refactored for i18n's sake.
*
*
*
@@ -910,33 +913,41 @@ openerp.mail = function(session) {
suffix = $l.suffixFromNow;
}
}
var seconds = Math.abs(distanceMillis) / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
var days = hours / 24;
var years = days / 365;
function substitute(stringOrFunction, number) {
function convert(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)) ||
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;
var separator = $l.wordSeparator === undefined ? " " : $l.wordSeparator;
return $.trim([prefix, words, suffix].join(separator));
// compose and translate the final string
var finalString = $.trim([prefix, string, suffix].join(separator));
var translatedFinalString = _.str.sprintf(_t(finalString), value);
return translatedFinalString;
},
parse: function(iso8601) {
var s = $.trim(iso8601);