i18n_patterns and django-distill
Closed this issue · 7 comments
Hi,
I'm trying to use django-distill on my website that uses the function django.conf.urls.i18n.i18n_patterns
to generate language dependent urls.
I got the exception django.core.exceptions.ImproperlyConfigured: Using i18n_patterns in an included URLconf is not allowed.
that is raised by the django.conf.urls.include
function. This is called in django-distill.renderer.load_urls
.
Actually, I don't really understand what is the purpose of the call to the include
command in load_urls
since the result it returns is not used. As a matter of fact, everything seems to work well if I comment out this line in renderer.py
Is there a more suitable way to make this work ?
Best regards
The use of django.conf.urls.include(...)
in load_urls()
is to match Django's handling of URLs as URL patterns in path(...)
can include other applications URLs. The return value isn't required to be processed. Without calling this django-distill
would be unable to properly render nested URL paths.
Likely the best you can hope for when using i18n_patterns
is probably that django-distill
just renders the site once as the default settings.LANGUAGE_CODE
. As django-distill
just outputs what the browser would request with no cookies or dynamic information available it's not going to call translation.activate(...)
to switch the language or anything.
Do your i18n URLs work without django-distill
, just in a browser? Do you have the required middleware added for translations? If the i18n URLs do work without django-distill
can you give me as specific minimal example where this error is raised?
The use of
django.conf.urls.include(...)
inload_urls()
is to match Django's handling of URLs as URL patterns inpath(...)
can include other applications URLs. The return value isn't required to be processed. Without calling thisdjango-distill
would be unable to properly render nested URL paths.
Thanks for the explanation.
Likely the best you can hope for when using
i18n_patterns
is probably thatdjango-distill
just renders the site once as the defaultsettings.LANGUAGE_CODE
. Asdjango-distill
just outputs what the browser would request with no cookies or dynamic information available it's not going to calltranslation.activate(...)
to switch the language or anything.
Yes of course. This is exactly what I would like.
Do your i18n URLs work without
django-distill
, just in a browser? Do you have the required middleware added for translations?
Yes it works perfectly.
If the i18n URLs do work without
django-distill
can you give me as specific minimal example where this error is raised?
OK, i'll try to do this
Here is a very minimal example of the issue I described above :
https://github.com/FranckBoyer/test_distill_i18n
Perfect, thanks. I'll check that out when I get a moment. If this is an issue in distill it'll likely be to do with something like load ordering the middleware or some other similar load-related issue. Having the test framework match a live, real request requires quite a bit of tweaking.
Ah right, found the issue which is kind of obvious when I think about it. The i18n language prefixes are only available on the root URLs which makes sense. I was using a shortcut by just "including" the whole URL tree to load all the metadata, which works fine, apart from if a component checks to see if it's the root URL or not which i18n_patterns does. I'll need to modify the load_urls()
helper to be a bit more intelligent to to allow this to work.
any progress here? I ran into the same issue.
Thanks for looking into it!
Or any workaround?
Yep, had some time to finally look at this. The above patch which should fix this will be in the next release.