From f9bace32fd4f72f45bd2bb33bd4ebb0066a7d220 Mon Sep 17 00:00:00 2001 From: Tilly Woodfield <22456167+tillywoodfield@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:33:51 +0200 Subject: [PATCH] feat: implement language switcher logic --- docs/conf.py | 8 +++++++- iati_sphinx_theme/__init__.py | 2 ++ iati_sphinx_theme/footer.html | 9 +++------ iati_sphinx_theme/header.html | 7 +------ iati_sphinx_theme/language-switcher.html | 10 ++++++++++ iati_sphinx_theme/static/language-switcher.js | 20 +++++++++++++++++++ iati_sphinx_theme/theme.conf | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 iati_sphinx_theme/language-switcher.html create mode 100644 iati_sphinx_theme/static/language-switcher.js diff --git a/docs/conf.py b/docs/conf.py index 498025d..65dbebd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,6 +9,7 @@ project = "IATI Sphinx Theme" copyright = "2024 IATI Secretariat" author = "IATI Secretariat" +language = "en" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration @@ -26,6 +27,11 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = "iati_sphinx_theme" -html_theme_options = {"github_repository": "https://github.com/IATI/sphinx-theme"} +html_theme_options = { + "github_repository": "https://github.com/IATI/sphinx-theme", + "languages": { + "en": "English", + }, +} todo_include_todos = True diff --git a/iati_sphinx_theme/__init__.py b/iati_sphinx_theme/__init__.py index 516e47c..ea3ea5b 100644 --- a/iati_sphinx_theme/__init__.py +++ b/iati_sphinx_theme/__init__.py @@ -9,4 +9,6 @@ def setup(app: sphinx.application.Sphinx) -> None: app.add_html_theme("iati_sphinx_theme", path.abspath(path.dirname(__file__))) app.config["html_permalinks_icon"] = "#" app.config["html_favicon"] = "static/favicon-16x16.png" + app.config["html_context"]["language"] = app.config["language"] app.add_js_file("header.js") + app.add_js_file("language-switcher.js") diff --git a/iati_sphinx_theme/footer.html b/iati_sphinx_theme/footer.html index f38305c..b30f300 100644 --- a/iati_sphinx_theme/footer.html +++ b/iati_sphinx_theme/footer.html @@ -28,12 +28,9 @@