This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年09月12日 12:41 by ssegvic, last changed 2022年04月11日 14:57 by admin.
| Messages (3) | |||
|---|---|---|---|
| msg143902 - (view) | Author: Sinisa Segvic (ssegvic) | Date: 2011年09月12日 12:41 | |
Hi, There appears to be some space for improvement regarding the stable implementation of the Python locale aliasing engine. Sometimes, one wishes to be able to override the default system locale. For instance, it would be nice that a program supposed to sort people according to national rules would be able to run correctly even when the system does not default to the national locale. Judging from the Python manuals and provided the desired national locale is installed, this should be doable in at least the following two ways: import locale ianaLanguageSubtag='en' # the desired national locale locale.setlocale(locale.LC_ALL, (ianaLanguageSubtag, locale.getpreferredencoding())) #(1) locale.setlocale(locale.LC_ALL, locale.normalize(ianaLanguageSubtag)) #(2) For a quicker reference, this is the relevant part of the manual: http://docs.python.org/release/3.2/library/locale.html ''' locale.setlocale(category, locale=None) ... If (the locale) is a tuple, it is converted to a string using the locale aliasing engine. ... ''' The locale aliasing engine binds the IANA language subtags to POSIX locales. Its effects can be directly observed through locale.normalize: >>> import locale >>> locale.normalize('hr') 'hr_HR.ISO8859-2' >>> locale.normalize('en') 'en_US.ISO8859-1' My first objection concerns the Windows behaviour of the calls (1) and (2) above. Both of the two calls *do not work* since Windows does not recognize strings such as 'en_US.ISO8859-1'. Instead, Windows provides their own locale nomenclature: http://msdn.microsoft.com/en-us/library/x99tb11d%28VS.80%29.aspx Consequently, the following *works*: locale.setlocale(locale.LC_ALL, 'English_United States.1252') IMHO this issue should be fixed, perhaps by providing an alternate definition of the locale alias dictionary (locale.locale_alias). My second objection concerns the behaviour on Linux, where the call (1) above always works, while (2) in some cases might not work. It happens that the call (2) requests an outdated 8-bit encoding although UTF8 has obtained a world-wide acceptance. The call shall result in a locale error whenever the desired national locale is present only in the UTF8 variant. This might be fixed by changing the encodings in the locale.locale_alias from 8-bit variants to UTF8. Note however that the problem could be circumvented by issuing the call (1), so this would be less important than the Windows fix proposed above. Source code references: .../Python-3.Lib/locale.py locale.locale_alias locale.normalize locale.setlocale comp.lang.python discussion: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3591d496cf108ad2# Cheers, Sinisa |
|||
| msg185922 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2013年04月03日 13:12 | |
From msg143902 "Both of the two calls *do not work* since Windows does not recognize strings such as 'en_US.ISO8859-1'." so how can this be an enhancement? But anyway #10466 talks about the same thing, could this be closed as a duplicate? |
|||
| msg185923 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年04月03日 13:35 | |
I believe Martin is working on a proposal that will solve the windows issue, but it may be quite some time before that happens. Yes, the windows issue is essentially a dup, but the linux issue is different. As for your question, fixing the Windows issue is definitely an enhancement, since it requires mapping (or providing, as Martin proposes) the standard locale names on Windows, which is a service that currently doesn't exist. The linux issue might be a bug...we sometimes update alias tables in maintenance release. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:21 | admin | set | github: 57173 |
| 2014年02月03日 18:35:17 | BreamoreBoy | set | nosy:
- BreamoreBoy |
| 2013年04月03日 13:35:06 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg185923 |
| 2013年04月03日 13:12:44 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages: + msg185922 |
| 2011年09月17日 15:37:59 | eric.araujo | set | type: behavior -> enhancement versions: + Python 3.3, - Python 3.2 |
| 2011年09月12日 12:46:44 | vstinner | set | nosy:
+ lemburg, vstinner |
| 2011年09月12日 12:41:26 | ssegvic | create | |