Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSascha Silbe <silbe@activitycentral.com>2011-02-11 19:18:38 (GMT)
committer Sascha Silbe <silbe@activitycentral.com>2011-02-15 21:44:57 (GMT)
commit11bfce1a31ff326041b33ad707c52efe8c7eb983 (patch)
tree0b70dc5d85edfbfd12be248f8c2629451912a8a6 /src
parentb30bc0151c357f0e60eb92c934daa56ca28d2df0 (diff)
sugar.activity.i18n: add pgettext()
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@activitycentral.com> Acked-by: Simon Schampijer <simon@laptop.org>
Diffstat (limited to 'src')
-rw-r--r--src/sugar/activity/i18n.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/sugar/activity/i18n.py b/src/sugar/activity/i18n.py
index 7b09fc2..1ddbd79 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,23 @@ def _extract_modification_time(file_path):
raise ValueError('Could not find a revision date')
+# We ship our own version of pgettext() because Python 2.x will never contain
+# it: http://bugs.python.org/issue2504#msg122482
+def pgettext(context, message):
+ """
+ Return the localized translation of message, based on context and
+ the current global domain, language, and locale directory.
+
+ Similar to gettext(). Context is a string used to disambiguate
+ messages that are the same in the source language (usually english),
+ but might be different in one or more of the target languages.
+ """
+ translation = gettext('\x04'.join([context, message]))
+ if '\x04' in translation:
+ return message
+ return translation
+
+
def get_locale_path(bundle_id):
""" Returns the locale path, which is the directory where the preferred
MO file is located.