add plural context to TransUtils.py
svn: r11772
This commit is contained in:
parent
0d3201d8ab
commit
3d257ea84a
@ -24,7 +24,7 @@
|
|||||||
Provide translation assistance
|
Provide translation assistance
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from gettext import gettext
|
from gettext import (gettext, ngettext)
|
||||||
|
|
||||||
def sgettext(msgid, sep='|'):
|
def sgettext(msgid, sep='|'):
|
||||||
"""
|
"""
|
||||||
@ -48,3 +48,31 @@ def sgettext(msgid, sep='|'):
|
|||||||
sep_idx = msgid.rfind(sep)
|
sep_idx = msgid.rfind(sep)
|
||||||
msgval = msgid[sep_idx+1:]
|
msgval = msgid[sep_idx+1:]
|
||||||
return msgval
|
return msgval
|
||||||
|
|
||||||
|
def sngettext(singular, plural, n, sep='|'):
|
||||||
|
"""
|
||||||
|
Strip the context used for resolving translation ambiguities.
|
||||||
|
|
||||||
|
The translation of singular/plural is returned unless the translation is
|
||||||
|
not available and the singular contains the separator. In that case,
|
||||||
|
the returned value is the portion of singular following the last
|
||||||
|
separator. Default separator is '|'.
|
||||||
|
|
||||||
|
@param singular: The singular form of the string to be translated.
|
||||||
|
may contain a context seperator
|
||||||
|
@type singular: unicode
|
||||||
|
@param plural: The plural form of the string to be translated.
|
||||||
|
@type plural: unicode
|
||||||
|
@param n: the amount for which to decide the translation
|
||||||
|
@type n: int
|
||||||
|
@param sep: The separator marking the context.
|
||||||
|
@type sep: unicode
|
||||||
|
@return: Translation or the original with context stripped.
|
||||||
|
@rtype: unicode
|
||||||
|
|
||||||
|
"""
|
||||||
|
msgval = ngettext(singular, plural,n)
|
||||||
|
if msgval == singular:
|
||||||
|
sep_idx = singular.rfind(sep)
|
||||||
|
msgval = singular[sep_idx+1:]
|
||||||
|
return msgval
|
||||||
|
Loading…
Reference in New Issue
Block a user