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>
This commit is contained in:
parent
b30bc0151c
commit
11bfce1a31
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user