Hello guys,
I have done a bit more search and I found this:
http://www.jondesign.net/articles/2006/jul/02/langue-depuis-url-django-url-locale-middleware/
This partly solve the issue I was describing, language code in the
URL.
I would be glad if you could let me know what is your opinion about
it.
"""
from django.utils.cache import patch_vary_headers
from django.utils import translation
class MultilingualURLMiddleware:
def get_language_from_request (self,request):
from django.conf import settings
import re
supported = dict(settings.LANGUAGES)
lang = settings.LANGUAGE_CODE[:2]
check = re.match(r"/(\w\w)/.*", request.path)
changed = False
if check is not None:
request.path = request.path[3:]
t = check.group(1)
if t in supported:
lang = t
if hasattr(request, "session"):
request.session["django_language"] = lang
else:
response.set_cookie("django_language", lang)
changed = True
if not changed:
if hasattr(request, "session"):
lang = request.session.get("django_language", None)
if lang in supported and lang is not None:
return lang
else:
lang = request.COOKIES.get("django_language", None)
if lang in supported and lang is not None:
return lang
return lang
def process_request(self, request):
from django.conf import settings
language = self.get_language_from_request(request)
if language is None:
language = settings.LANGUAGE_CODE[:2]
translation.activate(language)
request.LANGUAGE_CODE = translation.get_language()
def process_response(self, request, response):
patch_vary_headers(response, ("Accept-Language",))
translation.deactivate()
return response
""""
thank you
On 6 déc, 18:33, yml <
yann.ma...@gmail.com> wrote:
> Hello,
> I also believe that we need some how to mark the xml:lang in the
> template. I am new to the concept of multilanguage public web site.
> For instance I have a web sitehttp://yml.alwaysdata.comwhere some