class ForceDefaultLanguageMiddleware(object):
"""
Ignore Accept-Language HTTP headers
This will force the I18N machinery to always choose settings.LANGUAGE_CODE
as the default initial language, unless another one is set via sessions or cookies
Should be installed *before* any middleware that checks request.META['HTTP_ACCEPT_LANGUAGE'],
namely django.middleware.locale.LocaleMiddleware
"""
def process_request(self, request):
if request.META.has_key('HTTP_ACCEPT_LANGUAGE'):
del request.META['HTTP_ACCEPT_LANGUAGE']
Comments
You could just disable the
LocaleMiddleware... :)#
Oops, I was afraid I wouldn't be clear, and I guess I was right :)
I need LocaleMiddleware because I do want a multingual website , BUT I also want one of the languages to be the default one for all visitors, whatever their browser preferences are, until said visitors explicitly choose a different language via a menu provided by my site. That is, unless a cookie or session setting has been set.
I'll explain my case, with some background, if you are curious ;).
In Galicia we have two official languages: Galician and Spanish. Galician is spoken by most people here but, due to several reasons, software localized to Galician is scarce. So virtually anyone will use the Spanish version of their browser of choice which, of course, will come preconfigured with Spanish as the preferred accept-language.
Now, most people don't even know that such configuration option exists and will expect certain bilingual Galician/Spanish websites to be in Galician by default (for example, sites from the Galician government), and will find it very weird otherwise.
#
hi fonso,
i see the same problem as you do.
i´ve changed the locale middleware to this to have my default language set:
#
hi jefferson,
Yes, AFAIK, if your settings.LANGUAGE_CODE is 'de', the posted middleware would have exactly the same effect your changes do.
#
Disabling LocaleMiddleware does not help. The goal here is to ignore HTTP Accept-Language headers, and choose the default language which is defined in settings.py After that user should be able to still change his language, if he wants to
This middle ware does exactly what we need. Thanks alot!
#