1

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 <LL@li.org>\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.

4
  • What are the file names of the templates? makemessages looks for *.py, *.html and *.txt. It should search in all subdirectories of the current working directory.
    – Håken Lid
    Jan 30, 2016 at 21:53
  • If the files show up with ls ./**/*.{html,txt,py} (assuming your shell is bash) you should be fine.
    – Håken Lid
    Jan 30, 2016 at 21:55
  • And to confirm that gettext is installed, you can try gettext -h.
    – Håken Lid
    Jan 30, 2016 at 22:02
  • @HåkenLid: thanks. gettext is installed. Template file extensions are *.html However, the template files don't show up with ls ./**/*.{html,txt,py}. I ran it on the level of manage.py. It lists files inside myproject/myproject/course and myproject/myproject/myproject folder. As templates are in myproject/myproject/course/templates/course, they don't show up. Also, I have translations in myproject/myproject/course/views.py, which are not considered when I run makemessages. And ideas? Is my folder structure wrong? I did follow the django tutorials though.
    – Chris
    Jan 31, 2016 at 8:06

1 Answer 1

6

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.

2
  • You can also run django-admin makemessages ... instead of addressing manage.py in root folder
    – Don
    Nov 9, 2016 at 8:23
  • @Chris you are my hero today, thanks. worked like a charm
    – philo
    Nov 11, 2020 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.