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

前端 未结 3 1214
终归单人心
终归单人心 2021-02-03 16:45

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 re

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-03 17:18

    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 
    

    … 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.

提交回复
热议问题