feat: refactoring for sphinx localisation support

This commit is contained in:
Ana Custura 2024-12-05 15:58:11 +00:00 committed by irl
parent 368b4ba0c1
commit bf5e7c383a
6 changed files with 189 additions and 33 deletions

View file

@ -0,0 +1,9 @@
<div class="sidebar-tree">
<p class="caption" role="heading"><span class="caption-text">{{ _('Translations') }}</span></p>
<ul>
{% for language, language_name in languages %}
<li class="toctree-l1"><a class="reference internal"
href="/{{ language }}/{{ pagename }}.html">{{ language_name }}</a></li>
{% endfor %}
</ul>
</div>

17
docs/build_docs.py Normal file
View file

@ -0,0 +1,17 @@
import subprocess
import os
import yaml
with open('languages.yaml', 'r') as file:
config = yaml.safe_load(file)
languages = config.get('languages', [])
def build_doc(language, dest_dir):
os.environ['SPHINXOPTS'] = "-D language='{}'".format(language)
subprocess.run(f"sphinx-build -b html . {dest_dir}", shell=True)
build_doc("en", "../public")
for language in languages:
build_doc(language['code'], f"../public/{language['code']}")

View file

@ -1,17 +1,36 @@
import builtins
import os
import sys
import yaml
sys.path.insert(0, os.path.abspath('..'))
language = 'en' # default language
locale_dirs = ['./locale/']
gettext_compact = False
templates_path = ['./_templates']
builtins.__sphinx_build__ = True
# Define languages and links in html_context
# this is used with templates in /_templates to extend the default theme,
# adding languages to the sidebar
with open('languages.yaml', 'r') as file:
config = yaml.safe_load(file)
languages = config.get('languages', [])
html_context = {
'languages': [[lang['code'], lang['name']] for lang in languages]
}
# -- Project information -----------------------------------------------------
project = 'Bypass Censorship Portal'
copyright = '2021-202r SR2 Communications Limited'
author = 'Bypass Censorship'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
@ -31,7 +50,6 @@ templates_path = ['_templates']
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for

8
docs/languages.yaml Normal file
View file

@ -0,0 +1,8 @@
languages:
- code: "en"
name: "English"
- code: "pl"
name: "Polski"
- code: "ro"
name: "Română"