我正在尝试使用2种语言创建项目 德语和英语
我的设置文件
LOCALE_PATHS = (os.path.join(BASE_DIR, 'app /locale'),)
MIDDLEWARE = (
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
我如何运行此工具
python manage.py makemessages -a
This tool runs in debug mode
processing locale en
processing locale de
python manage.py compilemessages
This tool runs in debug mode
processing file django.po in app/locale/de/LC_MESSAGES
processing file django.po in app/locale/en/LC_MESSAGES
档案位置app_ac / locale / de / LC_MESSAGES
-rw-rw-r--. 1 root root 421 May 11 11:44 django.mo
-rw-rw-r--. 1 root root 44K May 11 11:43 django.po
我没有得到所需的翻译,我觉得.mo文件可能出现问题,因为大小只有421字节,因为它是.po文件的隔离,这是44Kb
编辑1
我刚刚在django.po文件中找到了
该文件看起来像这样
#: project/settings.py:184
msgid "German"
msgstr ""
#: project/settings.py:185
msgid "English"
msgstr ""
而不是(理想情况下,对我可怜的德国人抱歉)
#: .\project\settings.py:185
msgid "German"
msgstr "Deutsch"
#: .\project\settings.py:186
msgid "English"
msgstr "Englisch"
答案 0 :(得分:0)
我刚刚发现po文件中缺少翻译消息,用适当的消息替换它们然后运行
python manage.py compilemessages
命令,现在翻译就像一个魅力!!