[Python-bugs-list] [ python-Bugs-554676 ] unknown locale de_DE@euro on Suse 8.0 Linux

noreply@sourceforge.net noreply@sourceforge.net
Mon, 08 Jul 2002 01:55:59 -0700


Bugs item #554676, was opened at 2002-05-10 23:02
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=554676&group_id=5470

Category: Python Library
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: vincent wehren (vinweh)
Assigned to: Nobody/Anonymous (nobody)
Summary: unknown locale de_DE@euro on Suse 8.0 Linux

Initial Comment:
Python 2.2 (#1, Mar 26 2002, 15:46:04)   
[GCC 2.95.3 20010315 (SuSE)] on linux2   
 
When calling the locale module's getdefaultlocale() 
method on SuSe 8.0 Linux you get:   
 
>>> locale.getdefaultlocale()   
Traceback (most recent call last):   
  File "<stdin>", line 1, in ?   
  File "/usr/lib/python2.2/locale.py", line 337, in   
getdefaultlocale   
    return _parse_localename(localename)   
  File "/usr/lib/python2.2/locale.py", line 271, in   
_parse_localename   
    raise ValueError, 'unknown locale: %s' %   
localename   
ValueError: unknown locale: de_DE@euro   
  
Evidently, Python2.2's locale module is unaware of 
the "somelang_SOMELANG@euro" nomenclature  
for euro-enabled locales on Linux.  
  
 

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-07-08 10:55

Message:
Logged In: YES 
user_id=21627

I see. For that, you should not use getdefaultlocale. The
reason is that getdefaultlocale cannot possibly determine
the locale's encoding correctly. Instead, you should use
locale.nl_langinfo where available (invoking setlocale
beforehand).

The fix you are reporting as 'easy' is a hack rather than a
solution: there is no guarantee whatsoever that the encoding
in a @euro locale will be Latin-9; it could just as well be,
say, UTF-8. Likewise, there might be other locales with
implied encodings.

----------------------------------------------------------------------

Comment By: Chema Cortés (chemacortes)
Date: 2002-07-06 03:11

Message:
Logged In: YES 
user_id=78289

We, as non-english writers, need 'getdefaultlocale' to set the default encoding for 
unicode strings: 
 
lang,encoding=locale.getdefaultlocale() 
sys.setdefaultencoding(encoding) 
 
The problem can be fixed easyly by insert the new locales into the locale_alias of 
module locale: 
 
locale_alias={ 
... 
  "de_de@euro": "de_DE.iso8859_15", 
  "de_at@euro": "de_AT@iso8859_15", 
  "es_es@euro":"es_ES@iso8859_15", 
... 
} 
 
As a workarround, you can modify the locale_alias into the sitecustomize.py 
 
# adding euro locales 
import locale 
eurolocs=[ "ca_ES", "da_DK", "de_AT", "de_BE", "de_DE", "de_LU", "en_BE", 
           "en_IE", "es_ES", "eu_ES", "fi_FI", "fr_BE", "fr_FR", "fr_LU", 
           "ga_IE", "gl_ES", "it_IT", "nl_BE", "nl_NL", "pt_PT", "sv_FI" 
] 
 
for l in eurolocs: 
   key=l.lower()+"@euro"          # eg: "es_es@euro" 
   cod=l+".iso8859_15"            # eg: "es_ES.iso8859_15" 
   locale.locale_alias[key]=cod 
 
# Setting the unicode default encoding 
import sys 
if hasattr(sys,"setdefaultencoding"): 
  lang,encoding=locale.getdefaultlocale() 
  sys.setdefaultencoding(encoding) 
 

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-06-09 11:10

Message:
Logged In: YES 
user_id=21627

Can you please explain what you need getdefaultlocale for?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=554676&group_id=5470