Django 1.5.5 始终显示原始 (en) 字符串(不翻译) [英] Django 1.5.5 displays original (en) strings always (does not translate)
问题描述
我正在尝试在模板中实现简单的 Django 1.5.5 字符串翻译.
我有:
USE_I18N = True
在settings.py
'django.middleware.locale.LocaleMiddleware'
inMIDDLEWARE_CLASSES
insettings.py
'django.core.context_processors.i18n'
inTEMPLATE_CONTEXT_PROCESSORS
insettings.py
- 模板中的一些
{% trans "My string" %}
字符串 {% load i18n %}
在所有模板中- 跑
python manage.py makemessages -l he
- 使用 Poedit 翻译我的字符串
- 运行
python manage.py compilemessages
LOCALE_PATHS = ('conf/locale',)
在settings.py
- 重启服务器
翻译后的字符串仍为英文.
我在模板中使用 {% get_current_language as LANG %}{{ LANG }}
检查当前语言是否为 he
.
我做了什么才配得上这个我哪里做错了?
答案(更新自评论):
这似乎是路径问题(否则您会看到一些错误).
尝试在您的设置中执行以下操作:
<前>导入操作系统PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))LOCALE_PATHS = ( os.path.join(PROJECT_PATH, '../locale'), )打印 LOCALE_PATHS完全确定您的路径是正确的.
另外不要忘记您需要拥有包含 django.mo(和 po)文件的路径 locale/he/LC_MESSAGES/
.
I'm trying to implement simple Django 1.5.5 string translation in templates.
I have:
USE_I18N = True
insettings.py
'django.middleware.locale.LocaleMiddleware'
inMIDDLEWARE_CLASSES
insettings.py
'django.core.context_processors.i18n'
inTEMPLATE_CONTEXT_PROCESSORS
insettings.py
- Some
{% trans "My string" %}
strings in templates {% load i18n %}
in all templates- Ran
python manage.py makemessages -l he
- Translated my strings using Poedit
- Ran
python manage.py compilemessages
LOCALE_PATHS = ('conf/locale',)
insettings.py
- Restarted the server
Translated strings remain English.
I do check that current language is he
using {% get_current_language as LANG %}{{ LANG }}
in the template.
What did I do to deserve thisWhere did I go wrong?
Answer (updated from comment):
It seems like a path issue (or else you'd see some error).
Try doing something like this in your settings:
import os PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) LOCALE_PATHS = ( os.path.join(PROJECT_PATH, '../locale'), ) print LOCALE_PATHS
to be totally sure that you've the correct path.
Also don't forget that you need to have the path locale/he/LC_MESSAGES/
that will contain your django.mo (and po) file.
这篇关于Django 1.5.5 始终显示原始 (en) 字符串(不翻译)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!