Frage

I want to show only the items which have translations into a language, when this language is active. At the moment untranslated items are shown too. Is there such setting in django-modeltranslation or do I have to write something myself?

War es hilfreich?

Lösung

I've solved it myself:

In translation.py:

class MenuItemTranslationOptions(TranslationOptions):
fields = ('title',)
fallback_values = {
    'title': False,
}

In a template:

  {% if request.LANGUAGE_CODE == 'en' and item.title_en %}  #this checks if the item is translated into english          

        <li class="navig"><a href="{{ item.link }}">{{ item.title }} </a>
        </li>

        {% elif request.LANGUAGE_CODE == 'ru' %} #default language

           <li class="navig"><a href="{{ item.link }}">{{ item.title }} </a>
        </li>

        {% endif %}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top