views:

38

answers:

2

I am using django-localeurl to change the language of a project based on a suffix after the domain (example.com/en , example.com/hu etc). However I also have subdomains for the countries which are exactly the same as the suffixes.

How can I modify the locale-url or add another filter to the links so that I could change the suffix and subdomain at the same time?

f.e.

example.com -> hu.example.com/hu -> es.example.com/es etc.

Here there is the localeurl chlocale function:

def chlocale(url, locale):
    """
    Changes the URL's locale prefix if the path is not locale-independent.
    Otherwise removes locale prefix.
    """
    _, path = utils.strip_script_prefix(url)
    _, path = utils.strip_path(path)
    return utils.locale_url(path, locale)

chlocale = stringfilter(chlocale)
register.filter('chlocale', chlocale) 

That's my call as URL href:

<a href="{{ request.path|chlocale:"hu" }}">Hungary</a>
A: 

This one actually returns only the relative path not the http full address of the webpage, so it's OK to attach prefix http://sitename.domain at the beginning before the {{ request.path... }} call.

Mario Peshev
A: 

domain = Site.objects.get_current().domain

  <a href="http://hu.{{ domain }}{{ request.path|chlocale:"hu" }}">Hungary</a>

A little hacky but perhaps what you are looking for.

skyl