From 8acdff6b487db9b72f53b0633624124b549207bc Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 25 Nov 2012 17:50:22 +0200 Subject: [PATCH] Test import of pysollib.resource. --- pysollib/mygettext.py | 37 +++++++++++++++++++++++ pysollib/resource.py | 1 + scripts/gen_individual_importing_tests.py | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/pysollib/mygettext.py b/pysollib/mygettext.py index 36527112..0b51a7c5 100644 --- a/pysollib/mygettext.py +++ b/pysollib/mygettext.py @@ -1,4 +1,41 @@ #!/usr/bin/env python # -*- mode: python; coding: utf-8; -*- + +import gettext + def n_(x): return x + +def fix_gettext(): + def ugettext(message): + # unicoded gettext + if not isinstance(message, unicode): + message = unicode(message, 'utf-8') + domain = gettext._current_domain + try: + t = gettext.translation(domain, + gettext._localedirs.get(domain, None)) + except IOError: + return message + return t.ugettext(message) + gettext.ugettext = ugettext + def ungettext(msgid1, msgid2, n): + # unicoded ngettext + if not isinstance(msgid1, unicode): + msgid1 = unicode(msgid1, 'utf-8') + if not isinstance(msgid2, unicode): + msgid2 = unicode(msgid2, 'utf-8') + domain = gettext._current_domain + try: + t = gettext.translation(domain, + gettext._localedirs.get(domain, None)) + except IOError: + if n == 1: + return msgid1 + else: + return msgid2 + return t.ungettext(msgid1, msgid2, n) + gettext.ungettext = ungettext + +fix_gettext() +_ = gettext.ugettext diff --git a/pysollib/resource.py b/pysollib/resource.py index b3cabdce..5eda1ae2 100644 --- a/pysollib/resource.py +++ b/pysollib/resource.py @@ -29,6 +29,7 @@ import os, glob, traceback from pysollib.mfxutil import Struct, KwStruct from pysollib.settings import DEBUG +from pysollib.mygettext import _ # ************************************************************************ # * Abstract diff --git a/scripts/gen_individual_importing_tests.py b/scripts/gen_individual_importing_tests.py index 1fa2ef3f..e0f9a2e6 100644 --- a/scripts/gen_individual_importing_tests.py +++ b/scripts/gen_individual_importing_tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import os.path -for module_name in ['pysollib.mfxutil', 'pysollib.move', 'pysollib.settings', 'pysollib.mygettext', 'pysollib.wizardpresets',]: +for module_name in ['pysollib.mfxutil', 'pysollib.move', 'pysollib.resource', 'pysollib.settings', 'pysollib.mygettext', 'pysollib.wizardpresets',]: open(os.path.join(".", "tests", "individually-importing", "import_" + module_name + ".py"), 'w').write('''#!/usr/bin/env python import sys sys.path.append("./tests/lib")