{#- Copyright (c) 2026 Humberto Sandmann and contributors SPDX-License-Identifier: MIT Language selector, replacing the theme's partial. Shows the current language in the header, and links to the current page in other languages, falling back to their home pages if the page doesn't exist there. -#} {% set i18n = config.extra.i18n %} {% if i18n %} {% if config.theme.variant == "modern" %} {% set check = "lucide/check" %} {% set chevron = "lucide/chevron-down" %} {% else %} {% set check = "material/check" %} {% set chevron = "material/chevron-down" %} {% endif %} {% set icon = config.theme.icon.alternate or "material/translate" %} {#- The base URL is absolute on some pages, e.g., 404 pages, where it's the site root without site URL, so we add the language's prefix -#} {% set root = (base_url ~ "/") | replace("//", "/") %} {% set absolute = not config.site_url and base_url[:1] == "/" %} {% if absolute %} {% set root = root ~ i18n.prefix %} {% endif %}
    {% for alt in i18n.languages %} {% set current = alt.locale == i18n.locale %} {#- Link to the current page, if it exists in the language, so crawlers and readers without JavaScript find translations. Languages that aren't built only have pages on their site -#} {% set href = alt.link %} {% if page and alt.locale in i18n.pages and page.url in i18n.pages[alt.locale] %} {% set href = alt.link ~ page.url %} {% endif %}
  • {% if absolute and "://" not in href %} {% set href = root ~ href %} {% else %} {% set href = href | url %} {% endif %} {{ alt.name | e }} {{ alt.lang }} {% include ".icons/" ~ check ~ ".svg" %}
  • {% endfor %}
{% include "partials/i18n/styles.html" %} {% include "partials/i18n/script.html" %}
{% endif %}