
from django.conf import settings
from django.template import loader
from xadmin.plugins.utils import get_context_dict
from xadmin.sites import site
from xadmin.views import BaseAdminPlugin, CommAdminView


class SetLangNavPlugin(BaseAdminPlugin):

    def block_top_navmenu(self, context, nodes):
        context = get_context_dict(context)
        context['redirect_to'] = self.request.get_full_path()
        nodes.append(loader.render_to_string('xadmin/blocks/comm.top.setlang.html', context=context))

if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:
    site.register_plugin(SetLangNavPlugin, CommAdminView)
    site.register_view(r'^i18n/', lambda site: 'django.conf.urls.i18n', 'i18n')

@@ -62,16 +62,59 @@
  loader%0A
+from django.views.i18n import set_language%0A
 from xad
@@ -240,16 +240,31 @@
 dminView
+, BaseAdminView
 %0A%0A%0Aclass
@@ -558,16 +558,221 @@
 text))%0A%0A
+class SetLangView(BaseAdminView):%0A%0A    def post(self, request, *args, **kwargs):%0A        if 'nav_menu' in request.session:%0A            del request.session%5B'nav_menu'%5D%0A        return set_language(request)%0A%0A
 if setti
@@ -958,53 +958,45 @@
 18n/
-', lambda site: 'django.conf.urls.i18n', 'i18n
+setlang/$', SetLangView, 'set_language
 ')%0A

Clean session nav_menu cache when switch the language.