Search code examples
pythondjangointernationalizationdjango-i18n

Django translation not working in my case


I feel bad for asking this as it was asked so many times:

django - how to make translation work?

django internationalization and translations issue

How to setup up Django translation in the correct way?

http://askbot.org/en/question/8948/weve-edited-djangopo-files-but-translations-do-not-work-why/

I want to have English (default) and Slovenian languages. My settings are like this:

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
)
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Belgrade'
USE_I18N = True
USE_L10N = True
USE_TZ = True
from django.utils.translation import ugettext_lazy as _
LANGUAGES = (
  ('si', _('Slovenian')),
  ('en-us', _('English')),
)
LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

Urls.py:

urlpatterns = i18n_patterns('',
    url(r'^', include('analytics.urls')),
    url(r'^login', RedirectView.as_view(url='/admin/login', permanent=False)),
    url(r'^admin/', include(admin.site.urls)),
)

Templates:

<div class="time_range">{% trans "Time range:" %}</div>

I compiled messages to .po file and now according to the documentation one would expect this to start working. But no luck for me. If I visit the url with /si/ prefix I still see the english strings.


Solution

  • I'm not sure if this is significant, but in my internationalized application I have this:

    LANGUAGES = (
        ("nl", "Nederlands"),
        ("en", "English"),
        )   
    

    i.e., without the _() around the strings. Your code fragment doesn't show how you define _, the documentation says you have to alias it to ugettext_lazy(). Maybe it makes a difference.

    What also would make it easier to help you, is if you provide the source code to a minimal Django application which demonstrates your problem (on github, for example).