Reputation: 1476
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.
Upvotes: 2
Views: 1901
Reputation: 5819
After creating your .po files, there are two more steps:
./manage.py compilemessages
to compile your .po file into a .mo fileTo quote the Django translation documentation, After you create your message file – and each time you make changes to it – you’ll need to compile it into a more efficient form, for use by gettext. Do this with the django-admin compilemessages utility.
Upvotes: 6
Reputation: 1619
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).
Upvotes: 2