Skip to content

Commit 129aa5c

Browse files
committed
Add language selector to sphinx docs
1 parent d03496b commit 129aa5c

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

docs/_templates/footer.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{%- extends "!footer.html" %}
2+
3+
{% block extrafooter %}
4+
<style>
5+
.language-switcher {
6+
text-align: center;
7+
margin: 1em 0;
8+
font-size: 0.9em;
9+
}
10+
.language-switcher a {
11+
margin: 0 0.5em;
12+
text-decoration: none;
13+
color: #4183c4;
14+
}
15+
.language-switcher a:hover {
16+
text-decoration: underline;
17+
}
18+
.language-switcher .current-language {
19+
margin: 0 0.5em;
20+
font-weight: bold;
21+
color: #333;
22+
}
23+
</style>
24+
<div class="language-switcher">
25+
{% set langs = { "en": "English", "ru": "Русский" } %}
26+
{% for code, name in langs.items() %}
27+
{% if code == language %}
28+
<span class="current-language">{{ name }}</span>
29+
{% else %}
30+
<a href="/{{ code }}/{{ pagename }}.html">{{ name }}</a>
31+
{% endif %}
32+
{% if not loop.last %} | {% endif %}
33+
{% endfor %}
34+
</div>
35+
{% endblock %}

docs/_templates/layout.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{%- extends "!layout.html" %}
2+
3+
{% block metatags %}
4+
{{ super() }}
5+
{# point every “/foo” URL at the real site root #}
6+
<base href="{{ pathto('', 1) }}" />
7+
{% endblock %}

docs/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636
html_static_path = ['_static']
3737

3838
html_sidebars = {
39-
"**": ["globaltoc.html", "sourcelink.html", "searchbox.html"]
39+
"**": [
40+
"globaltoc.html",
41+
"sourcelink.html",
42+
"searchbox.html",
43+
"language_switcher.html",
44+
],
4045
}
4146

4247
html_theme_options = {

0 commit comments

Comments
 (0)