Refactored the Q_ translation function

This commit is contained in:
Alexander Cherniuk 2010-04-07 04:09:58 +03:00
parent d5a6a4d53d
commit cf0bc0b478
1 changed files with 19 additions and 14 deletions

View File

@ -67,20 +67,25 @@ if gettext._translations:
else:
_translation = gettext.NullTranslations()
def Q_(s):
# Qualified translatable strings
# Some strings are too ambiguous to be easily translated.
# so we must use as:
# s = Q_('?vcard:Unknown')
# widget.set_text(s)
# Q_() removes the ?vcard:
# but gettext while parsing the file detects ?vcard:Unknown as a whole string.
# translator can either put the ?vcard: part or no (easier for him or her to no)
# nothing fails
s = _(s)
if s[0] == '?':
s = s[s.find(':')+1:] # remove ?abc: part
return s
def Q_(text):
"""
Translate the given text, optionally qualified with a special
construction, which will help translators to disambiguate between
same terms, but in different contexts.
When translated text is returned - this rudimentary construction
will be stripped off, if it's present.
Here is the construction to use:
Q_("?vcard:Unknown")
Everything between ? and : - is the qualifier to convey the context
to the translators. Everything after : - is the text itself.
"""
text = _(text)
if text.startswith('?'):
qualifier, text = text.split(':', 1)
return text
def ngettext(s_sing, s_plural, n, replace_sing = None, replace_plural = None):
"""