Django switching, for a block of code, switch the language so translations are done in one language

后端 未结 5 1230
野性不改
野性不改 2020-12-08 16:09

I have a django project that uses a worker process that sends emails to users. The worker processes listens to a rabbitmq server and gets all the details about the email to

5条回答
  •  醉梦人生
    2020-12-08 16:56

    Turns out the django docs explain how:

    While Django provides a rich set of i18n tools for use in views and templates, it does not restrict the usage to Django-specific code. The Django translation mechanisms can be used to translate arbitrary texts to any language that is supported by Django (as long as an appropriate translation catalog exists, of course). You can load a translation catalog, activate it and translate text to language of your choice, but remember to switch back to original language, as activating a translation catalog is done on per-thread basis and such change will affect code running in the same thread.

提交回复
热议问题