I'm new to Django and now I am practicing Django Internationalization, intending to show my webpages in Chinese, however:
Whatever changes I've made into the django.po file, and used compilemesseages to generate the .mo file, the pages still returned the previous translations, even if I deleted the .po file to generate a new one.
Did I miss something? If so, please tell me, thank you :)
This is my settings:
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'),
)
also I've added the 'django.middleware.locale.LocaleMiddleware'into settings.py, just like this:
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',
)
what I was test is this function in views.py:
def test1_view(request):
n = 2
weekdays = [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'),
_('Sunday')]
return HttpResponse(weekdays[n])
the django.po file generated at /locale/zh_CN/LC_MESSAGES/django.po, and i'm sure i had delete the #,fuzzy:
#: 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 "七"
then I used the $ python manage.py compilemessages and the .mo file generated, but when I restarted the server, the page was still as the same as the first time I modified the .po file: it just showed "星期三" instead of "三".
I'm really confused about this, are there some cookies that I should empty to ensure the changes could work? TOT
PS: My django version is 1.8.8
After almost 3 days , I finally solved this problem by writing emails for help. Actually this problem seemed to be caused by some specific languages settings, such as Chinese:
I changed my settings.py:
LANGUAGES = (
('en', ('English')),
('zh-CN', ('中文简体')),
('zh-TW', ('中文繁體')),
)
which used '-' instead of '_', however still used
$ python manage.py makemessages -l zh_CN
to generate the django.po(where the '_' was still the same).
@Emin Mastizada, thank you all the same :)