简体   繁体   中英

Localization of Allauth emails

Allauth doc descibe how to customize emails ( here ).

Now, how can we make Allauth send an email depending of the current language preference?

Setup your own adapter:

ACCOUNT_ADAPTER = 'example.MyAdapter'

Then:

from django.utils import translation

class MyAdapter(DefaultAccountAdapter):

    def render_mail(self, template_prefix, email, context):
        # Set language, based on `email`, or `self.request.session`, or
        # whatever fits your project
        #
        # TODO: insert your logic here
        lang = 'nl'  

        with translation.override(lang):
             return super().render_mail(template_prefix, email, context)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM