How to activate translation for all management commands by default?

134 Views Asked by At

I need translation to be activated in all of my django management commands by default. Currently I'm putting this line of code in all my management commands:

translation.activate(settings.LANGUAGE_CODE)

And sometimes I forget to consider it in my command. I need it to send translated notifications. Is there any way to activate translation for all of management commands by default?
Any help is appreciated.

1

There are 1 best solutions below

0
Ali Farhoudi On

After looking into BaseCommand's source I figured out django is disabling translation and I could just prevent that by adding an attribute inside my Command class:

class CoreBaseCommand(BaseCommand):

    leave_locale_alone = True

I did put that line in my custom BaseCommand to be applied in all inherited commands.