set language within a django view

后端 未结 8 2118
暖寄归人
暖寄归人 2020-11-30 20:45

background: The view is called when a payment service pings back a payment outcome behind the scenes - afterwhich I need to send an email in the right langu

8条回答
  •  囚心锁ツ
    2020-11-30 21:29

    If just want to get the translated strings for a language for whatever reason, you can use override as a decorator like this:

    from django.utils import translation
    from django.utils.translation import ugettext as _
    
    with translation.override(language):
        welcome = _('welcome')
    

提交回复
热议问题