Django - Suffix all urls with language code -
i'm working on multilingual site want suffix urls current 2-character language code. if no language specified want default english.
for example:
mysite.com/
--> mysite.com/en
mysite.com/location
--> mysite.com/locations/en
mysite.com/ar
display arabic site
since don't want add (?p<language>[a-x]{2})$
urls i'm guessing should write middleware check suffix , strip out?
what's best way achieve this?
as indicated in comment @bogdan above resorted using built-in prefixing feature in django.
i added
localemiddleware
inmiddleware_classes
settingi added languages setting specify languages in site, in case english , arabic languages looked
languages = ( ('ar', _('arabic')), ('en', _('english')), )
in views used
request.language_code
access language code , display appropriate language in template
Comments
Post a Comment