From 18c6e6e38aecebbf1a2d222fb9f3d79cbd09e7fe Mon Sep 17 00:00:00 2001 From: calvin Date: Mon, 21 Apr 2008 01:28:47 +0000 Subject: [PATCH] Set default_encoding on i18n init git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3707 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- linkcheck/i18n.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linkcheck/i18n.py b/linkcheck/i18n.py index fef9d276..e56445dc 100644 --- a/linkcheck/i18n.py +++ b/linkcheck/i18n.py @@ -77,16 +77,17 @@ def init (domain, directory): Initialize this gettext i18n module. Searches for supported languages and installs the gettext translator class. """ - global default_language + global default_language, default_encoding if os.path.isdir(directory): # get supported languages for lang in os.listdir(directory): path = os.path.join(directory, lang, 'LC_MESSAGES') if os.path.exists(os.path.join(path, '%s.mo' % domain)): supported_languages.add(lang) - loc = get_locale() + loc, encoding = get_locale() if loc in supported_languages: default_language = loc + default_encoding = encoding # install translation service routines into default namespace translator = get_translator(domain, directory, languages=[default_language], fallback=True) @@ -148,14 +149,15 @@ def get_locale (): Return current configured locale. """ loc = None + encoding = 'ascii' try: - loc = locale.getlocale(category=locale.LC_MESSAGES)[0] + loc, encoding = locale.getlocale(category=locale.LC_MESSAGES) except ValueError: # XXX ignore Python bug # http://bugs.python.org/issue1158909 pass if loc is None: - return 'C' + return ('C', 'ascii') loc = locale.normalize(loc) # split up the locale into its base components pos = loc.find('@') @@ -167,7 +169,7 @@ def get_locale (): pos = loc.find('_') if pos >= 0: loc = loc[:pos] - return loc + return (loc, encoding) lang_names = {