1
votes

I am setting up a new small project to try i18n in Django 1.4.3 (English and Dutch). But I think I'm missing a step, as it is not translating the strings.

Who can tell me what I need to do to get the translated strings? How can I debug?

settings.py:

gettext = lambda s: s
LANGUAGES = (
  ('nl', gettext('Dutch')),
  ('en', gettext('English')),
)

LOCALE_PATH= (
  '/var/www/test/locale',
)
# django.middleware.locale.LocaleMiddleware is also included @ MIDDLEWARE_CLASSES

The urls.py file:

urlpatterns = i18n_patterns('',
    #home
    url(r'^$','bday.views.home',name="index"),
)

views.py in project:

from django.utils.translation import ugettext as _
def home(request):
  text=_("Welcome!")
  return HttpResponse("LANG[{}], TEXT[{}]".format( request.LANGUAGE_CODE, text ) ) 

/var/www/test/locale/nl/LC_MESSAGES/django.po

#: bday/views.py:16
msgid "Welcome!"
msgstr "Welkon in Nederlands"

/var/www/test/locale/en/LC_MESSAGES/django.po

#: bday/views.py:16
msgid "Welcome!"
msgstr "Welcome in English"

The messages do get compiled, I get:

./manage.py compilemessages
processing file django.po in /var/www/test/locale/nl/LC_MESSAGES
processing file django.po in /var/www/test/locale/en/LC_MESSAGES

But in my app, I'm getting:

$ curl "http://www.host.com:8000/nl/" 
LANG[nl], TEXT[Welcome!]
$ curl "http://www.host.com:8000/en/" 
LANG[en], TEXT[Welcome!]
1
You need to set the actuall language with django.utils.translation.activate - Rickard Zachrisson
Thanks for your reply. I think this is done automatically by the urlconf. Adding it to the code (directly after the imports) doesn't change anything. - Karel
$ mv locale{,old}/ $ mkdir locale $ ./manage.py makemessages -l en $ vim locale/en/LC_MESSAGES/django.po $ ./manage.py compilemessages No change - Karel

1 Answers

1
votes

Did you set LOCALE_PATHS in settings.py?

This only applies if you have translations in project directory.