ziowik
ziowik

Reputation: 23

How to hide an untranslated page from language chooser in django cms?

I want to hide an untranslated page from the language chooser in django cms so that the language chooser shows only the languages that have translations for that page. How can I do that?

One idea is to extend the language chooser template and check there if the language has a translated page but I couldn't find out how to do that.

Upvotes: 2

Views: 568

Answers (2)

Mario
Mario

Reputation: 2639

Actually there is a beautiful solution, first posted here: https://groups.google.com/forum/#!topic/django-cms/z1rdf4C-ltQ

current_page.get_languages is the solution. Works with djangocms 3 in my Aldryn project.

includes/menu/langnav.html:

{% load i18n menu_tags %}
{% if languages|length > 1 %}

{% comment %}
    This is awesome: https://groups.google.com/forum/#!topic/django-cms/z1rdf4C-ltQ
{% endcomment %}

<li class="lang">
    {% for language in current_page.get_languages %}
        <a class="{{ language }}{% ifequal current_language language %} selected{% endifequal %}"
           href="{% page_language_url language %}">{{ language }}</a>
    {% endfor %}
</li>
{% endif %}

Upvotes: 2

digi604
digi604

Reputation: 1090

in django cms 3.0:

{% if page and language in page.languages %}

for 2.4:

you probably will a custom filter or templatetag that runs::

if page.title_set.filter(language=lang).count():
    return True
else:
    return False

Upvotes: 1

Related Questions