[Sugar-devel] [PATCH Distance] Units apply l10n SL #3524
Manuel Kaufmann
humitos at gmail.com
Tue May 15 12:20:56 EDT 2012
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 at 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/smoot_toolbar.py
+++ b/smoot_toolbar.py
@@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import gtk
-from gettext import gettext as _
from sugar.graphics.combobox import ComboBox
from sugar.graphics.toolcombobox import ToolComboBox
@@ -27,6 +26,14 @@ INCHES = 2
FEET = 3
YARDS = 4
CUSTOM = 5
+
+
+# This is a workaround to fix SL #3524
+# Documentation:
+# http://docs.python.org/library/gettext.html#deferred-translations
+def _(message):
+ return message
+
UNITS = [_('meters'), _('centimeters'),
# TRANS: English units of measure
_('inches'), _('feet'), _('yards'),
@@ -37,6 +44,8 @@ UNIT_DICTIONARY = {METERS: (_('meters'), 1.0),
FEET: (_('feet'), 3.28),
YARDS: (_('yards'), 1.09),
CUSTOM: (_('custom units'), None)}
+del _
+from gettext import gettext as _
def _label_factory(label, toolbar):
@@ -58,7 +67,7 @@ def _combo_factory(combo_array, default, tooltip, toolbar):
my_combo.set_tooltip_text(tooltip)
for i, s in enumerate(combo_array):
- my_combo.append_item(i, s, None)
+ my_combo.append_item(i, _(s), None)
toolbar.insert(ToolComboBox(my_combo), -1)
@@ -96,12 +105,12 @@ class SmootToolbar(gtk.Toolbar):
self._unit_name = name
if hasattr(self._parent, 'fr'):
self._parent.fr.set_label(
- _('Measured distance in %s') % (self._unit_name))
+ _('Measured distance in %s') % _(self._unit_name))
if name == _('meters'):
self._factor_label.set_label(' ')
else:
self._factor_label.set_label(_('%(unit)20.2f %(name)s per meter') %
- {'unit': self._unit_scale, 'name': name})
+ {'unit': self._unit_scale, 'name': _(name)})
def get_scale(self):
return self._unit_scale
--
1.7.10
More information about the Sugar-devel
mailing list