Language switcher: only show published translation page

SOLVE
KLi4
Member

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

Accepted Solutions
Indra
Solution
Top Contributor | Diamond Partner

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 #}

Bureau Vet

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

View solution in original post

2 Replies 2
dennisedson
Community Manager

@Anton , how do you deal with this?

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
Indra
Solution
Top Contributor | Diamond Partner

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 #}

Bureau Vet

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

View solution in original post