3

We have to create multi-regional and multilingual web site. For example:

For multiligual, django-cms and i18n_patterns handle it very well. But when I try to use django sites framework to add multi-regional support, it doesnot work as expected :(. I add site with subdomain: mysite.com/au , mysite.com/vn, mysite.com/us. In django-cms admin page I add content to site already. But now I don't know how to config url to match the site.

And I want to have http://mysite.com/<region>/<language>/ but i18n_patterns seem to force url like http://mysite.com/<language>/<region>/. How to change this also

Please help

James
  • 13,571
  • 6
  • 61
  • 83

2 Answers2

3

I'm not sure how flexible you are with your URL scheme, but how about this:

Use the standard django CMS i18n URL rules (so you end up with yoursite.com/ja/ and yoursite.com/en/).

Next create two pages: 'au' and 'jp'. Redirect the homepage to one of the two pages (or write some smarter logic for that, for example in a middleware). Now keep your regional content in those two sub trees.

Simply don't translate the pages in the 'au' subtree into Japanese if you don't want.

ojii
  • 4,729
  • 2
  • 23
  • 34
  • Your solution seem easier to implement, but then we have to change url to / and it somehow not what they asked. Thank your your solution. – James May 29 '13 at 02:38
  • So changing that requirement is not an option? How will the two regions differ? – ojii May 29 '13 at 04:13
  • That's client reequirement :( I think I must write a middleware to handle this. Thankyou anyway – James May 29 '13 at 05:00
  • Don't forget that a middleware won't suffice. You also need something like i18n_patterns to make reverse work. Good luck! – ojii May 29 '13 at 05:15
  • Yeah, middleware and custom i18n_patterns as well :( – James May 30 '13 at 03:27
  • your client should read iso standards and change his mind imho – user2298943 May 30 '13 at 21:46
1

You may make it, by writing your own copy of i18n_patterns.

So by definition:

Language prefix in URL patterns

i18n_patterns(*urls, prefix_default_language=True)[source]

This function can be used in a root URLconf and Django will automatically prepend the current active language code to all URL patterns defined within i18n_patterns().

Here an example made inside template but same variables/objects you need in your implementation.

Reversing in templates

If localized URLs get reversed in templates they always use the current language. To link to a URL in another language use the language template tag. It enables the given language in the enclosed template section:

{% load i18n %}

{% get_available_languages as languages %}

{% trans "View this category in:" %}
{% for lang_code, lang_name in languages %}
    {% language lang_code %}
    <a href="{% url 'category' slug=category.slug %}">{{ lang_name }}</a>
    {% endlanguage %}
{% endfor %}

The language tag expects the language code as the only argument.

Reference: Django docs - i18n/translation

user.dz
  • 962
  • 2
  • 19
  • 39