Hi,
I created a multi lingual site in Django 1.7.1 where the user can change
the language by means of a dropdown menu at the top of the site.
The urls are www.site.com/page. The page view checks the language, and
then loads the correct templates which are named the same as the page.
The template is in a directory of its own and to find it, I only need to
do this: template = 'template_subdir/{}.html'.format(page)
This works great but might be a bit less useful when trying to refer
people to an url in a different language.
To that end I've created an additional function that first checks for a
language in the url, then calls the original page function.
urls.py:
...
url(r'^(?P.*)/(?P[-\w\d]+)$',
'main.views.page_lang',name='page_lang'),
url(r'^(?P[-\w\d]+)$', 'main.views.page',name='page'),
...
views.py
def page_lang(request, language, thepage):
# Set the language
check_for_language(language)
activate(language)
request.session['django_language'] = language
# Next load the page
return page(request, thepage)
def page(request, page):
...
This allows reconstruction of the url but only the current page. If you
click another page, the language is still changed but the language is not
added to the url as expected. There are a couple of questions remaining:
- When dealing with multilingual sites, is it better to deal with an url
with or without the language or both? Without makes the url shorter and
clean, with makes it more accessible. I'm leaning toward the latter.
- I thought of using language prefix but the prefix argument to
i18_patterns() is deprecated in v1.8 and I'm not going to add a feature I
know is changing in the near future. There is a reference to
django.conf.urls.url() but it's not clear to me on how the proceed with
this to add the language part in front of my url's.
Thanks for any info regarding this matter,
Regards,
Benedict
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/ml8oaf%24ukb%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.