tags:

views:

57

answers:

3

What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call:

datetime.date(2009,1,16).strftime("%A %Y-%b-%d")

instead of getting:

Out[20]: 'Friday 2009-Jan-16'

i get spanish/french/german/... output

Out[20]: 'Viernes 2009-Ene-16'

without having to change my whole operating system's locale (i.e. just use python calls to dynamically set the locale and keep the changes scoped within my app)

Thanks.

+1  A: 

locale.setlocale()

Ignacio Vazquez-Abrams
sorry for the basic question, but how do you set it? 'spanish' in locale.locale_alias.keys()Truelocale.setlocale(locale.LC_ALL, 'spanish')Error: unsupported locale setting
jd
`locale.setlocale(local.LC_TIME, 'es_ES')`
Ignacio Vazquez-Abrams
tried locale.setlocale(locale.LC_TIME, 'es_ES')and still get Error: unsupported locale setting
jd
Then for some reason your operating system's locale entries are missing.
Ignacio Vazquez-Abrams
That's a hardcoded mapping; it doesn't look at your OS to figure out what it knows about.
Ignacio Vazquez-Abrams
got it; thanks for your help; will try to figure out my ubuntu's locale settings and follow up on this thread
jd
sudo locale-gen es_ES.UTF-8 did the trick; now your answer worked;thanks.
jd
+1  A: 

After setting your locale (with locale.setlocale) You can use the locale modules' nl_langinfo method like so:

time.strftime(locale.nl_langinfo(locale.D_T_FMT), time.localtime())
Kyle Lutz
A: 

Also, have a look at the babel project.

codeape