From 11bfce1a31ff326041b33ad707c52efe8c7eb983 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Fri, 11 Feb 2011 19:18:38 +0000 Subject: 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 Acked-by: Simon Schampijer --- (limited to 'src') 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. -- cgit v0.9.1