Unable to find a locale path to store translations for file __init__.py

DjangoTranslation

Django Problem Overview


I'm trying to translate a Django app. I created some strings with {% trans %} in my templates. However, when I execute the following command in my app folder, I receive an error message:

$ django-admin.py makemessages -l fr 
CommandError: Unable to find a locale path to store translations for file __init__.py`

What did I do wrong?

Django Solutions


Solution 1 - Django

Turns out you need to create a locale folder first using mkdir locale. If you are running the command from within an app folder, you need a locale folder within that app folder.

Solution 2 - Django

Actually you can configure where the locale folder is. In your settings.py add:

LOCALE_PATHS = (
    PROJECT_ROOT + '/website/locale', )

Then create a folder for each of the languages you want to translate:

mkdir -p website/locale/de

Solution 3 - Django

The problem is that the command is not run from the app directory but from the project directory. This snippet from the docs explains it:

Turns out you need to create a locale folder first using mkdir locale. > ./manage.py makemessages […] Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the Django tree) or locale (for project and application) directory.

So, you either run the command from the app directory:

$ cd app
$ django-admin makemessages -l <locale>

… or you define a project wide locale directory using LOCALE_PATHS and you can run makemessages from the main directory from there on.

Either way, you should check that the ./locale/directory is present and create it using

$ mkdir locale

in case it's not.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAntoine M.View Question on Stackoverflow
Solution 1 - DjangoAntoine M.View Answer on Stackoverflow
Solution 2 - DjangoDavid DehghanView Answer on Stackoverflow
Solution 3 - DjangojnnsView Answer on Stackoverflow