Skip to content

Commit 6c8766b

Browse files
author
Felix Kleinekathoefer
committed
Fallback to en if locale is not available for version
1 parent 1d355b2 commit 6c8766b

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/theme/context.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ def _split_environment_variable(name):
66
return value and value.split()
77

88

9+
def build_locale_map():
10+
locales = {}
11+
for k, v in os.environ.items():
12+
if not k.startswith("LOCALES_"):
13+
continue
14+
k = k[len("LOCALES_"):].replace('_', '.')
15+
locales[k.lower()] = v.split()
16+
return locales
17+
18+
919
def setup_html_context():
1020
github_user = os.environ.get('GITHUB_USER')
1121
github_repo = os.environ.get('GITHUB_REPO')
@@ -16,7 +26,7 @@ def setup_html_context():
1626
'conf_py_path': '/source/',
1727

1828
# List of supported languages
19-
'locales': _split_environment_variable('LOCALES'),
29+
'locales': build_locale_map(),
2030

2131
# Current version and list of documented versions
2232
'current_version': os.environ.get('VERSION'),

src/theme/scripts/list-translations

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ for language in r.json()['data']:
4040
if language['data']['translationProgress'] >= 5 or language['data']['languageId'].startswith('en-'):
4141
locales.append(languages[language['data']['languageId']])
4242
else:
43-
print("Skipping %s with %d%% completion" %
44-
(language['data']['languageId'], language['data']['translationProgress']), file=sys.stderr)
43+
print("[%s] Skipping %s with %d%% completion" %
44+
(branchId, language['data']['languageId'], language['data']['translationProgress']), file=sys.stderr)
4545

4646
# Sort locales
4747
locales.sort()

src/theme/templates/versions.html

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<div id="versions" class="rst-other-versions">
1818

1919
{# Languages #}
20-
{% if locales %}
20+
{% if locales[current_version] %}
2121
<dl id="languages">
2222
<dt>{% trans %}Languages{% endtrans %}</dt>
23-
{% for locale in locales %}
23+
{% for locale in locales[current_version] %}
2424
{% if locale != 'translate' %}
2525
<dd><a href="{{ page_link(language=locale) }}">{{ language_flag(locale) }}</a></dd>
2626
{% endif %}
@@ -33,8 +33,15 @@
3333
<dl>
3434
<dt>{% trans %}Versions{% endtrans %}</dt>
3535
{% for version in versions %}
36-
<dd><a {{ mark_current(version, current_version) }}
37-
href="{{ page_link(version=version) }}">{{ version }}</a></dd>
36+
<dd>
37+
{% if language and language in locales[version] %}
38+
<a {{ mark_current(version, current_version) }}
39+
href="{{ page_link(version=version) }}">{{ version }}
40+
</a>
41+
{% else %}
42+
<a href="{{ page_link(version=version, language="en") }}">{{ version }} (en)</a>
43+
{% endif %}
44+
</dd>
3845
{% endfor %}
3946
</dl>
4047
{% endif %}
@@ -48,14 +55,14 @@
4855
{% endif %}
4956

5057
{# Contribute #}
51-
{% if github_page_link or (locales and 'translate' in locales) %}
58+
{% if github_page_link or (locales and 'translate' in locales[current_version]) %}
5259
<dl>
5360
<dt>{% trans %}Contribute{% endtrans %}</dt>
5461
{% if github_page_link %}
5562
<dd><a href="{{ github_page_link() }}">{{ _("Source") }}</a></dd>
5663
<dd><a href="{{ github_page_link('edit') }}">{{ _("Edit") }}</a></dd>
5764
{% endif %}
58-
{% if locales and 'translate' in locales %}
65+
{% if locales and 'translate' in locales[current_version] %}
5966
<dd><a href="{{ page_link(language='translate') }}">{{ _("Translate") }}</a></dd>
6067
{% endif %}
6168
</dl>

0 commit comments

Comments
 (0)