[Django]-Unable to find a locale path to store translations for file __init__.py

189๐Ÿ‘

โœ…

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.

๐Ÿ‘คAntoine M.

36๐Ÿ‘

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
๐Ÿ‘คDavid Dehghan

20๐Ÿ‘

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.

๐Ÿ‘คjnns

0๐Ÿ‘

If you want per-app locale dirs, simply create them in every app dir with translation strings (that has files with translation strings) before running makemessages. And django will find them. No need to cd.

If you want one project-wide locale dir, create it in the project dir before running makemessages.

๐Ÿ‘คx-yuri

0๐Ÿ‘

For me, I had LOCALE_PATHS set correctly, but I did not have the environment variables set. When I set the environment variables, I ran python manage.py makemessages -l de and it ran correctly.

0๐Ÿ‘

Folks, one thing I noticed. I had to create the locale directory from Terminal within the app folder by issuing the command mkdir locale. While creating it from inside PyCharm I kept getting the error message:

CommandError: Unable to find a locale path to store translations for file allauth_introducao/init.py. Make sure the โ€˜localeโ€™ directory exists in an app or LOCALE_PATHS setting is set.

๐Ÿ‘คBruno Daemon

-1๐Ÿ‘

You must create locale folder just under your django-project folder as shown below. *The folder name must be locale according to my experiments:

django-project
 |-core
 |  โ””-settings.py
 |-app1
 |  |-models.py
 |  โ””-admin.py
 |-app2
 |  |-models.py
 |  โ””-admin.py
 โ””-locale # Here

Then, you can create django.po in each locale/<...>/LC_MESSAGES/ with the command below. *The command below can create or update one or more django.po:

django-admin makemessages --locale=en --locale=fr --locale=ja

Or:

django-admin.py makemessages -l en -l fr -l ja

Then, django.po is created in each locale/<...>/LC_MESSAGES/ as shown below:

django-project
 |-core
 |  โ””-settings.py
 |-app1
 |  |-models.py
 |  โ””-admin.py
 |-app2
 |  |-models.py
 |  โ””-admin.py
 โ””-locale
    |-en
    |  โ””-LC_MESSAGES
    |     โ””-django.po # Here
    |-fr
    |  โ””-LC_MESSAGES
    |     โ””-django.po # Here
    โ””-ja
       โ””-LC_MESSAGES
          โ””-django.po # Here

And, you can update all django.po in locale folder with the command below. *With the command below, you can only update django.po but cannot create django.po:

django-admin makemessages --all

Or:

django-admin makemessages -a

And, you can compile django.po to django.mo in each locale/<...>/LC_MESSAGES/ with the command below:

django-admin compilemessages

Then, django.po is compiled to django.mo in each locale/<...>/LC_MESSAGES/ as shown below:

django-project
 |-core
 |  โ””-settings.py
 |-app1
 |  |-models.py
 |  โ””-admin.py
 |-app2
 |  |-models.py
 |  โ””-admin.py
 โ””-locale
    |-en
    |  โ””-LC_MESSAGES
    |     |-django.po
    |     โ””-django.mo # Here
    |-fr
    |  โ””-LC_MESSAGES
    |     |-django.po
    |     โ””-django.mo # Here
    โ””-ja
       โ””-LC_MESSAGES
          |-django.po
          โ””-django.mo # Here

In addition, even if you create locale folder just under core, app1 and app2 folders as shown below:

django-project
 |-core
 |  |-settings.py
 |  โ””-locale # Here
 |-app1
 |  |-models.py
 |  |-admin.py
 |  โ””-locale # Here
 โ””-app2
    |-models.py
    |-admin.py
    โ””-locale # Here

Then, run the command below:

django-admin.py makemessages -l en -l fr -l ja

Then, you will still get the error below according to my experiments and opposed to How Django discovers translations so you must create locale folder just under your django-project folder:

CommandError: Unable to find a locale path to store translations for
file manage.py. Make sure the โ€˜localeโ€™ directory exists in an app or
LOCALE_PATHS setting is set.

Leave a comment