{% comment %} Language switcher for translated docs pages. Renders a dropdown-style link list showing available translations of the current page. Include this in any page or layout that should offer locale switching. Usage: {% include language_switcher.html %} Logic: - Derives the current page's relative path within its section - Checks if translated versions exist in locale subdirectories - Shows a globe icon with available locale links {% endcomment %} {% assign current_path = page.path %} {% assign locales = site.data.locales %} {% if locales and current_path %} {% assign path_parts = current_path | split: "/" %} {% assign first_segment = path_parts[0] %} {% comment %} Build the list of available translations first {% endcomment %} {% assign has_translations = false %} {% if locales[first_segment] %} {% comment %} We're on a translated page — English link is always available {% endcomment %} {% assign has_translations = true %} {% assign remaining_parts = path_parts | slice: 1, path_parts.size %} {% assign en_path = remaining_parts | join: "/" | replace: ".md", "" %} {% else %} {% comment %} Check if any translated version exists {% endcomment %} {% assign en_relative = current_path | replace: ".md", "" %} {% for locale in locales %} {% assign locale_code = locale[0] %} {% assign locale_file = locale_code | append: "/" | append: en_relative | append: ".md" %} {% for p in site.pages %} {% if p.path == locale_file %} {% assign has_translations = true %} {% break %} {% endif %} {% endfor %} {% if has_translations %}{% break %}{% endif %} {% endfor %} {% endif %} {% if has_translations %}
🌐 English
{% endif %} {% endif %}