mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-05-30 09:37:13 -04:00
85 lines
3.0 KiB
HTML
85 lines
3.0 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 %}
|
|
{% 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 %}
|
|
<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">
|
|
{% if locales[first_segment] %}
|
|
<li><a href="{{ en_path | relative_url }}" lang="en">English</a></li>
|
|
{% endif %}
|
|
|
|
{% for locale in locales %}
|
|
{% assign locale_code = locale[0] %}
|
|
{% assign locale_info = locale[1] %}
|
|
|
|
{% if locales[first_segment] %}
|
|
{% if locale_code == first_segment %}
|
|
{% continue %}
|
|
{% endif %}
|
|
{% assign locale_path = locale_code | append: "/" | append: en_path %}
|
|
{% else %}
|
|
{% assign locale_path = locale_code | append: "/" | append: en_relative %}
|
|
{% endif %}
|
|
|
|
{% 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 %}
|
|
{% endif %}
|