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