{% set localizedRoutes = localized_page_routes() %}
{% set queryString = app.request.query.all|url_encode %}

{% if localizedRoutes.routes|length > 1 %}
    <span class="theme-language-switcher">
        {% for localizedRoute in localizedRoutes.routes %}
            {% if localizedRoute.locale == localizedRoutes.currentLocale %}
                <span lang="{{ localizedRoute.locale }}" aria-current="page">{{ localizedRoute.locale|upper }}</span>
            {% else %}
                <a
                    href="{{ localizedRoute.path }}{% if queryString %}?{{ queryString }}{% endif %}"
                    lang="{{ localizedRoute.locale }}"
                    hreflang="{{ localizedRoute.hreflang }}"
                    aria-label="{{ localizedRoute.languageName }}"
                    title="{{ localizedRoute.languageName }}"
                    data-turbo-frame="_top"
                >{{ localizedRoute.locale|upper }}</a>
            {% endif %}

            {% if not loop.last %}<span aria-hidden="true">/</span>{% endif %}
        {% endfor %}
    </span>
{% endif %}
