[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r6340 - trunk/gnue-common/src/apps
From: |
johannes |
Subject: |
r6340 - trunk/gnue-common/src/apps |
Date: |
Mon, 20 Sep 2004 13:56:29 -0500 (CDT) |
Author: johannes
Date: 2004-09-20 13:56:28 -0500 (Mon, 20 Sep 2004)
New Revision: 6340
Modified:
trunk/gnue-common/src/apps/i18n.py
Log:
Better handling of language and encoding. should work well on win32 too
Modified: trunk/gnue-common/src/apps/i18n.py
===================================================================
--- trunk/gnue-common/src/apps/i18n.py 2004-09-20 16:06:48 UTC (rev 6339)
+++ trunk/gnue-common/src/apps/i18n.py 2004-09-20 18:56:28 UTC (rev 6340)
@@ -40,26 +40,13 @@
__modules = {} # Modules by filename
__catalogs = {} # Message catalogs by domain
+__userlangue = None
language = None
encoding = None
enc_policy = "replace" # policy to use if an unicode character
-# The ENC_MAP dictionary defines a mapping between an encoding retrieved from
-# the locale module and the encoding used by the unicode () function.
-ENC_MAP = {
- '1250': 'cp1250',
- '1251': 'cp1251',
- '1252': 'cp1252',
- '1253': 'cp1253',
- '1254': 'cp1254',
- '1255': 'cp1255',
- '1256': 'cp1256',
- '1257': 'cp1257',
- '1258': 'cp1258',
-}
-
# -----------------------------------------------------------------------------
# Find a module from filename
# -----------------------------------------------------------------------------
@@ -170,11 +157,10 @@
This function returns the encoding of the currently active locale
@returns: encoding of the current locale
"""
- enc = locale.getlocale () [1]
- if ENC_MAP.has_key (enc):
- return ENC_MAP [enc]
+ if sys.platform == 'win32':
+ return locale.getdefaultlocale () [1] or 'ascii'
else:
- return enc or 'ascii'
+ return locale.getlocale () [1] or 'ascii'
# -----------------------------------------------------------------------------
@@ -185,8 +171,8 @@
"""
This function return the language of the currently acitve locale
@returns: language of the current locale
- """
- return locale.getlocale () [0] or 'C'
+ """
+ return __userlanguage or 'C'
# ---------------------------------------------------------------------------
@@ -201,7 +187,8 @@
items = ['LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG']
for key in items:
if os.environ.has_key (key):
- return os.environ [key]
+ envLang = os.environ [key]
+ return locale.locale_alias.get (envLang, envLang)
try:
result = locale.getdefaultlocale () [0]
@@ -227,16 +214,25 @@
if newLocale is None:
newLocale = ''
+ parts = []
+ add = []
normal = locale.normalize (newLocale)
next = normal.split ('@') [0]
- noenc = next.split ('.') [0]
- alias = locale.locale_alias.get (string.lower (noenc.split ('_') [0]))
+ __userlanguage = next.split ('.') [0]
- parts = [normal]
- for item in [next, noenc, alias]:
+ if sys.platform == 'win32':
+ return
+
+ alias = locale.locale_alias.get (__userlanguage.split ('_') [0].lower ())
+ if alias:
+ add = [alias.split ('@') [0]]
+ add.append (add [-1].split ('.') [0])
+ add.append (locale.locale_alias.get (add [-1].split ('_') [0].lower ()))
+
+ for item in [normal, next, __userlanguage] + add:
if item is not None and item not in parts:
parts.append (item)
-
+
for item in parts:
try:
locale.setlocale (locale.LC_ALL, item)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r6340 - trunk/gnue-common/src/apps,
johannes <=