#Django-admin makemessages -a

40 messages · Page 1 of 1 (latest)

zinc steeple
#

Hello,
Not something important, but I wonder why the command

python manage.py makemessages -a

never works for me.

E.g. I have two locales defined: en and fr.
I always need to update them explicitly:

python manage.py makemessages -l en -l fr

as the --all option never works for me.
Does anyone have an idea why?

This is my relevant part of settings.py:

LOCALE_PATHS = (
    os.path.join(BASE_DIR, "locale"),
)

Do I need another setting for -all to work?

Thank you.

mint geyser
#

Where are the locals defined?

zinc steeple
mint geyser
#

And in settings?

zinc steeple
mint geyser
#

I may be wrong (not used it much) but i am pretty sure you need to configure what locals to use/make in the Django settings as well?

mint geyser
#

Looks like i was wrong 🤔

#

All paths listed in LOCALE_PATHS in your settings file are searched for <language>/LC_MESSAGES/django.(po|mo)

#

compilemessages apparently does not have "all" but must be called slike this 🤔

You can also run django-admin compilemessages --settings=path.to.settings to make the compiler process all the directories in your LOCALE_PATHS setting

#

For makemessages it confusingly says

This command doesn’t require configured settings. However, when settings aren’t configured, the command can’t ignore the MEDIA_ROOT and STATIC_ROOT directories or include LOCALE_PATHS.

But if you run it through manage.py, settings should be set?

#

This is how it finds locals

all_locales = [
            lang_code
            for lang_code in map(os.path.basename, locale_dirs)
            if looks_like_locale.match(lang_code)
        ]
#

But it looks like it might only look in "default_locale_path" ?

#

Does it change if you change LOCALE_PATHS from a tuple to a list?

#

default_locale_path should be set to the first value in LOCALE_PATHS when settings are loaded

mint geyser
#

Yeah

#

Looks like that might be ot

#

Of it does x[0] of a single-item tuple, it will only get the first character

#

While a list will get the first whole item in the list

#

@zinc steeple

zinc steeple
mint geyser
#

No 😅

#

You need to make LOCALE_PATHS a list, not a tuple as you have now.

#

[ ] vs ( )

#

Pretty sure this is your problem.

#

No wait, hmmm.

#

You have a comma after the os.join ....

#

So it should not be that either 🤔

#

Just make it a list for safety and test again?

zinc steeple
#

Not sure why that is a problem, there is only one element in the list

zinc steeple
mint geyser
#

Could you share a tree view of your folders?

zinc steeple
#

Hum, can't share screenshots it seems

mint geyser
#

No, unfortunately people keep sharing code as pictures and not text for some reason. If you feel it would be useful to share an image you can use i.e. imgur.com

zinc steeple
#

basically:

  • app
    • locale
      • en
        • LC_MESSAGES
    • migrations
    • templates
    • etc...
mint geyser
#

But that is not the path you have in settings?

#

It would look for a locale-folder at the same level as manage.py?

zinc steeple
#

There is also a locale folder at the root, but it's not used. I don't know why -l en uses app folder and -a seems to ignore them.

mint geyser
#

Try to make the locale dirs and see if all works?

zinc steeple
#

It shouldn't be necessary to add the app folders accoring to the doc:

  1. The directories listed in LOCALE_PATHS have the highest precedence, with the ones appearing first having higher precedence than the ones appearing later.

  2. Then, it looks for and uses if it exists a locale directory in each of the installed apps listed in INSTALLED_APPS. The ones appearing first have higher precedence than the ones appearing later.

  3. Finally, the Django-provided base translation in django/conf/locale is used as a fallback.