Django 1.5.5 始终显示原始 (en) 字符串(不翻译) [英] Django 1.5.5 displays original (en) strings always (does not translate)

查看:20
本文介绍了Django 1.5.5 始终显示原始 (en) 字符串(不翻译)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在模板中实现简单的 Django 1.5.5 字符串翻译.

我有:

  1. USE_I18N = Truesettings.py
  2. 'django.middleware.locale.LocaleMiddleware' in MIDDLEWARE_CLASSES in settings.py
  3. 'django.core.context_processors.i18n' in TEMPLATE_CONTEXT_PROCESSORS in settings.py
  4. 模板中的一些 {% trans "My string" %} 字符串
  5. {% load i18n %} 在所有模板中
  6. python manage.py makemessages -l he
  7. 使用 Poedit 翻译我的字符串
  8. 运行 python manage.py compilemessages
  9. LOCALE_PATHS = ('conf/locale',)settings.py
  10. 重启服务器

翻译后的字符串仍为英文.

我在模板中使用 {% 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:

  1. USE_I18N = True in settings.py
  2. 'django.middleware.locale.LocaleMiddleware' in MIDDLEWARE_CLASSES in settings.py
  3. 'django.core.context_processors.i18n' in TEMPLATE_CONTEXT_PROCESSORS in settings.py
  4. Some {% trans "My string" %} strings in templates
  5. {% load i18n %} in all templates
  6. Ran python manage.py makemessages -l he
  7. Translated my strings using Poedit
  8. Ran python manage.py compilemessages
  9. LOCALE_PATHS = ('conf/locale',) in settings.py
  10. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆