Ignas Butėnas
Ignas Butėnas

Reputation: 6307

Multilanguage Django website with custom URLs

I'm stuck a little and need your advices guys... I'm creating the website which will be translated in two languages. For example I have two urls /gallery/pictures and /galerija/paveikslai (these are the same but different languages) which points to the same content (for example will show gallery of paintings).

Of course depending on the link it should change the language of the content and the page itself. Any ideas how to do it better? Maybe I need to use the language prefix? If yes, how then I will deal with it (middleware or something)?

Maybe someone already did the same and has some nice advices or code to show?

Thanks, Ignas

Upvotes: 2

Views: 1123

Answers (1)

wtrevino
wtrevino

Reputation: 4861

Perhaps something like this:

settings.py:

from django.utils.translation import ugettext_lazy as _

GALLERY_URL = _('gallery')
PICTURES_URL = _('pictures')

urls.py:

url(r'^'+settings.GALLERY_URL+'/'+settings.PICTURES_URL+'/$',
    'my_view',         
    name='my_view'),

You should somehow validate that GALLERY_URL and PICTURES_URL are not empty.

Upvotes: 1

Related Questions