Ali Farhoudi
Ali Farhoudi

Reputation: 6020

How to activate translation for all management commands by default?

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.

Upvotes: 0

Views: 141

Answers (1)

Ali Farhoudi
Ali Farhoudi

Reputation: 6020

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.

Upvotes: 0

Related Questions