views:

18

answers:

0

I need to localize a django project, but keep one of the applications (the blog) English only.

I wrote this middleware in order to achieve this:

from django.conf import settings
from django.core.urlresolvers import resolve

class DelocalizeMiddleware:
    def process_request(self, request):
        current_app_name = __name__.split('.')[-2]
        match = resolve(request.path)
        if match.app_name == current_app_name:
            request.LANGUAGE_CODE = settings.LANGUAGE_CODE

Problem is, it assumes the middleware lies directly in the application module (e.g. blog/middleware.py) for retrieving the app name. Other projects might have the middleware in blog/middleware/delocalize.py or something else altogether.

What's the best way to retrieve the name of the currently running app?