From 1e183a32587d04e5e4abb2857f93d9f0a67b5450 Mon Sep 17 00:00:00 2001 From: bendikro Date: Sun, 17 Jan 2016 17:13:45 +0100 Subject: [PATCH] [UI] Add gettext.ngettext to __builtin__.__dict__ Handle plurality with getttext using ngettext. Added to __builtin__.__dict__ as _n --- .pylintrc | 2 +- deluge/ui/util/lang.py | 9 ++++++--- docs/source/conf.py | 5 +++++ tox.ini | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc index 05cb9439b..68f20c42e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -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. diff --git a/deluge/ui/util/lang.py b/deluge/ui/util/lang.py index 0c2bfccaa..f7439d172 100644 --- a/deluge/ui/util/lang.py +++ b/deluge/ui/util/lang.py @@ -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) diff --git a/docs/source/conf.py b/docs/source/conf.py index e5e140ffa..2b9aae06f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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. diff --git a/tox.ini b/tox.ini index 3ff0bb2b7..a15d9cbb8 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ [flake8] max-line-length = 120 -builtins = _,__request__ +builtins = _,_n,__request__ exclude = .git,.tox,dist,build [pep8]