I use Django 1.3.
I have a clean project with:
settings.py
import os, sys
# absolute path to the project
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
# add to PYTHONPATH
sys.path.append(os.path.join(PROJECT_ROOT, "apps"))
LANGUAGE_CODE = 'ru-ru'
USE_I18N = True
USE_L10N = True
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT,'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'i18n_app',
)
urls.py
urlpatterns = patterns('',
url(r'^$', 'i18n_app.views.test'),
)
i18n_app/views.py
from django.shortcuts import render_to_response
from django.template import RequestContext
def test(request):
return render_to_response('i18n_app/test.html', context_instance=RequestContext(request))
templates/i18n_app/test.html
{% load i18n %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
{% trans "String for trans" %}
<br>
<br>
<br>
{% blocktrans %}And one more{% endblocktrans %}
</body>
</html>
From project’s root i run this command:
D:\Django\projects\testi18n>django-admin.py makemessages -l ru
processing language ru
Then I fill out file django.po which was created after this command and do:
D:\Django\projects\testi18n>django-admin.py compilemessages --traceback
processing file django.po in D:\Django\projects\testi18n\conf\locale\ru\LC_MESSAGES
But all I see it’s english strings.
I have found too much questions about this, but no one of them hasn’t helped to me.
What I’m doing wrong?
Add to your settings:
Create an empty folder named
localein your projects directoryThen from your projects directory run:
This command will create a .po file inside your
localefolder.Open that file and fill the emptymsgstr ""fields with the desired translation of themsgidfields that sit above.This is where you define the translation of the strings you marked for translation in the .html file.
After writing the translation of your strings run: