django, change language settings dynamically

After some failed attempts, I just found how to change the language settings dynamically in django, and I thought it could be useful to someone. Just use function activate() from django.utils.translation. For example:

from django.utils.translation import activate

activate('es-ES')

will change global language settings to ‘es-ES’ (Spain spanish). I use it because I have two forms and I want that errors appear in different languages, but I do not want to get into gettext

8 Responses to “django, change language settings dynamically”

  1. Yury Lifshits
    February 16th, 2010 10:02
    1

    Thanks a lot!
    You prob

  2. Yury Lifshits
    February 16th, 2010 10:02
    2

    Thanks a lot, Fabian!!

    You probably saved me a few hours!!!

  3. Candy Harris
    March 6th, 2010 21:35
    3

    Thanks for this blog. I am new at development and this got me straight.

  4. Larry Henrie
    March 7th, 2010 01:25
    4

    This is great! Thanks for this blog. I am starting python and this will help a lot.

  5. Laveta Belko
    March 10th, 2010 13:40
    5

    For the reason that a Newbie I am incessantly scouring the web on the web to get this type of information .Thank you:P

  6. Jared
    May 21st, 2010 06:40
    6

    Fabian,
    Is there a way to set other Django settings dynamically, specifically I am looking to change the email_host? Thanks

  7. jenicek
    March 4th, 2011 16:01
    7

    God Bless You! Thx!

  8. green witch
    October 25th, 2011 14:12
    8

    Thanks a lot bro..