Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Created November 3, 2012 07:01
Show Gist options
  • Save naiquevin/4006363 to your computer and use it in GitHub Desktop.
Save naiquevin/4006363 to your computer and use it in GitHub Desktop.
Examples for i18n using Django middleware blog post
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
MIDDLEWARE_CLASSES = (
# ...
'shopper.middleware.ChatLocaleMiddleware',
'django.middleware.locale.LocaleMiddleware',
# ...
)
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