1

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 is LANGUAGE_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 paragraphs
  • Is 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

bgarcial
  • 2,915
  • 10
  • 56
  • 123
  • new to python and starting with gnu gettext? Respect ;-) Anyway, could you please add more information to your question? Do you have some code for us? I read your question twice but still don't know what your're exactly doing... – aronadaal May 21 '15 at 20:03
  • 1
    Of course @aronadaal. I'm not too much newbie although I am just following an example of Internationalization in which use gettext library. In my main post of this question I complete more details. Thanks – bgarcial May 21 '15 at 20:14
  • 1
    @aronadaal I've edited my question for have more details about it. Thanks – bgarcial May 21 '15 at 20:45
  • Strange. I think I found something similar here: http://stackoverflow.com/questions/4370035/django-makemessages-errors-unknown-encoding-utf8 The problem could be similar to yours: what is inside of the init.py files? – aronadaal May 21 '15 at 20:59
  • Inside of my __init__.py files there is not nothing. The most files are empty. That problem that you refer me is similar, but the error of they is about of utf-8 codification type inside of __init__py files. My error is more strange (I think so), this of language python unknown – bgarcial May 21 '15 at 21:12
  • How did you install gettext or xgettext and what OS are you running? – Justin Hamade Jun 29 '15 at 19:03
  • @JustinHamade I install gettext of this way. I've dowload from https://www.gnu.org/software/gettext/, unzipped, and I build the package with ./configure, make and make install commands using the following source http://www.marinamele.com/taskbuster-django-tutorial/internationalization-localization-languages-time-zones#inter-translation – bgarcial Jul 06 '15 at 05:06
  • 2
    @BernardoGarcia Sounds like your install is missing Python support which I can't reproduce. If you are running a linux distro I would recommend installing a pre-compiled binary from your distro's package management. For ubuntu 'sudo apt-get install gettext' For OS X install from brew http://brewformulas.org/Gettext – Justin Hamade Jul 14 '15 at 23:28

0 Answers0