django l10n dateformat只出错了

时间:2015-09-11 13:05:00

标签: python django localization

我正在使用l10n设置翻译我的网站。 一切顺利,除非浏览器语言设置为' en' 当我打印get_language()并获取语言日期格式。他们返回正确的值(' en',' m / d / Y')

但是,当我在模板中检查日期时,它是Y-m-d

对于其他所有语言,它只是按照它应该的方式工作

# settings.py
LANGUAGE_CODE = 'nl-NL'
USE_I18N = True
USE_L10N = True

# forms
# DatePickerForm is needed to also setup the bvootstrap-datepicker
class DatePickerForm(forms.Form):
""" hidden inputs to make bootstrap-datepicker work with django locale """

FORMAT_MAP = {
    # 'locale': [datepicket_lang, datepicker-pattern]
    # 'en-US': ['en', 'mm/dd/yyyy']
    'en': ['en', 'mm/dd/yyyy'],
    'nl': ['nl', 'd-m-yyyy'],
    'pl': ['pl', 'dd.mm.yyyy'],
    'de': ['de', 'dd.mm.yyyy'],
}

locale_language = forms.CharField(widget=forms.HiddenInput())
locale_date_format = forms.CharField(widget=forms.HiddenInput())

def __init__(self, *args, **kwargs):
    self.locale_language = get_language()
    super(DatePickerForm, self).__init__(*args, **kwargs)
    self.initial['locale_language'] = self.datepicker_language()
    self.initial['locale_date_format'] = self.datepicker_format()
    print self.locale_language

def datepicker_format(self):
    if self.locale_language in DatePickerForm.FORMAT_MAP:
        return DatePickerForm.FORMAT_MAP[self.locale_language][1]
    else:
        return DatePickerForm.FORMAT_MAP['nl'][1]

def datepicker_language(self):
    if self.locale_language in DatePickerForm.FORMAT_MAP:
        return DatePickerForm.FORMAT_MAP[self.locale_language][0]
    else:
        return DatePickerForm.FORMAT_MAP['nl'][0]

class TotalForm(DatePickerForm):
""" date range input for totals """

begin = forms.DateField(label='')
end = forms.DateField(label='')

任何人都知道为什么会出错?

0 个答案:

没有答案