[UI] Add gettext.ngettext to __builtin__.__dict__
Handle plurality with getttext using ngettext. Added to __builtin__.__dict__ as _n
This commit is contained in:
parent
891209d925
commit
1e183a3258
|
@ -254,7 +254,7 @@ dummy-variables-rgx=_$|dummy
|
|||
|
||||
# List of additional names supposed to be defined in builtins. Remember that
|
||||
# you should avoid to define new builtins when possible.
|
||||
additional-builtins=_,__request__
|
||||
additional-builtins=_,_n,__request__
|
||||
|
||||
# List of strings which can identify a callback function by name. A callback
|
||||
# name must start or end with one of those strings.
|
||||
|
|
|
@ -22,11 +22,12 @@ log.addHandler(logging.NullHandler()) # Silence: No handlers could be found for
|
|||
def set_dummy_trans(warn_msg=None):
|
||||
import __builtin__
|
||||
|
||||
def _func(txt):
|
||||
def _func(*txt):
|
||||
if warn_msg:
|
||||
log.warn("'%s' has been marked for translation, but translation is unavailable.", txt)
|
||||
return txt
|
||||
log.warn("'%s' has been marked for translation, but translation is unavailable.", txt[0])
|
||||
return txt[0]
|
||||
__builtin__.__dict__["_"] = _func
|
||||
__builtin__.__dict__["_n"] = _func
|
||||
|
||||
|
||||
def get_translations_path():
|
||||
|
@ -111,6 +112,8 @@ def setup_translations(setup_gettext=True, setup_pygtk=False):
|
|||
gettext.bind_textdomain_codeset(domain, 'UTF-8')
|
||||
gettext.textdomain(domain)
|
||||
gettext.install(domain, translations_path, unicode=True)
|
||||
import __builtin__
|
||||
__builtin__.__dict__["_n"] = gettext.ngettext
|
||||
except Exception as ex:
|
||||
log.error("Unable to initialize gettext/locale!")
|
||||
log.exception(ex)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
# All configuration values have a default value; values that are commented out
|
||||
# serve to show the default value.
|
||||
|
||||
import __builtin__
|
||||
import os
|
||||
import sys
|
||||
from datetime import date
|
||||
|
@ -21,6 +22,10 @@ try:
|
|||
except ImportError:
|
||||
get_version = None
|
||||
|
||||
# Must add these for autodoc to import packages successully
|
||||
__builtin__.__dict__["_"] = lambda x: x
|
||||
__builtin__.__dict__["_n"] = lambda s, p, n: s if n == 1 else p
|
||||
|
||||
# If your extensions are in another directory, add it here. If the directory
|
||||
# is relative to the documentation root, use os.path.abspath to make it
|
||||
# absolute, like shown here.
|
||||
|
|
Loading…
Reference in New Issue