0

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?

Thomas Schwärzl
  • 9,518
  • 6
  • 43
  • 69
LarsVegas
  • 6,522
  • 10
  • 43
  • 67
  • Have you already gone through [how django detects language preference](https://docs.djangoproject.com/en/dev/topics/i18n/translation/#how-django-discovers-language-preference)? – Burhan Khalid Oct 22 '12 at 13:37
  • Thanks for the link Burhan, I must have missed this part. Just to make sure: if I use [redirect-view](https://docs.djangoproject.com/en/dev/topics/i18n/translation/#the-set-language-redirect-view) to set the user preference I'll be set with `request` functions within my view? – LarsVegas Oct 22 '12 at 13:49
  • Plus you should make sure you use request context (ie, use the [`render` shortcut](http://django.me/render) or CBV). – Burhan Khalid Oct 22 '12 at 13:51

1 Answers1

2

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.

Community
  • 1
  • 1
Thomas Schwärzl
  • 9,518
  • 6
  • 43
  • 69