From a8fa2b290b1329ec576f264dc6bb470f819fda4d Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Fri, 25 Mar 2022 19:32:53 +0100 Subject: add language switcher in sidebar --- Makefile | 28 ++++++++++++++++++++++------ _templates/versions.html | 39 +++++++++++++++++++++++++++++++++++++++ conf.py | 15 ++++++++++----- 3 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 _templates/versions.html 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 $( + + {{_('Versions')}} + v: {{ version }} + + +
+ {% if languages|length >= 1 %} +
+
{{ _('Langages') }}
+ {% for slug, url in languages %} + {% if slug == language %} {% endif %} +
{{ slug }}
+ {% if slug == language %}
{% endif %} + {% endfor %} +
+ {% endif %} + {% if versions|length >= 1 %} +
+
{{ _('Versions') }}
+ {% for slug, url in versions %} + {% if slug == version %} {% endif %} +
{{ slug }}
+ {% if slug == version %}
{% endif %} + {% endfor %} +
+ {% endif %} + {% if downloads|length >= 1 %} +
+
{{ _('Téléchargements') }}
+ {% for type, url in downloads %} +
{{ type }}
+ {% endfor %} +
+ {% endif %} +
+ + 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 = { -- cgit v1.2.3