Ticket #3524: 0001-Units-apply-l10n-SL-3524.patch

File 0001-Units-apply-l10n-SL-3524.patch, 2.6 KB (added by humitos, 12 years ago)
  • smoot_toolbar.py

    From 150f5b84836a2c4e4e3c7c1f69a60b69434fc892 Mon Sep 17 00:00:00 2001
    Message-Id: <150f5b84836a2c4e4e3c7c1f69a60b69434fc892.1337098744.git.humitos@gmail.com>
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Tue, 15 May 2012 13:18:57 -0300
    Subject: [PATCH Distance] Units apply l10n SL #3524
    
    When the string is not going to be used when it's declarated we should
    do a workaround[1] to use the translated version later.
    
    [1] http://docs.python.org/library/gettext.html#deferred-translations
    
    Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
    ---
     smoot_toolbar.py |   17 +++++++++++++----
     1 file changed, 13 insertions(+), 4 deletions(-)
    
    diff --git a/smoot_toolbar.py b/smoot_toolbar.py
    index 334fd76..f0a49d6 100644
    a b  
    1616# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1717
    1818import gtk
    19 from gettext import gettext as _
    2019
    2120from sugar.graphics.combobox import ComboBox
    2221from sugar.graphics.toolcombobox import ToolComboBox
    INCHES = 2 
    2726FEET = 3
    2827YARDS = 4
    2928CUSTOM = 5
     29
     30
     31# This is a workaround to fix SL #3524
     32# Documentation:
     33# http://docs.python.org/library/gettext.html#deferred-translations
     34def _(message):
     35    return message
     36
    3037UNITS = [_('meters'), _('centimeters'),
    3138         # TRANS: English units of measure
    3239         _('inches'), _('feet'), _('yards'),
    UNIT_DICTIONARY = {METERS: (_('meters'), 1.0), 
    3744                   FEET: (_('feet'), 3.28),
    3845                   YARDS: (_('yards'), 1.09),
    3946                   CUSTOM: (_('custom units'), None)}
     47del _
     48from gettext import gettext as _
    4049
    4150
    4251def _label_factory(label, toolbar):
    def _combo_factory(combo_array, default, tooltip, toolbar): 
    5867        my_combo.set_tooltip_text(tooltip)
    5968
    6069    for i, s in enumerate(combo_array):
    61         my_combo.append_item(i, s, None)
     70        my_combo.append_item(i, _(s), None)
    6271
    6372    toolbar.insert(ToolComboBox(my_combo), -1)
    6473
    class SmootToolbar(gtk.Toolbar): 
    96105        self._unit_name = name
    97106        if hasattr(self._parent, 'fr'):
    98107            self._parent.fr.set_label(
    99                 _('Measured distance in %s') % (self._unit_name))
     108                _('Measured distance in %s') % _(self._unit_name))
    100109        if name == _('meters'):
    101110            self._factor_label.set_label(' ')
    102111        else:
    103112            self._factor_label.set_label(_('%(unit)20.2f %(name)s per meter') %
    104                     {'unit': self._unit_scale, 'name': name})
     113                    {'unit': self._unit_scale, 'name': _(name)})
    105114
    106115    def get_scale(self):
    107116        return self._unit_scale