CMS Development

KLi4
Member

Language switcher: only show published translation page

SOLVE

I’ve a a custom language switcher on a blog. Currently it shows me all language options, even the ones which are in draft, not published yet. So this language option should not be displayed. 

Is there a way to only display the language options which are published?

0 Upvotes
1 Accepted solution
Indra
Solution
Guide | Elite Partner
Guide | Elite Partner

Language switcher: only show published translation page

SOLVE

Hi @KLi4,

 

There is a bug inside HubSpot multilanguage switcher so they have created a fix for it. So you need to update your code for it.

 

You need to add a extra condition to it like this:

{% if content.translated_content.values()|selectattr('published')|length || is_listing_view && group.translations %}
{% endif %}

 

You can find the original code on the developers documentation for Multi-language Content.

 

Your new code should look like this.

{# Header navigation row one #}
      <div class="header__row-1">
        {% if content.translated_content.values()|selectattr('published')|length || is_listing_view && group.translations %}
          <div class="header__language-switcher header--element">
            <div class="header__language-switcher--label">
              {% module 'language-switcher' path='@hubspot/language_switcher',
                label='Language switcher',
                display_mode='localized'
              %}
              <div class="header__language-switcher--label-current"> {{ locale_name(locale) }}</div>
            </div>
          </div>
        {% endif %}
        <div class="header__search header--element">
          {% module 'site_search' path='@hubspot/search_input',
            label='Search',
            field_label='Search',
            placeholder=''
          %}
        </div>
      </div>
      {# End header navigation row one #}

Vet Digital - The Growth Agency | HubSpot Solutions Partner Agency

Did my post solve your question? Help the community by marking it as a solution

View solution in original post

2 Replies 2
Indra
Solution
Guide | Elite Partner
Guide | Elite Partner

Language switcher: only show published translation page

SOLVE

Hi @KLi4,

 

There is a bug inside HubSpot multilanguage switcher so they have created a fix for it. So you need to update your code for it.

 

You need to add a extra condition to it like this:

{% if content.translated_content.values()|selectattr('published')|length || is_listing_view && group.translations %}
{% endif %}

 

You can find the original code on the developers documentation for Multi-language Content.

 

Your new code should look like this.

{# Header navigation row one #}
      <div class="header__row-1">
        {% if content.translated_content.values()|selectattr('published')|length || is_listing_view && group.translations %}
          <div class="header__language-switcher header--element">
            <div class="header__language-switcher--label">
              {% module 'language-switcher' path='@hubspot/language_switcher',
                label='Language switcher',
                display_mode='localized'
              %}
              <div class="header__language-switcher--label-current"> {{ locale_name(locale) }}</div>
            </div>
          </div>
        {% endif %}
        <div class="header__search header--element">
          {% module 'site_search' path='@hubspot/search_input',
            label='Search',
            field_label='Search',
            placeholder=''
          %}
        </div>
      </div>
      {# End header navigation row one #}

Vet Digital - The Growth Agency | HubSpot Solutions Partner Agency

Did my post solve your question? Help the community by marking it as a solution
dennisedson
HubSpot Product Team
HubSpot Product Team

Language switcher: only show published translation page

SOLVE

@Anton , how do you deal with this?

0 Upvotes