Django Internationalization doesn't work (makemessages doesn't find .py file)
Question: I'm trying to internationalize my Django site with I18N. When I do the
makemessages. Bit that did not get the text of the view.py. I have done the
following things:

    
    
    # my flow
    PROJECT
    - LOCALE
    - MYSITE
      - urls.py
      - settings.py
    - APP1
      - views.py
    - APP2
    - APP3      
    manage.py
    
    # settings.py
    LANGUAGES = (
         ('it', 'Italiano'),
         ('en', 'English'),
                )
    LANGUAGE_CODE = 'it'
    USE_I18N = True
    LOCALE_PATHS = ('home/project/locale/',)
    MIDDLEWARE_CLASSES = ( ...
                          'django.middleware.locale.LocaleMiddleware',
                         )   
    TEMPLATE_CONTEXT_PROCESSORS = (...,
                          'django.core.context_processors.i18n',
                         )
    
     # views.py
    
     from django.utils.translation import ugettext as tra
     text = tra("this is a text")
     ...
    
     # template.html
     ...
     {% trans 'Dashboard' %}
     ....
    

from the root (where is manage.py) when I do "python manage.py makemessages.py
en-l" I get only a django.po with text from html file and not from views.py. I
also tried with "python manage.py makemessages.py en-l-e html,py" but it
doesn't work. Where am I doing wrong?


Answer: `makemessages` looks for very specific patterns in your code; `tra()` is _not_
one of those patterns.

From the [`makemessages` command
source](https://github.com/django/django/blob/master/django/core/management/commands/makemessages.py#L74)
you can see the `xgettext` command line tool is instead instructed to look
for: `gettext_noop`, `gettext_lazy`, `ngettext_lazy`, `ugettext_noop`,
`ugettext_lazy`, `ungettext_lazy`, `pgettext`, `npgettext`, `pgettext_lazy`
and `npgettext_lazy` (in addition to the `_()` callable).

Change your `views.py` code to:

    
    
    from django.utils.translation import ugettext as _
    text = _("this is a text")
    

to follow the widespread `gettext` conventions, or use:

    
    
    from django.utils.translation import ugettext
    text = ugettext("this is a text")
    

Best to stick to the original `translation.*` methods or `_()`, here.

