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.
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
- [Django]-Django 2.0 โ Not a valid view function or pattern name (Customizing Auth views)
- [Django]-What is the equivalent of "none" in django templates?
- [Django]-Django testing: Test the initial value of a form field
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.
- [Django]-How do you catch this exception?
- [Django]-Django.contrib.gis.db.backends.postgis vs django.db.backends.postgresql_psycopg2
- [Django]-Django-social-auth django-registration and django-profiles โ together
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
.
- [Django]-How to select a record and update it, with a single queryset in Django?
- [Django]-Django Footer and header on each page with {% extends }
- [Django]-Django error โ matching query does not exist
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.
- [Django]-Celery : Execute task after a specific time gap
- [Django]-How to run a celery worker with Django app scalable by AWS Elastic Beanstalk?
- [Django]-What is the difference between cached_property in Django vs. Python's functools?
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.
- [Django]-Django: How to get related objects of a queryset?
- [Django]-How do you change the collation type for a MySQL column?
- [Django]-Django: Filter a Queryset made of unions not working
-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.
- [Django]-In Django 1.4, do Form.has_changed() and Form.changed_data, which are undocumented, work as expected?
- [Django]-How do I get the class of a object within a Django template?
- [Django]-Django database query: How to get object by id?