I am trying work with internationalization and install the GNU gettext tool for generate messages.
In my settings/base.py I use the i18n context processor in the directive TEMPLATES:
TEMPLATES = [
{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS':[os.path.join(BASE_DIR, "templates")], 'APP_DIRS': True, 'OPTIONS' : { 'context_processors':[ 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', ], },
}, ]
I also use the LocaleMiddleware in my settings/base.py
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
I also specify the languages that I want use in my settings/base.py:
from django.utils.translation import ugettext_lazy as _
LANGUAGES = (
('en', _('English')),
('ca', _('Catalan')),
('es-co', _('Spanish')),
)
My predetermined
LANGUAGE_CODE
isLANGUAGE_CODE = 'en-us'
and I specify the locale folder so (also in settings/base.py):LOCALE_PATHS = ( os.path.join(BASE_DIR, 'locale'), )
For the behavior of my app, i implement this url i18n_patterns function:
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
urlpatterns += i18n_patterns(
url(r'^$', home, name='home'),
url(r'^admin/', include(admin.site.urls)),
)
With this, my app in my local server home page redirect to /en or /ca
Of side of my templates, I am testing the translation on some tags html like
and using this two template tags: trans for translate a single line and blocktrans for paragraphsIs here when I use gettext library (I build and install in my machine) and in the the moment of generate my message, I get this output error:
(tb_test)➜ my_project git:(master) ✗ python manage.py makemessages -l ca CommandError: errors happened while running xgettext on __init__.py language
Python' unknown (tb_test)➜ my_project git:(master) ✗
The output says that there is a problem on init.py ... The most files named init.py I have them empty .. On which files should I focus for this message of `Python' unknown
I'm newbie in python, my apologies. Best Regards, thanks
Postdata: I am interested in learn about of internationalization in Django apps, and I did want follow this sample of this great tutorial http://www.marinamele.com/taskbuster-django-tutorial/internationalization-localization-languages-time-zones
This page describe a bit the steps that I describe here in my post. Thanks