translation not working in Django 1.5 even after compiling message

117 views Asked by At

I'm using Django 1.5

I have to enable internationalization in my application. For that, I have added a few things to the settings.py file

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

from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
    '...local context processrors...'
)

# global_settings.TEMPLATE_CONTEXT_PROCESSORS contains 
# TEMPLATE_CONTEXT_PROCESSORS = (
#     'django.contrib.auth.context_processors.auth',
#     'django.core.context_processors.debug',
#     'django.core.context_processors.i18n',
#     ...
# )

USE_I18N = True
USE_L10N = True

LANGUAGE_CODE = 'es'

# List of languages available for translation
ugettext = lambda s: s
LANGUAGES = (
    ('en', ugettext('English')),
    ('es', ugettext('Spanish'))
)
LOCALE_PATHS = (
    os.path.join(PROJECT_ROOT, 'locale/'),
)

The LOCALE_PATHS has the location output as

('/media/path_to_project/workbench/workbench/settings/../locale/',)

But on running ./manage.py makemessages -l es it generates *.po file in

/media/path_to_project/workbench/workbench

instead of

/media/path_to_project/workbench/workbench/locale

Also, the compiled language is not showing in the template.

1

There are 1 answers

6
Devang Padhiyar On BEST ANSWER

You need to check following things.

  • Ensure that you added USE_L10N = True and USE_I18N = True into your settings.py file
  • Check for PROJECT_ROOT and LOCALE_PATHS and make sure that it is correct
  • Add django.core.context_processors.i18n to TEMPLATE_CONTEXT_PROCESSORS in setting.py.

Translation and formatting are controlled by USE_I18N and USE_L10N settings respectively. However, both features involve internationalization and localization. The names of the settings are an unfortunate result of Django’s history.