commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r6976 - trunk/gnue-common/src/apps


From: reinhard
Subject: [gnue] r6976 - trunk/gnue-common/src/apps
Date: Tue, 8 Feb 2005 06:54:15 -0600 (CST)

Author: reinhard
Date: 2005-02-08 06:54:14 -0600 (Tue, 08 Feb 2005)
New Revision: 6976

Modified:
   trunk/gnue-common/src/apps/i18n.py
Log:
Try to fix all those locale issues.


Modified: trunk/gnue-common/src/apps/i18n.py
===================================================================
--- trunk/gnue-common/src/apps/i18n.py  2005-02-07 21:20:45 UTC (rev 6975)
+++ trunk/gnue-common/src/apps/i18n.py  2005-02-08 12:54:14 UTC (rev 6976)
@@ -157,6 +157,10 @@
   This function returns the encoding of the currently active locale
   @returns: encoding of the current locale
   """
+  # For Windows, getlocale () is broken - it returns e.g. ('Hungarian_Hungary',
+  # '1250') instead of ('hu_HU', 'cp1250'). So we have to use getdefaultlocale.
+  # However, this means that under Windows, no locales but the default locale
+  # can be used.
   if sys.platform == 'win32':
     return locale.getdefaultlocale () [1] or 'ascii'
   else:
@@ -184,15 +188,22 @@
   This function tries to find out which locale the user is using.
   @returns: localestring of the user's locale, i.e. address@hidden
   """
+
+  # *Actually* the following is very much what locale.getdefaultlocale should
+  # do anyway.  However, that function is broken for $LANGUAGE containing a
+  # list of locales, separated with ":". So we have to manually rebuild it...
   items = ['LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG']
   for key in items:
     if os.environ.has_key (key):
-      envLang = os.environ [key]
+      # Some systems (most notably Debian...) set $LANGUAGE to a *list* of
+      # locales, separated by a ":".
+      envLang = (os.environ [key]).split (':') [0]
       return locale.locale_alias.get (envLang, envLang)
 
+  # Now this should only happen on Windows, where getdefaultlocale seems to
+  # work ok.
   try:
     result = locale.getdefaultlocale () [0]
-
   except locale.Error:
     result = ''
 
@@ -220,6 +231,7 @@
   next   = normal.split ('@') [0]
   __userlanguage = next.split ('.') [0]
 
+  # Setting a locale different than the current locale doesn't work on Windows.
   if sys.platform == 'win32':
     return
 
@@ -254,8 +266,13 @@
 except:
   pass
 
-# This will give us the user's language and encoding even on non-POSIX systems
-(language, encoding) = locale.getdefaultlocale ()
+# On win32, getlocale is broken - it returns Hungarian_Hungary instead of
+# hu_HU. On the other hand, getdefaultlocale is broken when $LANGUAGE contains
+# a ":" separated list of locales, like it does for Debian...
+if sys.platform == 'win32':
+  (language, encoding) = locale.getdefaultlocale ()
+else:
+  (language, encoding) = locale.getlocale ()
 
 # Make sure encoding is not None
 if not encoding:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]