3

When I run django-admin makemessages -l en nothing happens and no po files are created. It only says processing locale en

This is my folder structure

/myproject
 myapp/
 locale/
 media/
 static/
 templates/
 db.sqlite
 manage.py
 settings.py
 urls.py
 wsgi.py

settings.py

import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
INSTALLED_APPS = [
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'myapp',
]
MIDDLEWARE = [
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django_user_agents.middleware.UserAgentMiddleware',
]
ROOT_URLCONF = 'urls'
WSGI_APPLICATION = 'wsgi.application'
LANGUAGE_CODE = 'fr'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
asked Oct 25, 2020 at 18:47

2 Answers 2

3

I realized that makemessages does not create po files if translations are not referenced in any of the templates

I was expecting makemessages to create an empty po file that can I continue editing, but it does not work that way. At least one of the templates must have translations for the file to be created at the first time.

{% load i18n %}
....
{% trans 'Welcome' %}
python manage.py makemessages -l en
# 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: 2020年11月08日 18:58+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"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: .\templates\index.html:4
msgid "Welcome"
msgstr ""

I hope this will be useful to anyone encountering the same issue

answered Nov 8, 2020 at 18:01
Sign up to request clarification or add additional context in comments.

Comments

0

You should probably add your app as ‘myapp.apps.MyappConfig’ instead of just ‘myapp’ in your settings.py INSTALLED_APPS and also include your app in LOCALE_PATHS

LOCALE_PATHS = ( 
os.path.join(BASE_DIR, "locale"),
os.path.join(BASE_DIR, "yourapp/locale"), 

)

answered Oct 26, 2020 at 14:45

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.