Karel
Karel

Reputation: 369

Django translation returning the same strings

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!]

Upvotes: 1

Views: 1482

Answers (1)

bmihelac
bmihelac

Reputation: 6323

Did you set LOCALE_PATHS in settings.py?

This only applies if you have translations in project directory.

Upvotes: 1

Related Questions