Tuesday, September 16, 2014

How/where to call setlocale

Hello,

I am running Django/python on Ubuntu. I am finding that my locale is not setup correctly. Running locale from the command line shows this:

LANG=en_GB.UTF-8
LANGUAGE=en_GB:en
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

Running python from the command line I can see that my locale is not set hence I am running with the default ("C") locale which has the wrong (non-GB) date format. Calling setlocale(...) fixes this:

>>> import locale
>>> locale.getdefaultlocale()
('en_GB', 'UTF-8')
>>>
>>> locale.getlocale()
(None, None)
>>> locale.nl_langinfo(locale.D_FMT)
'%m/%d/%y'
>>>
>>> locale.setlocale(locale.LC_ALL, '')
'en_GB.UTF-8'
>>>
>>> locale.getlocale()
('en_GB', 'UTF-8')
>>> locale.nl_langinfo(locale.D_FMT)
'%d/%m/%y'

However, I am unsure how/where to run setlocale(...) within my configuration/start-up since this affects the entire environment, though that is not really a problem since all my sites are UK based.

Can someone help please?

Thanks
Jay

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/64573f83-ef1e-4fcb-872f-64affb0e3e3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment