[Sugar-devel] [PATCH sugar-toolkit] sugar.activity.i18n: add pgettext()

Sascha Silbe silbe at activitycentral.com
Fri Feb 11 14:22:51 EST 2011


Python 2 will never have pgettext() [1], so we need to ship our own version.
sugar.activity.i18n is the best place for that.

[1] http://bugs.python.org/issue2504#msg122482

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
 src/sugar/activity/i18n.py |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/sugar/activity/i18n.py b/src/sugar/activity/i18n.py
index 7b09fc2..7e5ad51 100644
--- a/src/sugar/activity/i18n.py
+++ b/src/sugar/activity/i18n.py
@@ -19,6 +19,7 @@
 
 import gconf
 
+from gettext import gettext
 import locale
 import os
 import struct
@@ -94,6 +95,13 @@ def _extract_modification_time(file_path):
     raise ValueError('Could not find a revision date')
 
 
+def pgettext(context, msgid):
+    translation = gettext('\x04'.join([context, msgid]))
+    if '\x04' in translation:
+        return msgid
+    return translation
+
+
 def get_locale_path(bundle_id):
     """ Returns the locale path, which is the directory where the preferred
         MO file is located.
-- 
1.7.2.3



More information about the Sugar-devel mailing list