I am developing a website using Django Mezzanine.
I have some pages using a model derived from Mezzanine Page model with translatable fields (using i18n) and this works.
However I have some pages relative to some events in given countries, so they are only in one language, and they use a model derived from Mezzanine Displayable model, without translatable fields but a language attribute.
In the list I tried to put links including the language of the page (like /en/events/event/eventslug ).
I tried to add translation.activate(lang_code)
to the view.
This way I get the page in the wanted language (I use {% trans %}
template tags).
The problem comes when I visit the page from another language (for example if I am on the filter page in Spanish and go to an English event). Then the language switch (mezzanine form sending a POST request to /i18n/) doesn't work any more (I am locked in English) The switch still work in private navigation for example as long as I don't visit one of this pages from another language.
How can I fix this? I am out of ideas as of why...
Update: I changed the urlpattern so it is not i18n anymore (I think it makes more sense) but as I still need translation.activate(lang_code)
for the {% trans %}
tags my problem is still the same.
The problem came from the fact that if you use translation.activate(language)
then you need to use translation.deactivate()
.
So that would have required the use of a middleware to make it work properly.
However I found the i18next module allowing to override the locale in the template, so I defined the context 'lang_code' in my view and used {% overridelocale lang_code %}
in my template.