Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

configuration - Django 1.5.5 displays original (en) strings always (does not translate)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...