Chris
Chris

Reputation: 671

Django makemessage command not processing app

I'm trying to internationalize a django application. I followed the tutorial, but when i run ...

./manage.py makemessages --all

... django only creates a .po file that contains the translations of my settings.py (see below). It completely ignores anything inside my app and its templates.

This is my file structure:

myproject
  |- myproject
      |- course
          |- templates
          |- static
          |- ...
          |- apps.py
          |- models.py
          |- views.py
          |- ...
      |- locale
      |- myproject
          |- settings.py
          |- ...
      |- manage.py

My settings file looks like this:

from django.utils.translation import ugettext_lazy as _

...

INSTALLED_APPS = [
     ...
     'course.apps.CourseConfig',
]

MIDDLEWARE_CLASSES = [
    ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': False,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'CET'
USE_I18N = True
USE_L10N = True
USE_TZ = True


LANGUAGES = [
    ('en', _('English')),
    ('kr', _('Korean')),
    ('cn', _('Chinese')),
    ('pt', _('Portuguese')),
]

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

My templates contain translation texts:

{% extends "course/base.html" %}

{% load i18n %}    
{% trans "Back to modules" %}
...

If I run the 'makemessages' command, the only thing that's being included in the .po file is the language names in the settings.py file, but not the template variables or anything I translated with ugettext in a view.

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-30 20:25+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: myproject/settings.py:146
msgid "English"
msgstr ""

#: myproject/settings.py:147
msgid "Korean"
msgstr ""

#: myproject/settings.py:148
msgid "Chinese"
msgstr ""

#: myproject/settings.py:149
msgid "Portuguese"
msgstr ""

Can anyone tell what I'm missing? The app works just fine, all templates are found at runtime. Thanks a lot.

Upvotes: 1

Views: 3550

Answers (1)

Chris
Chris

Reputation: 671

I finally found the "problem". I had to go into the directory of my django app course and then run ../manage.py makemessages -l en, etc. from there again. Then, the files were created and everything worked just fine. Django docs were not really explicit about me having to cd into my each app.

Upvotes: 6

Related Questions