0

My django is not executing translations that i define in my *.po files.

I have my setup like this:

  • MainFolder:
    • locale
      • en
        • LC_MESSAGES
          • django.po
          • django.mo
      • de
        • LC_MESSAGES
          • django.po
          • django.mo
    • app1
      • settings.py
    • app2
    • ....

in my settings.py i have everything enabled i think:

USE_I18N = True

USE_L10N = True

LANGUAGE_CODE = 'en'

LANGUAGES = (
   ('en', _('English')),
   ('de', _('German')),
)

TEMPLATE_CONTEXT_PROCESSORS = (
    ....
    'django.core.context_processors.static',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    )

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
)

let's say my django.po file contains an example like this:

msgid "Home"
msgstr "Home22222"

and i use this in my template file:

{% trans "Home" %}

The home is not being replace by Home22222 It stays the same, even when i remove the LocaleMiddleware.

i did ran

makemessages --locale=en

and afterwards:

compilemessages

I am using Python 2.7 and django 1.6.4

Maxim
  • 3,836
  • 6
  • 42
  • 64
  • did you run `django-admin.py compilemessages` ? – cor Sep 02 '14 at 11:53
  • Yes i did, i will add that to my original description, sorry. – Maxim Sep 02 '14 at 11:57
  • This http://stackoverflow.com/a/11609913/821594 can help – stalk Sep 02 '14 at 11:57
  • according to their documentation: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#how-django-discovers-translations it is not necessary to set a locale path in my case, since i have it in a by default discoverable place i think – Maxim Sep 02 '14 at 11:59
  • I tried setting the LOCALE_PATH, but the issue remains the same – Maxim Sep 02 '14 at 12:19
  • First of all you define only one language in your LANGUAGES, secondly, could you please provide your urls? have you actually enabled i18n in your urls according to the documentation? – petkostas Sep 02 '14 at 12:39
  • I have now defined 2 languages (see updated original post). I have also added the url for setting the language. I went to myurl/i18n/setlang which redirects me to the previous page. However the language is not changed. – Maxim Sep 02 '14 at 14:59
  • After some more searching i followed this answer and everything worked. http://stackoverflow.com/questions/14031753/internationalization-doesnt-work-or-i-dont-know-how-to-make-it-work?rq=1 apparently i did set the incorrect locale path – Maxim Sep 02 '14 at 17:32

0 Answers0