请教各位大神,由于最近在学Django,学到django国际化的时候,出现了小问题:
无论我怎么更改django.po文件,删除重新生成,重启服务器,每次显示的页面仍然是我第一次使用.po文件的样子/(ㄒoㄒ)/~~settings.py
如下:
LANGUAGE_CODE = 'zh-CN'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LANGUAGES = (
('en', ('English')),
('zh_CN', ('中文简体')),
('zh-hant', ('中文繁體')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
也添加了对应的中间件:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
测试的函数,在views.py中如下:
def test1_view(request):
n = 2
weekdays = [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'),
_('Sunday')]
return HttpResponse(weekdays[n])
利用$ python manage.py makemessages -l zh_CN
,在/locale/zh_CN/LC_MESSAGES/django.po处生成文件更改如下:
#: testdeploy/views.py:64
msgid "Monday"
msgstr "一"
#: testdeploy/views.py:64
msgid "Tuesday"
msgstr "二"
#: testdeploy/views.py:64
msgid "Wednesday"
msgstr "三"
#: testdeploy/views.py:64
msgid "Thursday"
msgstr "四"
#: testdeploy/views.py:64
msgid "Friday"
msgstr "五"
#: testdeploy/views.py:64
msgid "Saturday"
msgstr "六"
#: testdeploy/views.py:65
msgid "Sunday"
msgstr "七"
并且也删除了#,fuzzy
,利用$ django-admin.py compilemessages
进行了编译,返回的仍然是第一次试验的时候的:
而且,即使我将.po文件删除,重启服务器同样可以显示,请问这是为什么呢?是否仍然存在类似于cookies之类的缓存需要清除呢?
谢谢各位~
经过自强学堂向涂老师发邮件请教,问题在于将settings.py中设置成
而生成的时候仍然按照下划线生成,即执行
$ python manage.py makemessages -l zh_CN
python manage.py compilemessages 了么?