diff --git a/linkcheck/__init__.py b/linkcheck/__init__.py index d655a767..33519647 100644 --- a/linkcheck/__init__.py +++ b/linkcheck/__init__.py @@ -132,7 +132,7 @@ def get_link_pat (arg, strict=False): } -def init_i18n (): +def init_i18n (loc=None): """Initialize i18n with the configured locale dir. The environment variable LOCPATH can also specify a locale dir. @@ -142,7 +142,7 @@ def init_i18n (): locdir = os.environ['LOCPATH'] else: locdir = os.path.join(get_install_data(), 'share', 'locale') - i18n.init(configdata.name.lower(), locdir) + i18n.init(configdata.name.lower(), locdir, loc=loc) # install translated log level names import logging logging.addLevelName(logging.CRITICAL, _('CRITICAL')) diff --git a/linkcheck/i18n.py b/linkcheck/i18n.py index 5f53f209..3d448b98 100644 --- a/linkcheck/i18n.py +++ b/linkcheck/i18n.py @@ -59,7 +59,7 @@ class NullTranslator (gettext.NullTranslations): install_builtin(self, do_unicode) -def init (domain, directory): +def init (domain, directory, loc=None): """Initialize this gettext i18n module. Searches for supported languages and installs the gettext translator class.""" global default_language, default_encoding @@ -70,7 +70,10 @@ def init (domain, directory): mo_file = os.path.join(path, '%s.mo' % domain) if os.path.exists(mo_file): supported_languages.add(lang) - loc, encoding = get_locale() + if loc is None: + loc, encoding = get_locale() + else: + encoding = get_locale()[1] if loc in supported_languages: default_language = loc else: diff --git a/tests/checker/__init__.py b/tests/checker/__init__.py index f82b78f9..01a61e4f 100644 --- a/tests/checker/__init__.py +++ b/tests/checker/__init__.py @@ -26,7 +26,6 @@ import linkcheck.checker import linkcheck.configuration import linkcheck.director import linkcheck.logger -import linkcheck.i18n from .. import get_file # helper alias @@ -141,10 +140,14 @@ class LinkCheckTest (unittest.TestCase): Functional test class with ability to test local files. """ + def setUp (self): + """Ensure the current locale setting is the default. + Otherwise, warnings will get translated and will break tests.""" + super(LinkCheckTest, self).setUp() + linkcheck.init_i18n(loc='C') + def norm (self, url, encoding=None): - """ - Helper function to norm a url. - """ + """Helper function to norm a url.""" return linkcheck.url.url_norm(url, encoding=encoding)[0] def get_attrs (self, **kwargs):