infoportugal / wagtail-modeltranslation

Simple app to patch modeltranslation (https://github.com/deschler/django-modeltranslation) into Wagtail CMS.
151 stars 119 forks source link

change_lang returns None #13

Closed arjanvaneersel closed 9 years ago

arjanvaneersel commented 9 years ago

I'm using the wagtail demo and I have made the HomePage translatable according your instructions. In the admin this works fine.

Now I amended the home_page.html template with this:

{% load modeltranslation %}
<li class="dropdown">
    <a data-toggle="dropdown" class="dropdown-toggle" data-hover="dropdown" href="#">{{     LANGUAGE_CODE }}<i class="fa fa-angle-down ml5"></i></a>
    <ul class="dropdown-menu" id="language-dropdown">
        {% for lang in languages %}
            {% if lang.0 != LANGUAGE_CODE %}
                <li tabindex="-1"><a href="{% change_lang lang.0 %}">{{ lang.1 }}</a></li>
            {% endif %}
        {% endfor %}
   </ul>
</li>

To make sure that languages has a value I wrote a tiny context processor:

from django.conf import settings

def languages(request):

    return {'languages': settings.LANGUAGES}

And settings.LANGUAGES is defined like this (in compliance with the instructions from django-model-translation): gettext = lambda s: s LANGUAGES = ( ('en', gettext('English')), ('nl', gettext('Dutch')), ('bg', gettext('Bulgarian')), )

Unfortunately this doesn't seem the way to do it, because the returned urls are None, for example:

<li tabindex="-1"><a href="None">Dutch</a></li>
<li tabindex="-1"><a href="None">Bulgarian</a></li>

What am I doing wrong?

rmartins90 commented 9 years ago

Hi ArieVanE, we've been very busy, we just released a new version with support for StreamFields, and fix some small issues. We'll look at your problem very soon.

pymarco commented 9 years ago

ArieVanE, your context processor is unneeded. In your template you can use

{% load i18n %}
{% get_available_languages as LANGUAGES %}
{% get_current_language as LANGUAGE_CODE %}

But how to switch languages as you are trying to do is something I am yet to learn. Hopefully soon though

pymarco commented 9 years ago

ArieVanE, to switch languages from a dropdown you can follow the tutorial at this link. It worked for me.

http://machakux.appspot.com/blog/17010/django_using_i18n_patterns_and_locale_switcher

rmartins90 commented 9 years ago

This was fixed here https://github.com/infoportugal/wagtail-modeltranslation/pull/32