From a8c75cead4de26d465e52f94eaa8b96177681eb4 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 12 Oct 2025 14:50:23 -0400 Subject: [PATCH] refactor: Add language detection for HTML context Automatically detect and list available languages for templates. Mostly so we can sort by display name. Signed-off-by: Josh --- user_manual/conf.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/user_manual/conf.py b/user_manual/conf.py index 405381938..7ff8635de 100644 --- a/user_manual/conf.py +++ b/user_manual/conf.py @@ -38,7 +38,6 @@ templates_path = [ '_templates', ] - exclude_patterns = [ '_build', ] @@ -91,7 +90,6 @@ epub_copyright = u'2012-2025, The Nextcloud developers' # -- Options for LaTeX output ------------------------------------------------ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-latex-output - latex_elements = { } latex_documents = [ @@ -154,6 +152,19 @@ pdf_documents = [ current_docs = 'user_manual' html_context['versions'] = generateVersionsDocs(current_docs) html_context['theme_vcs_pageview_mode'] += current_docs -html_context['available_languages'] = [ - ] +# Automatically detect available languages and pass to template + +locale_path = os.path.join(os.path.dirname(__file__), 'locale') +available_languages = [] + +if os.path.isdir(locale_path): + available_languages = [ + lang for lang in os.listdir(locale_path) + if os.path.isdir(os.path.join(locale_path, lang)) and lang != 'source' + ] + if 'en' not in available_languages: + available_languages.append('en') + available_languages.sort() + +html_context['available_languages'] = available_languages