Skip to content

Commit a8c75ce

Browse files
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 <josh.t.richards@gmail.com>
1 parent c40d359 commit a8c75ce

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

user_manual/conf.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
'_templates',
3939
]
4040

41-
4241
exclude_patterns = [
4342
'_build',
4443
]
@@ -91,7 +90,6 @@
9190
# -- Options for LaTeX output ------------------------------------------------
9291
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-latex-output
9392

94-
9593
latex_elements = {
9694
}
9795
latex_documents = [
@@ -154,6 +152,19 @@
154152
current_docs = 'user_manual'
155153
html_context['versions'] = generateVersionsDocs(current_docs)
156154
html_context['theme_vcs_pageview_mode'] += current_docs
157-
html_context['available_languages'] = [
155+
156+
# Automatically detect available languages and pass to template
157+
158+
locale_path = os.path.join(os.path.dirname(__file__), 'locale')
159+
available_languages = []
160+
161+
if os.path.isdir(locale_path):
162+
available_languages = [
163+
lang for lang in os.listdir(locale_path)
164+
if os.path.isdir(os.path.join(locale_path, lang)) and lang != 'source'
158165
]
166+
if 'en' not in available_languages:
167+
available_languages.append('en')
168+
available_languages.sort()
159169

170+
html_context['available_languages'] = available_languages

0 commit comments

Comments
 (0)