summaryrefslogtreecommitdiff
path: root/odoo/tools/translate.py
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2019-08-19 11:31:24 +0000
committerDavid Beguin <dbe@odoo.com>2019-08-20 08:02:46 +0000
commitc5500e685aeeb2a0b6dbedc2edc7be5647bf05d7 (patch)
tree8e5c0b0eeb7462b16b0d70d07414318cedccbb9c /odoo/tools/translate.py
parentb4ef0299db0e1ba5073cebd99abf6720c142671d (diff)
[FIX] tools : use babel to format timedelta
Babel is already taking the language into account while formating a time delta into a readable string like '2 minutes ago'. _format_time_ago was put in translate.py file to be able to use the _ translate class. But it can be placed in misc like other format function already using babel. This fix the PR #34624 and is linked to Task ID : 2028059 Task ID: 2055847 Closes PR #35806 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'odoo/tools/translate.py')
-rw-r--r--odoo/tools/translate.py33
1 files changed, 0 insertions, 33 deletions
diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py
index 4d7392bd25f..1577fa2bb48 100644
--- a/odoo/tools/translate.py
+++ b/odoo/tools/translate.py
@@ -1151,36 +1151,3 @@ def load_language(cr, lang):
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
installer = env['base.language.install'].create({'lang': lang})
installer.lang_install()
-
-def _format_time_ago(env, time):
- # Set Context to be used by translate _get_Lang (by introspection)
- # DO NOT REMOVE THIS context VARIABLE
- context = env.context
- seconds = time.total_seconds()
- days = round(seconds / (60 * 60 * 24))
-
- if not days:
- if seconds < 10:
- return _("just now")
- if seconds / 60 < 1:
- return _("%s seconds ago") % round(seconds)
- if seconds < 120:
- return _("a minute ago")
- if seconds / 3600 < 1:
- return _("%s minutes ago") % round(seconds / 60)
- if seconds < 7200:
- return _("an hour ago")
- return _("%s hours ago") % round(seconds / (60*60))
- else:
- if days == 1:
- return _("yesterday")
- if days < 7:
- return _("%s days ago") % days
- if days < 31:
- nbr_weeks = round(days / 7)
- return _("%s week%s ago") % (nbr_weeks, '' if nbr_weeks == 1 else 's')
- if days < 365:
- nbr_months = round(days / 30)
- return _("%s month%s ago") % (nbr_months, '' if nbr_months == 1 else 's')
- nbr_years = round(days / 365)
- return _("%s year%s ago") % (nbr_years, '' if nbr_years == 1 else 's')