[Inteproxy-commits] r100 - in trunk: . inteproxy
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri May 18 12:58:19 CEST 2007
Author: bh
Date: 2007-05-18 12:58:18 +0200 (Fri, 18 May 2007)
New Revision: 100
Modified:
trunk/ChangeLog
trunk/inteproxy/main.py
Log:
* inteproxy/main.py (setup_language): New function to set locale
environment variables for gettext if they're not set yet.
Improves locale handling on windows.
(run_server): call setup_language
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-05-16 17:44:45 UTC (rev 99)
+++ trunk/ChangeLog 2007-05-18 10:58:18 UTC (rev 100)
@@ -1,3 +1,10 @@
+2007-05-18 Bernhard Herzog <bh at intevation.de>
+
+ * inteproxy/main.py (setup_language): New function to set locale
+ environment variables for gettext if they're not set yet.
+ Improves locale handling on windows.
+ (run_server): call setup_language
+
2007-05-16 Bernhard Herzog <bh at intevation.de>
* inteproxy/resources.py (default_config_file): New function to
Modified: trunk/inteproxy/main.py
===================================================================
--- trunk/inteproxy/main.py 2007-05-16 17:44:45 UTC (rev 99)
+++ trunk/inteproxy/main.py 2007-05-18 10:58:18 UTC (rev 100)
@@ -13,6 +13,7 @@
import optparse
import urlparse
import urllib2
+import locale
import inteproxy.proxyconnection as proxyconnection
import inteproxy.transcoder
import inteproxy.resources
@@ -95,6 +96,29 @@
elif inteproxy.resources.in_py2exe():
sys.stderr = open(os.devnull, "w")
+def setup_language():
+ """Sets the language environment if it's not set yet.
+ This function checks if any of the common language environment
+ variables is already set and if none are set, it sets LANG from the
+ default locale as determined by locale.getdefaultlocale.
+
+ This is necessary on Windows because there the locale is not usually
+ set through environment variables, but Python's gettext module uses
+ the environment variables to determine which language to use.
+ """
+ for envvar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
+ if envvar in os.environ:
+ break
+ else:
+ default_locale = locale.getdefaultlocale()
+ # The default is normally a tuple of two strings. It may
+ # contain None, objects under some circumstances, though.
+ if len(default_locale) > 1:
+ lang = default_locale[0]
+ if isinstance(lang, str):
+ os.environ["LANG"] = lang
+
+
# The main application object. It's a global variable so that worker
# threads can easily get access to it.
the_application = None
@@ -125,6 +149,8 @@
inteproxy.transcoder.transcoder_map.read_config(opts.config_file)
+ setup_language()
+
setup_logging(opts)
setup_urllib2(opts.debug_level)
More information about the Inteproxy-commits
mailing list