locale settings and date parsing under windows
matt.j.warren at gmail.com
Thu Feb 3 13:23:21 CET 2011
On Feb 3, 12:13 pm, "Martin P. Hellwig" <martin.hell... at dcuktec.org>
> On 02/03/11 10:59, AlienBaby wrote:
> > On Feb 3, 10:22 am, AlienBaby<matt.j.war... at gmail.com> wrote:
> >> Hi,
> >> I'm attempting to convert some date-time strings from a text file
> >> under windows into a datetime object as returned by strptime()
> >> However, the strings can represent dates in various formats based on
> >> the country of origin, for example shortened month names etc.. are
> >> different between countries.
> >> I am trying to set the correct locale for strptime to work, but I'm
> >> having a lot of trouble doing this under windows.
> >> IE, wher the date is in the Danish Language,
> >> import locale
> >> locale.setlocale('LC_ALL',locale.normalize('da_DK'))
> >> gives
> >> locale.Error: unsupported locale string.
> >> I have tried various ways but always hit the same error.
> >> I understand setting LC_ALL may not be what I require, I was first
> >> looking to simply get the locale setting correctly before I started
> >> changing only the date-time specific elements.
> >> Any help or pointers much appreciated. Current searching around is
> >> revealing a fair amount of confusion..!
> >> Thanks,
> >> Matt.
> > As often happens, writing that out and the working through a bit more,
> > I resolved my own question.
> > It ended up being a simple matter of translating from posix codes to
> > windows codes, so 'fr_FR' becomes 'French_France'...
> > thanks,
> > MAtt.
> You might also want to have a look at the contents of:
> mph- Hide quoted text -
> - Show quoted text -
I did for a bit..
I tried, for example with French
from locale.locale_alias, you can find
'fr_FR' aliases to 'fr_FR.ISO8859-1'
locale.Error: unsupported locale setting
I'm now just using a handbuilt dict that holds translations like
'fr_FR' : 'French_France'
'da_DK' : 'Danish_Denmark'
More information about the Python-list