From 438232f6bef8e0b2d1a089dddf0c91685e1da001 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 10 Jan 2011 16:19:12 +0100 Subject: [PATCH] [FIX] res_lang: sanitize time_format for python's strftime POSIX's strftime has a number of 'compound' formats for quick-formatting of time spans (e.g. %T for %H:%M:%S) which Python's own strftime does not support => error when trying to use them manually expand those compound formats to their atoms refs: http://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html http://docs.python.org/library/time.html#time.strftime lp bug: https://launchpad.net/bugs/698134 fixed lp bug: https://launchpad.net/bugs/697833 fixed bzr revid: odo@openerp.com-20110110151912-ysu06271z40hxxho --- bin/addons/base/res/res_lang.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/addons/base/res/res_lang.py b/bin/addons/base/res/res_lang.py index abaa81ed357..d19e9389884 100644 --- a/bin/addons/base/res/res_lang.py +++ b/bin/addons/base/res/res_lang.py @@ -66,17 +66,29 @@ class lang(osv.osv): def fix_xa0(s): + """Fix badly-encoded non-breaking space Unicode character from locale.localeconv(), + coercing to utf-8, as some platform seem to output localeconv() in their system + encoding, e.g. Windows-1252""" if s == '\xa0': return '\xc2\xa0' return s + def fix_time_format(format): + """Python's strftime does not support all the compound formats + from C's strftime, as returned by locale.nl_langinfo(). + Under Ubuntu at least, we encounter %T or %r for some locales.""" + format = format.replace('%T', '%H:%M:%S')\ + .replace('%r', '%I:%M:%S %p')\ + .replace('%R', '%H:%M') + return str(format) + lang_info = { 'code': lang, 'iso_code': iso_lang, 'name': lang_name, 'translatable': 1, 'date_format' : str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')), - 'time_format' : str(locale.nl_langinfo(locale.T_FMT)), + 'time_format' : fix_time_format(locale.nl_langinfo(locale.T_FMT)), 'decimal_point' : fix_xa0(str(locale.localeconv()['decimal_point'])), 'thousands_sep' : fix_xa0(str(locale.localeconv()['thousands_sep'])), }