3

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 %}
    <a href="{{ ll(locale.id, element) }}" class="dropdown-item">{{ locale.nativeName|capitalize }}</a>
{% endfor %}

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

1 Answer 1

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 #}
            <a href="{{ siteLocale.getUrl() }}" class="text-uppercase {% if craft.locale == siteLocale.locale %}active{% endif %}">{{ locale }}</a>{% if not loop.last %} |{% endif %}
        {% else %}

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.