How do I redirect to a corresponding route when user switches languages? I'm working on a multilingual site with english and spanish locales. I've built persistent switcher that resides in the site footer. When users click it, it redirects to a corresponding entry in the other locale if one exists and the homepage if one does not.

The problem is that I have a handful of pages on my site that aren't entries: they are routes that are tied to particular templates. For example:

news-events/tags

Is the route for a template that lists all tags in use in my news section, and:

noticias-eventos/tags

would be the corresponding route on the spanish site.

I'd like to be able to check if the current uri is covered by a route and if so, whether there is a corresponding route in the other locale. If so, I'd redirect to that and if not, back to the homepage as per usual.

But from what I can see, routes are not localizable and exist independently of each other. Am I wrong? How would I go about this?
This is a rather hacky workaround, but I have no idea what else you could do to handle it. What I do is to compose an array of "route objects" that basically mirror the routes set up in the CP. This array can then be compared to the URL segments (→ getSegments). Not nice but it works :)

{# Map the corresponding routes #}
{% set routes = [
    { en: 'news-events/tags', es: 'noticias-eventos/tags' },
    { en: 'news-events/categories', es: 'noticias-eventos/categorias' },
] %}

{# Configure and loop through selected site locales #}
{% set locales = ['en', 'es'] %}
{% for locale in locales %}

    {# Is this an entry page? #}
    {% if entry is not defined %}

        {# ... Do entry stuff #}

    {# Not an entry page --&gt; check the routes #}
    {% else %}

        {# Get URL segments #}
        {% set segments = craft.request.getSegments %}

        {# Set var before loop #}
        {% set noRoute = true %}

        {# Loop routes array #}
        {% for prop in routes %}

            {# Check if URL segments match a route #}
            {% if prop[craft.locale]|split('/') == segments %}

                {# Output link to the mapped route #}
                &lt;a href="{{ craft.config.siteUrl[locale] ~ prop[locale] }}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;

                {# Switch var value #}
                {% set noRoute = false %}

            {% endif %}

        {% endfor %}

        {# No route found --&gt; output a link to the homepage #}
        {% if noRoute %}
            &lt;a href="{{ craft.config.siteUrl[locale] }}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;
        {% endif %}

    {% endif %}

{% endfor %}