Changing language by request.LANGUAGE_CODE

82 views
Skip to first unread message

Dmitry A. Erokhin

unread,
Feb 16, 2010, 6:34:21 PM2/16/10
to django-multilingual
What is the correct way to switch language in multilingual?

Only by invoking multilingual.languages.set_default_language() or
there is ability to make it automaticly by default django's
"request.LANGUAGE_CODE".

I'm trying to grow friendship between multilingual and localeurl.
Localeurl changing LANGUAGE_CODE and I want it to cause multilingual
language switching too.

Two hours of multilingual code inspecting brings zero results. :)

Thanks.

Dmitry A. Erokhin

unread,
Feb 17, 2010, 6:39:19 AM2/17/10
to django-multilingual
Like a temporarily solutinon I've added some cheat code to loacaleurl
middleware:


class LocaleURLMiddleware(object):

def __init__(self):
# ========<some code missed here>============
if "multilingual" in settings.INSTALLED_APPS:
try:
self.switch_ml = settings.ALLOW_LOCALEURL #settings
variable to turn on/off feature
except:
self.switch_ml = False #False by deafault
if self.switch_ml:
from multilingual.languages import set_default_language
self.ml_switch_lang=set_default_language


def process_request(self, request):
# ==========<some code missed here>============
if self.switch_ml:
self.ml_switch_lang(request.LANGUAGE_CODE)


It's working now, bu it's a "dirty hack".

Still looking for "nice and simple" solution... :-)

qrilka

unread,
Feb 23, 2010, 8:27:03 AM2/23/10
to django-multilingual
I think multilingual.middleware.DefaultLanguageMiddleware is supposed
to do the switching but I could not get it working :(

Kind regards,
Kirill Zaborsky

On Feb 17, 2:39 pm, "Dmitry A. Erokhin" <dmitry.erok...@gmail.com>
wrote:

Dmitry A. Erokhin

unread,
Feb 24, 2010, 5:27:19 AM2/24/10
to django-multilingual

On 23 фев, 16:27, qrilka <qri...@gmail.com> wrote:
> I think multilingual.middleware.DefaultLanguageMiddleware is supposed
> to do the switching but I could not get it working :(
>
> Kind regards,
> Kirill Zaborsky

Thanks a lot, Kirill!

It works fine now without any hacks. :)

I haven't read about middleware in docs – stupid mistake, I know...

Reply all
Reply to author
Forward
0 new messages