mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-05-31 01:58:13 -04:00
72 lines
2.8 KiB
HTML
72 lines
2.8 KiB
HTML
{% 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 %}
|
|
<details class="language-switcher" aria-label="Language options">
|
|
<summary class="language-switcher-btn" title="View in another language">
|
|
🌐 <span class="lang-current">English</span>
|
|
</summary>
|
|
<ul class="language-switcher-list">
|
|
{% comment %} Always show English link back to source {% endcomment %}
|
|
{% assign path_parts = current_path | split: "/" %}
|
|
{% assign first_segment = path_parts[0] %}
|
|
|
|
{% comment %} Detect if we're currently IN a locale subdir {% endcomment %}
|
|
{% if locales[first_segment] %}
|
|
{% comment %} We're on a translated page — link back to English {% endcomment %}
|
|
{% assign remaining_parts = path_parts | slice: 1, path_parts.size %}
|
|
{% assign en_path = remaining_parts | join: "/" | replace: ".md", "" %}
|
|
<li><a href="{{ en_path | relative_url }}" lang="en">English</a></li>
|
|
{% endif %}
|
|
|
|
{% comment %} Show all available locale versions {% endcomment %}
|
|
{% for locale in locales %}
|
|
{% assign locale_code = locale[0] %}
|
|
{% assign locale_info = locale[1] %}
|
|
|
|
{% if locales[first_segment] %}
|
|
{% comment %} We're already on a translated page {% endcomment %}
|
|
{% if locale_code == first_segment %}
|
|
{% continue %}
|
|
{% endif %}
|
|
{% assign locale_path = locale_code | append: "/" | append: en_path %}
|
|
{% else %}
|
|
{% comment %} We're on an English page {% endcomment %}
|
|
{% assign en_relative = current_path | replace: ".md", "" %}
|
|
{% assign locale_path = locale_code | append: "/" | append: en_relative %}
|
|
{% endif %}
|
|
|
|
{% comment %}
|
|
Check if the translated file actually exists.
|
|
Jekyll doesn't have a file_exists filter, so we check site.pages.
|
|
{% endcomment %}
|
|
{% assign locale_file = locale_path | append: ".md" %}
|
|
{% assign page_exists = false %}
|
|
{% for p in site.pages %}
|
|
{% if p.path == locale_file %}
|
|
{% assign page_exists = true %}
|
|
{% break %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{% if page_exists %}
|
|
<li><a href="{{ locale_path | relative_url }}" lang="{{ locale_code }}" {% if locale_info.dir == "rtl" %}dir="rtl"{% endif %}>{{ locale_info.name }}</a></li>
|
|
{% endif %}
|
|
{% endfor %}
|
|
</ul>
|
|
</details>
|
|
{% endif %}
|