aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2022-03-25 19:32:53 +0100
committern-peugnet <n.peugnet@free.fr>2022-03-26 22:03:20 +0100
commita8fa2b290b1329ec576f264dc6bb470f819fda4d (patch)
tree4127e0dbdf90ea357b1798337aec4b07e6c38d3e
parentf688d73fa32bbdaa0a229a945ebd4c78b3bb6f61 (diff)
downloadclub1-docs-a8fa2b290b1329ec576f264dc6bb470f819fda4d.tar.gz
club1-docs-a8fa2b290b1329ec576f264dc6bb470f819fda4d.zip
add language switcher in sidebar
-rw-r--r--Makefile28
-rw-r--r--_templates/versions.html39
-rw-r--r--conf.py15
3 files changed, 71 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index b9fe36e..2ff019a 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,13 @@ else
override NOTFR =
endif
+ifneq (,$(filter grouped-target,$(.FEATURES)))
+GROUPED_TARGET = 1
+else
+$(warning WARNING: This version of make does not support grouped-target, disabling parallel jobs.)
+.NOTPARALLEL:
+endif
+
SPHINXLANG = -D language=$(LOCALE)
SPHINXOPTS += -a
SPHINXBUILD ?= sphinx-build
@@ -19,8 +26,13 @@ SPHINXCMDS = pickle json htmlhelp changes xml pseudoxml linkcheck doctest
SOURCEDIR = .
BUILDDIR = _build
MDFILES = index.md $(shell find . -type f -name '*.md')
+TEMPLATES = $(shell find _templates -type f -name '*.html')
LOCALES = en
LOCALEFILES = $(LOCALES:%=locales/%/LC_MESSAGES/package.po)
+PONAMES = package sphinx
+POTS = $(PONAMES:%=locales/%.pot)
+
+export LANGUAGES = fr $(LOCALES)
# Put it first so that "make" without argument is like "make help".
help:
@@ -30,15 +42,19 @@ help:
update-po: $(LOCALEFILES)
-gettext: locales/package.pot
+gettext: $(POTS)
-$(LOCALEFILES): locales/%/LC_MESSAGES/package.po: locales/package.pot
+$(LOCALEFILES): locales/%/LC_MESSAGES/package.po: $(POTS)
sphinx-intl update -p $(<D) -l $*
@touch $@
-locales/package.pot: $(MDFILES)
+ifdef GROUPED_TARGET
+$(POTS)&: $(MDFILES) $(TEMPLATES)
+else
+$(POTS): $(MDFILES) $(TEMPLATES)
+endif
$(SPHINXBUILD) -b gettext "$(SOURCEDIR)" locales $(SPHINXOPTS) $O
- @touch $@
+ @touch $(POTS)
latexpdf: latex
$(MAKE) -C $(BUILDDIR)/latex/$(LOCALE)
@@ -50,7 +66,7 @@ publish:
rsync -av --del --exclude='.*' _build/html/ $(USER)@$(PUBHOST):$(PUBDIR)
# Shinx commands that need locales (builders).
-$(SPHINXBUILDERS): $(if $(NOTFR),locales/$(LOCALE)/LC_MESSAGES/package.po)
+$(SPHINXBUILDERS): $(if $(NOTFR),$(PONAMES:%=locales/$(LOCALE)/LC_MESSAGES/%.po))
$(SPHINXBUILD) -b $@ "$(SOURCEDIR)" "$(BUILDDIR)/$@/$(LOCALE)" $(SPHINXLANG) $(SPHINXOPTS) $O
# Other Sphinx commands for autocompletion
@@ -58,6 +74,6 @@ $(SPHINXCMDS):
$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $O
clean:
- rm -f locales/*/LC_MESSAGES/package.mo
+ rm -f locales/*/LC_MESSAGES/*.mo
rm -rf locales/.doctrees
rm -rf $(BUILDDIR)/*
diff --git a/_templates/versions.html b/_templates/versions.html
new file mode 100644
index 0000000..a68c705
--- /dev/null
+++ b/_templates/versions.html
@@ -0,0 +1,39 @@
+{# Add rst-badge after rst-versions for small badge style. #}
+<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
+ <span class="rst-current-version" data-toggle="rst-current-version">
+ <span class="fa fa-book"> {{_('Versions')}}</span>
+ v: {{ version }}
+ <span class="fa fa-caret-down"></span>
+ </span>
+ <div class="rst-other-versions">
+ {% if languages|length >= 1 %}
+ <dl>
+ <dt>{{ _('Langages') }}</dt>
+ {% for slug, url in languages %}
+ {% if slug == language %} <strong> {% endif %}
+ <dd><a href="{{ pathto(url + pagename) }}">{{ slug }}</a></dd>
+ {% if slug == language %} </strong> {% endif %}
+ {% endfor %}
+ </dl>
+ {% endif %}
+ {% if versions|length >= 1 %}
+ <dl>
+ <dt>{{ _('Versions') }}</dt>
+ {% for slug, url in versions %}
+ {% if slug == version %} <strong> {% endif %}
+ <dd><a href="{{ pathto(url + pagename) }}">{{ slug }}</a></dd>
+ {% if slug == version %} </strong> {% endif %}
+ {% endfor %}
+ </dl>
+ {% endif %}
+ {% if downloads|length >= 1 %}
+ <dl>
+ <dt>{{ _('Téléchargements') }}</dt>
+ {% for type, url in downloads %}
+ <dd><a href="{{ url }}">{{ type }}</a></dd>
+ {% endfor %}
+ </dl>
+ {% endif %}
+ </div>
+</div>
+
diff --git a/conf.py b/conf.py
index df992cb..23934f4 100644
--- a/conf.py
+++ b/conf.py
@@ -10,7 +10,7 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
-# import os
+import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
@@ -21,6 +21,7 @@ project = 'CLUB1'
copyright = '2022, Nicolas PEUGNET'
author = 'Nicolas PEUGNET'
version = 'main'
+release = version
# -- General configuration ---------------------------------------------------
@@ -46,6 +47,9 @@ templates_path = ['_templates']
# Usually you set "language" from the command line for these cases.
language = 'fr'
+# Set by make.
+languages = os.environ['LANGUAGES'].split(' ')
+
# Use a single POT and PO file par language.
gettext_compact = 'package'
@@ -71,10 +75,11 @@ exclude_patterns = [
html_theme = 'sphinx_rtd_theme'
html_context = {
- 'display_github': True,
- 'github_user': 'club-1',
- 'github_repo': 'docs',
- 'github_version': 'main/',
+ 'display_github': True,
+ 'github_user': 'club-1',
+ 'github_repo': 'docs',
+ 'github_version': f'{version}/',
+ 'languages': [(lang, f'../{lang}/') for lang in languages],
}
html_theme_options = {