<p>If someone still is looking for an answer:</p>

<pre><code>{% block locale__switch %}
    {# Loop through all of the site locales #}
    {% set otherLocales = craft.i18n.getSiteLocaleIds() %}

    {% for locale in otherLocales %}

        {# Check if site is category or Entry #}
        {% if category is defined %}
            {% set siteLocale = category.locale(locale) %}
        {% elseif entry is defined %}
            {% set siteLocale = craft.entries.id(entry.id).locale(locale).first %}
        {% endif %}

        {# Make sure that it's actually localized to this locale #}
        {% if siteLocale.locale == locale %}

            {# Output a link to it #}
            &lt;a href="{{ siteLocale.getUrl() }}" class="text-uppercase {% if craft.locale == siteLocale.locale %}active{% endif %}"&gt;{{ locale }}&lt;/a&gt;{% if not loop.last %} |{% endif %}
        {% else %}

            {# Output a link to the hompage #}
            &lt;a href="{{ craft.config.siteUrl[locale] }}"&gt;{{ locale }}&lt;/a&gt;
        {% endif %}
    {% endfor %}
{% endblock %}
</code></pre>

CC BY-SA 3.0
2017-03-29T11:54:39.893Z
2017-03-29T15:16:04.543Z
2017-03-29T15:16:04.543Z
Michael Moser
<p>I am using Lindsey's <a href="https://github.com/lindseydiloreto/craft-languagelink" rel="nofollow">Language Link</a> plugin for my language switcher.</p>

<p>Everything works well, as long as the url is not a category url.</p>

<p>Here it is:</p>

<pre><code>{% set element = (entry is defined ? entry : null) %}

{% for locale in craft.i18n.getSiteLocales %}
    &lt;a href="{{ ll(locale.id, element) }}" class="dropdown-item"&gt;{{ locale.nativeName|capitalize }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>Where can I tell Craft to used the translated slug in my language switcher?</p>

<categories><localization>
Localization with categories
# Localization with categories

(Asked by: username_0 on 2016-05-11)

I am using Lindsey's Language Link plugin for my language switcher.
Everything works well, as long as the url is not a category url.
Here it is:
{% set element = (entry is defined ? entry : null) %}

{% for locale in craft.i18n.getSiteLocales %}
    {{ locale.nativeName|capitalize }}
{% endfor %}

Where can I tell Craft to used the translated slug in my language switcher?

**Tags:** categories, localization


---

## 1 answers

### Answer by username_1 on 2017-03-29. Score: 1

If someone still is looking for an answer:
{% block locale__switch %}
    {# Loop through all of the site locales #}
    {% set otherLocales = craft.i18n.getSiteLocaleIds() %}

    {% for locale in otherLocales %}

        {# Check if site is category or Entry #}
        {% if category is defined %}
            {% set siteLocale = category.locale(locale) %}
        {% elseif entry is defined %}
            {% set siteLocale = craft.entries.id(entry.id).locale(locale).first %}
        {% endif %}

        {# Make sure that it's actually localized to this locale #}
        {% if siteLocale.locale == locale %}

            {# Output a link to it #}
            {{ locale }}{% if not loop.last %} |{% endif %}
        {% else %}

            {# Output a link to the hompage #}
            {{ locale }}
        {% endif %}
    {% endfor %}
{% endblock %}


---

