I'm working on the language switcher and have it working. The only thing is I want it to pull from group data-id=1 It's pulling from all sites because of the i18n to change the language name to it's native name.

I made a "disabled" group in Craft CMS 3 and put Russian in it and it shows up with i18n. I had it working before by only the 2 letter abbreviation showed such as "de" instead of Deutsch and Russian didn't show.

<div class="language-menu" aria-labelledby="navbarDropdownMenuLink" id="language-menu">
{% set currentSite = craft.app.sites.currentSite %}
{% for siteInGroup in currentSite.getGroup.getSites() %}
   {% if siteInGroup.id == entry.siteId %}
      {% for locale in craft.i18n.getSiteLocales() %}
        <a href="{{ entryForOtherSite.getUrl() }}">{{ locale.getDisplayName() }}</a>
   {% else %}
      {% set entryForOtherSite = craft.entries.id(entry.id).site(siteInGroup).one() %}
        <a href="{{ entryForOtherSite.getUrl() }}">{{ locale.getDisplayName(siteInGroup.language) }}</a>
      {% endfor %}
   {% endif %}
{% endfor %}
</div>

I figured it out:

    {% set currentSite = craft.app.sites.currentSite %}
{% for siteInGroup in currentSite.getGroup.getSites() %}
   {% if siteInGroup.id == entry.siteId %}
        <a href="{{ entryForOtherSite.getUrl() }}">{{ locale.getDisplayName() }}</a>
   {% else %}
      {% set entryForOtherSite = craft.entries.id(entry.id).site(siteInGroup).one() %}
      {% set locale = craft.i18n.getLocaleById(siteInGroup.language) %}
        <a href="{{ entryForOtherSite.getUrl() }}">{{ locale.getDisplayName(siteInGroup.language) }}</a>
   {% endif %}
{% endfor %}
  • Sorry, but I'm not following... what's the issue you're having and what's the behavior you're looking for? What is group and data-id=1? – Brad Bell Nov 8 at 20:17
  • I have two site groups (disabled and live) and just want to show the live group on the language menu. – Nick Nov 8 at 20:37
  • I figured it out – Nick Nov 8 at 21:33
  • Awesome! Would you mind adding your solution as an official answer? – Brad Bell Nov 8 at 21:42

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.