summaryrefslogtreecommitdiff
path: root/sysret.org/themes/tabi-lean/templates/partials/language_switcher.html
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2025-09-13 15:01:06 -0600
committerAlejandro Soto <alejandro@34project.org>2025-09-13 15:01:06 -0600
commitf4fcda54638685899c730b3fa90a87d80d6dbef5 (patch)
tree0737e627cce304c3a9c4e757bc5f6571a7456091 /sysret.org/themes/tabi-lean/templates/partials/language_switcher.html
parentd8b9cf1f61cc07d625f1c37ccc28adfd58918416 (diff)
parent2c13119932765c6d788f08fb53abc244407c0d80 (diff)
Merge commit '6a7d3111b31e73fc66af5360149d41f690fbcaa4'
Diffstat (limited to 'sysret.org/themes/tabi-lean/templates/partials/language_switcher.html')
-rw-r--r--sysret.org/themes/tabi-lean/templates/partials/language_switcher.html38
1 files changed, 38 insertions, 0 deletions
diff --git a/sysret.org/themes/tabi-lean/templates/partials/language_switcher.html b/sysret.org/themes/tabi-lean/templates/partials/language_switcher.html
new file mode 100644
index 0000000..83cf61f
--- /dev/null
+++ b/sysret.org/themes/tabi-lean/templates/partials/language_switcher.html
@@ -0,0 +1,38 @@
+<li class="language-switcher">
+ <details class="dropdown">
+ <summary role="button" aria-haspopup="true" title="{{ macros_translate::translate(key="language_selection", default="Language selection", language_strings=language_strings) }}" aria-label="{{ macros_translate::translate(key="language_selection", default="Language selection", language_strings=language_strings) }}">
+ <div class="language-switcher-icon"></div>
+ </summary>
+ <div class="dropdown-content" role="menu">
+ {#- Display the current language first in the dropdown -#}
+ {{ macros_translate::translate(key="language_name", default=lang, language_strings=language_strings) }}
+ {#- Loop through all the available languages in the config -#}
+ {%- for lcode, ldetails in config.languages -%}
+ {#- Skip the current language to avoid linking to the current page -#}
+ {%- if lang == lcode -%}
+ {%- continue -%}
+ {%- endif -%}
+ {#- Dynamically load the language strings for each language -#}
+ {%- set other_language_strings = load_data(path="i18n/" ~ lcode ~ ".toml", required=false) -%}
+ {%- if not other_language_strings -%}
+ {%- set other_language_strings = load_data(path="themes/tabi/i18n/" ~ lcode ~ ".toml", required=false) -%}
+ {%- endif -%}
+ {#- Use the loaded language strings to get the language name -#}
+ {% set language_name = macros_translate::translate(key="language_name", default=lcode,
+ language_strings=other_language_strings) %}
+ {#- Check if the language code matches the default language -#}
+ {%- if lcode == config.default_language -%}
+ {#- If it does, link to the root path (no language code in URL) -#}
+ <a role="menuitem" lang="{{ lcode }}" aria-label="{{ language_name }}" href="{{ current_url | replace(from='/' ~ lang ~ '/', to = '/') }}">{{ language_name }}</a>
+ {#- Check if the current language is the default language -#}
+ {#- If it is, append the language code to the base URL -#}
+ {%- elif lang == config.default_language -%}
+ <a role="menuitem" lang="{{ lcode }}" aria-label="{{ language_name }}" href="{{ config.base_url }}/{{ lcode }}{{ current_path | default(value="/") | safe }}">{{ language_name }}</a>
+ {%- else -%}
+ {#- If it's not, replace the current language code in the URL with the new one -#}
+ <a role="menuitem" lang="{{ lcode }}" aria-label="{{ language_name }}" href="{{ current_url | replace(from='/' ~ lang ~ '/', to='/' ~ lcode ~ '/') }}">{{ language_name }}</a>
+ {%- endif -%}
+ {%- endfor -%}
+ </div>
+ </details>
+</li>