问题
I'm trying to implement simple Django 1.5.5 string translation in templates.
I have:
USE_I18N = Trueinsettings.py'django.middleware.locale.LocaleMiddleware'inMIDDLEWARE_CLASSESinsettings.py'django.core.context_processors.i18n'inTEMPLATE_CONTEXT_PROCESSORSinsettings.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?
回答1:
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.
来源:https://stackoverflow.com/questions/20518783/django-1-5-5-displays-original-en-strings-always-does-not-translate