Django i18n和python地区(和日期) [英] Django i18n and python locales (and dates)
问题描述
我使用datetime.strftime填充一些选择元组,然后在表单中使用。
根据我的理解,django会将语言环境设置为用户的选择,以便datetime.strftime()以相应的语言输出,但这似乎不
我在这里缺少什么?
如果我手动设置区域设置(例如locale.setlocale (locale.LC_TIME,'de_DE.UTF-8'))datetime确实正确翻译。
谢谢,
Tom
Django不设置区域设置进行翻译,只需加载翻译目录。要获得所需的效果,您可以设置区域设置(这不是一个很好的选择,因为它在整个过程范围内)或使用专门的库。我推荐 Babel ,它具有很好的Django集成。
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
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.
这篇关于Django i18n和python地区(和日期)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!