Skip to content

Commit 1f5f067

Browse files
committed
Deduplicate language list.
1 parent 490f807 commit 1f5f067

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

build_docs.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
from collections import namedtuple
3636
from contextlib import contextmanager, suppress
3737
import filecmp
38+
import json
3839
import logging
3940
import logging.handlers
4041
import os
4142
from pathlib import Path
4243
import re
4344
from shlex import quote
4445
import shutil
46+
from string import Template
4547
import subprocess
4648
import sys
4749
from datetime import datetime
@@ -266,7 +268,24 @@ def setup_switchers(html_root):
266268
- Cross-link various languages in a language switcher
267269
- Cross-link various versions in a version switcher
268270
"""
269-
shutil.copy("switchers.js", os.path.join(html_root, "_static"))
271+
with open("switchers.js") as switchers_template_file:
272+
with open(
273+
os.path.join(html_root, "_static", "switchers.js"), "w"
274+
) as switchers_file:
275+
template = Template(switchers_template_file.read())
276+
switchers_file.write(
277+
template.safe_substitute(
278+
{
279+
"LANGUAGES": json.dumps(
280+
{
281+
language.tag: language.name
282+
for language in LANGUAGES
283+
if language.in_prod
284+
}
285+
)
286+
}
287+
)
288+
)
270289
for file in Path(html_root).glob("**/*.html"):
271290
depth = len(file.relative_to(html_root).parts) - 1
272291
script = f""" <script type="text/javascript" src="{'../' * depth}_static/switchers.js"></script>\n"""

switchers.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@
1919
'2.7': '2.7',
2020
};
2121

22-
var all_languages = {
23-
'en': 'English',
24-
'fr': 'French',
25-
'ja': 'Japanese',
26-
'ko': 'Korean',
27-
'pt-br': 'Brazilian Portuguese',
28-
'zh-cn': 'Simplified Chinese',
29-
};
22+
var all_languages = $LANGUAGES;
3023

3124
function build_version_select(current_version, current_release) {
3225
var buf = ['<select>'];

0 commit comments

Comments
 (0)