I have a django project that makes use of django-celery-beat and redis to make use of asynchronous messages. This is especially useful for handling sending many emails (for example, if an admin clicks a button, hundreds of emails have to be sent, without using celery/redis, this would take quite some time).
It's almost the same for browser-notifications. I have set up a few cron tasks that fire notifications to useres depending on various variables.
This all works fine, however, I am unable to find an elegant way for localizing the emails/notifications.
I am somewhat familiar with how internationalization works within django, and for localizing direct responses and error messages, I am sending the accept-language flag (based on the current browser language) from my (angular) frontend. Django respects this (according to the docs) and this is working fine.
However, when dealing with async tasks, there is no such thing as a request where django can look for a preferred language. When sending emails, I could pass the language from the accept-language field on to my async function, by setting the language within my function manually for each user (docs).
This wont work for notifications, as they are sent by a cron job, so there is no response where I could get the preferred language to begin with.
The only idea I could come up with is adding a language field to my User model. Upon registration (or by some other logic), this field is set to the preferred lanuage, and from within my async function, I can determine the target language from that field. However, that seems not to be too elegant, and I was wondering if there is anything that I am missing.
Is there really no other way for that?