Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2.7': 0.04; '3.2': 0.05; 'instance,': 0.05; 'versions,': 0.05; 'defines': 0.07; 'python': 0.08; 'locale': 0.09; 'error:': 0.12; 'setlocale': 0.16; 'subject:usage': 0.16; 'win7': 0.16; 'windows:': 0.16; 'linux': 0.17; 'cheers,': 0.18; '>>>': 0.18; 'idea?': 0.18; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'dictionary': 0.23; 'noticed': 0.24; 'skip:l 30': 0.24; 'traceback': 0.24; 'code': 0.25; 'string': 0.26; 'windows': 0.26; 'received:209.85.220': 0.27; 'url:mailman': 0.28; 'import': 0.28; 'bound': 0.29; 'module.': 0.29; 'message- id:@mail.gmail.com': 0.29; 'skip:( 20': 0.29; "skip:' 10": 0.30; 'hi,': 0.32; 'does': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; 'url:listinfo': 0.33; 'however,': 0.34; 'setting': 0.34; 'keys': 0.34; 'last):': 0.34; 'like:': 0.34; 'anything': 0.36; 'file': 0.36; 'url:python': 0.36; 'skip:" 10': 0.36; 'using': 0.37; 'but': 0.37; 'something': 0.37; 'not,': 0.38; 'could': 0.38; 'some': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'ways': 0.39; 'to:addr:python.org': 0.39; 'results': 0.61; 'dealing': 0.69; 'url:hr': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=0mK89RipUK/wMyDh2TmKs+zhCXptRsq+u/snVI6X1Tk=; b=Zz6D7hRNVLZu+uIT9j7sIuEzyaahDNhW+yE1LXJ7ffXTgWAAn5ZbxNpV/ilLdseXk5 IDYd60DjYFPdNKE/SoR3782Mf+e83f4WPH7VgSXdj4wOPUXbAxI/c2ZqjlO3cGNz06cf ftW+DKDFEDVZBtn2uCJ3B2ToFBZNIB0W1SuvA= MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 6 Sep 2011 15:13:17 +0200 Subject: Re: Portable locale usage From: Vlastimil Brom To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315314806 news.xs4all.nl 2484 [2001:888:2000:d::a6]:58779 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12833 2011/9/6 ssegvic : > Hi, > > I am musing on how to write portable Python3 code which would > take advantage of the standard locale module. > > For instance, it would be very nice if we could say something like: > > # does not work! > myISOCountryCode=3D'hr' > locale.setlocale(locale.LC_ALL, (myISOCountryCode, > locale.getpreferredencoding())) > > Up to now, I have found ways to set locale on Linux and Windows: > > import locale > locale.setlocale(locale.LC_ALL, 'hr_HR.utf8') =A0 =A0 =A0# works on linux > locale.setlocale(locale.LC_ALL, 'hrv_HRV.1250') # works on windows > > I have noticed that locale defines a dictionary locale.locale_alias, > and that it contains the following promising keys: 'hr_hr', > 'hrvatski', 'hr'. > Unfortunately, both on Windows and Linux all these keys > are bound to the same outdated string 'hr_HR.ISO8859-2'. > > My questions are the following: > > 1. Is there a way for writing portable Python code dealing with > locales > =A0 =A0(as sketched in the beginning)? > > 2. If not, is there anything wrong with that idea? > > 3. What is the status of locale.locale_alias (official documentation > does not mention it)? > > > Cheers, > > Sinisa > > http://www.zemris.fer.hr/~ssegvic/index_en.html > -- > http://mail.python.org/mailman/listinfo/python-list > There may be some differences btween OSes end the versions, but using python 2.7 and 3.2 on Win XP and Win7 (Czech) I get the following results for setlocale: >>> locale.setlocale(locale.LC_ALL,'Croatian') 'Croatian_Croatia.1250' >>> locale.getlocale() ('Croatian_Croatia', '1250') >>> locale.getpreferredencoding(do_setlocale=3DFalse) 'cp1250' >>> However, "hr" is not recognised on this systems: >>> locale.setlocale(locale.LC_ALL, "hr") Traceback (most recent call last): File "", line 1, in File "locale.pyc", line 531, in setlocale Error: unsupported locale setting >>> regards, vbr