{% set otherLocales = craft.i18n.getSiteLocaleIds() %}
<li class="languageSwitch">
  {% for locale in otherLocales %}
      {% set localeEntry = craft.entries.id(entry.id).locale(locale).first %}
      {% if localeEntry.locale is defined and localeEntry.locale == locale %}
          <a href="{{ localeEntry.getUrl() }}" class="{% if craft.i18n.getCurrentLocale() == locale %}active{% endif %}">{{ locale }}x</a>
      {% else %}
          <a href="{{ craft.config.siteUrl[locale] }}" class="{% if craft.i18n.getCurrentLocale() == locale %}active{% endif %}">{{ locale }}</a>
      {% endif %}
  {% endfor %}
</li>
          Created
          February 21, 2018 13:56 
        
      - 
      
 - 
        
Save kaspar-allenbach/ab26a5783fe2d79bbb25b2ee9c6d2ba4 to your computer and use it in GitHub Desktop.  
    Craft CMS Language Switcher
  
        
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment