djangodjango-viewsdjango-multilingual

How to retrieve language settings from within view?


I want to set up a very small site in three different languages.

Basically I want to use a single view that sends back different data to the same template dependent on the selected language (all data is in one table anyway).

I just read through the internationalization documentation which gives a good overview but I still don't really get how to render the right kind of content based on a selected language. It seems as if I can extract this information with the requestcontext class but how exactly? Or am I over complicating things? Can somebody provide a good example?


Solution

  • This should do the trick

    from django.utils import translation
    language= translation.get_language_from_request(request)
    translation.activate(language)
    

    And maybe this answer could help you, too.