0

I created a Django site with localization built in, using python manage.py runserver to test it. But after setting it live with Apache/WSGI, the localization doesn't work correctly.

I can see dates being translated (so somehow it knows the current language), but all my site-specific strings are untranslated.

I have no idea where to look though on where to fix this.

When running on the Django console, it works fine:

>>> import django.utils.translation
>>> django.utils.translation.activate('nl')
>>> django.utils.translation.ugettext('Articles')
u'Artikelen'

But when using the same code in a view:

from django.utils import translation

def page_test(request):
    translation.activate('nl')
    return HttpResponse(translation.ugettext("Articles"))

this returns Articles.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195

1 Answers1

0

Turned out my LOCALE_PATHS was incorrect. I had this code in my settings.py:

SITE_ROOT = os.path.dirname(os.path.realpath(__name__)) 
LOCALE_PATHS = ( os.path.join(SITE_ROOT, 'locale'), ) 

but in the live situation, SITE_ROOT was empty. I replaced it with

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LOCALE_PATHS = ( os.path.join(BASE_DIR, 'locale'), ) 

and it works now.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195