Created
November 3, 2012 07:01
-
-
Save naiquevin/4006363 to your computer and use it in GitHub Desktop.
Examples for i18n using Django middleware blog post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatLocaleMiddleware(object): | |
def process_request(self, request): | |
if request.path in ['/jsi18n/']: | |
return None | |
match = SHOPPER_CHAT_PATH.match(request.path) | |
if match is not None: | |
appid = match.groups()[0] | |
try: | |
store = Store.objects.get(appid=appid) | |
except Store.DoesNotExist: | |
return HttpResponse(status=404) | |
customizations = get_customizations(store) | |
request.session['django_language'] = customizations['language'] | |
request.store = store | |
request.customizations = customizations | |
else: | |
request.session['django_language'] = settings.LANGUAGE_CODE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIDDLEWARE_CLASSES = ( | |
# ... | |
'shopper.middleware.ChatLocaleMiddleware', | |
'django.middleware.locale.LocaleMiddleware', | |
# ... | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def chat(request, appid): | |
store = get_object_or_404(Store, appid=appid) | |
customizations = get_customization(store) | |
request.session['django_language'] = customizations['language'] | |
# ... | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment