Context specific localisation in Django

146 Views Asked by At

I have a Django application. Localising this into multiple languages is a simple and straightforward but one part of the site is an complex rich internet application. This part of the site allows the user to his workspace mode.

Everything remains the same but the terminology changes. e.g.

www.exmaple.com/myria/chemist
www.exmaple.com/myria/biologist
www.exmaple.com/myria/physicist

myria is my rich internet application. The words chemist, biologist and physicist merely denote the workspace. The whole Django application itselt uses the same codebase and nothing else changes.

I'm using django-rosetta to manage translating and django-localeurl to provide URL based locale switchin (on normal parts of the site).

I'm at my wits end on how to accomplish this. Maybe some kludging with the sites framework?

1

There are 1 best solutions below

0
On

Short answer: you don't need it. In most cases it's better to have latin chars in URL instead of something %%-escaped.

Long answer: DjangoCMS provides locale-dependent URL for each page. You can kludge something like:

from django.utils.translations import ugettext as _
from django import http
...
def myria_view(request, localized_workspace):
    my_workspaces = (
       (_('foo'), foo_view),
       (_('bar'), bar_view),
       (_('buz'), buz_view),
    )
    for ws in my_workspaces:
        if ws[0] == localized_workspace:
            return ws[1](request)
    raise http.Http404

but once again, don't do it. It's just so wrong

Update: Django does it out of the box https://docs.djangoproject.com/en/dev/topics/i18n/internationalization/#translating-url-patterns