diff --git a/src/sugar/activity/i18n.py b/src/sugar/activity/i18n.py index 7b09fc25..1ddbd79e 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.