Middleware to set_default_language

1 view
Skip to first unread message

Joost Cassee

unread,
May 30, 2008, 9:57:22 AM5/30/08
to django-mu...@googlegroups.com
Hi all,


It has been discussed on this list earlier: automatically calling
set_default_language. However, I feel that all proposed solutions try to
solve two problems: 1) discovering the default language and 2) setting it.

I propose that DM should only be concerned with the second part of the
problem. In that line I propose to add an extremely simple middleware
module to the DM source:

middleware.py:
---
import multilingual

class DefaultLanguageMiddleware(object):
def process_request(self, request):
# Set the default language for model fields
multilingual.set_default_language(request.LANGUAGE_CODE)
---

This middleware works with any language discovery middleware, like
django.middleware.locale.LocaleMiddleware.

As for to getting the language from the URL (a solution to the first
part of the problem), I created a simple app, inspired by posts to this
list, that does just that. I will post another message soliciting comments.


Regards,

Joost

Panos Laganakos

unread,
Jun 16, 2008, 1:18:44 PM6/16/08
to django-mu...@googlegroups.com
Updated to the latest DM trunk, and installed the DefaultLanguage
middleware. Works like a charm, thanks :)

--
Panos Laganakos

Semmel

unread,
Jul 3, 2008, 10:21:13 AM7/3/08
to django-multilingual
Ah, great work. I always noticed the redundant set_default_language()
in all of my views but i never had the time to address this issue.
Thanks for this great yet simple middleware! Didn't thought that it
would be that easy anyway ... :)

Regards,
Flo
Reply all
Reply to author
Forward
0 new messages