Ticket #2354: 0001-Do-not-break-if-the-string-contains-no-conversion-sp.patch

File 0001-Do-not-break-if-the-string-contains-no-conversion-sp.patch, 1.6 KB (added by erikos, 14 years ago)

Patch to make Marco and Tomeu happy

  • src/sugar/util.py

    From 106b9fba686081bfa8c4d9b9d9d5fe78fa75dc1f Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@schampijer.de>
    Date: Wed, 29 Sep 2010 16:15:59 +0200
    Subject: [PATCH] Do not break if the string contains no conversion specifier #2354
    
    ---
     src/sugar/util.py |   15 +++++++++++----
     1 files changed, 11 insertions(+), 4 deletions(-)
    
    diff --git a/src/sugar/util.py b/src/sugar/util.py
    index b947c0a..3625f21 100644
    a b def timestamp_to_elapsed_string(timestamp, max_levels=2): 
    271271            if key in _i18n_timestamps_cache:
    272272                time_period += _i18n_timestamps_cache[key]
    273273            else:
    274                 translation = gettext.dngettext('sugar-toolkit',
    275                                                 name_singular,
    276                                                 name_plural,
    277                                                 elapsed_units) % elapsed_units
     274                tmp = gettext.dngettext('sugar-toolkit',
     275                                        name_singular,
     276                                        name_plural,
     277                                        elapsed_units)
     278                # FIXME: This is a hack so we don't crash when a translation
     279                # doesn't contain the expected number of placeholders (#2354)
     280                try:
     281                    translation = tmp % elapsed_units
     282                except TypeError:
     283                    translation = tmp
     284
    278285                _i18n_timestamps_cache[key] = translation
    279286                time_period += translation
    280287