I want to show a sorted list of available languages for any given page, e.g.:
- Chinese
- English
- German
Sorting the language codes (e.g. zh-CN
, en
de
) is possible via: {% for translation in page.translations | sort(attribute="lang") %}
. For converting the codes to a language name, I use the [translations]
table in config.toml:
[translations.en]
lang_name = "English"
[translations.zh-CN]
lang_name = "Chinese (simplified)"
[translations.de]
lang_name = "German"
This allows me to call trans(key="lang_name", lang = lang_code)
for every language code.
However, I didn’t find any way to sort the list by the language names, i.e. the results of the trans
call, instead of sorting by the language codes. Is this possible somehow?