Django locale .po files not showing up in locales folder

132 views Asked by At

I have been running into an issue setting up locales for my Django app. When I run the django-admin's makemessages command no resulting .po files show up in my {project_root}/locales folder.

Here are the steps I followed to setup locales:

Created locale/ folder in project root

Changes to settings.py

from os.path import join as osjoin

MIDDLEWARE = [
    ...
    'django.middleware.locale.LocaleMiddleware',
    ...
]


USE_I18N = True

LOCALE_PATHS = [
    osjoin(BASE_DIR, 'locale'),
]

Solved missing dependencies Had to install GNU gettext (for windows) and added it to system PATH.

Commands I ran

python manage.py makemessages -l fr

also tried:

django-admin makemessages -l fr

I also tried with the fr_FR tag, didn't change anything.

both result in this output message but no files added to locales/:

processing locale fr

I also superstitiously tried to run the command as admin but didn't change much.

I am also aware of these answers to the same question (9 years ago) but the answers didn't help.

3

There are 3 answers

2
Vaishnavi Kesherwani On
  1. Check File Structure
  2. Correct Locale Path
  3. Check Language Code
  4. Run makemessages from Project Root
  5. Check for Permissions
  6. Check for Messages to Translate from django.utils.translation import gettext as _ python manage.py makemessages -l fr -v 2
4
Mohsen Amiri On

you need make 'locale' directory in root . django cant make this folder.

1
Mess On

I think you have got a typo error.

Change this

LOCALE_PATHS = [
    osjoin(BASE_DIR, 'locale'),
]

To

# import os .. place on top
LOCALE_PATHS = [
    os.path.join(BASE_DIR, 'locale'),
]

Then run your command again.