问题
I've been playing with Django's i18n system and it seems to be mostly working. However, dates in model code seem to be causing a problem.
I use datetime.strftime to populate a few CHOICES tuples which are then used in forms.
From what I understood, django will set the locale to the user's choice so that datetime.strftime() will output in the appropriate language, but this doesn't seem to happen.
What am I missing here?
If I set the locale manually (eg. locale.setlocale(locale.LC_TIME,'de_DE.UTF-8') ) datetime does translate correctly.
Thanks,
Tom
回答1:
Django does not set locale for translation, just loads translation catalog. To get desired effect you have either set locale (which is not a good option since it works process-wide) or use specialized library. I recommend Babel which has nice Django integration.
回答2:
I've recently faced similar problem but managed to solve the problem by using format instead of the python strftime
来源:https://stackoverflow.com/questions/1318744/django-i18n-and-python-locales-and-dates