File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 35
35
from collections import namedtuple
36
36
from contextlib import contextmanager , suppress
37
37
import filecmp
38
+ import json
38
39
import logging
39
40
import logging .handlers
40
41
import os
41
42
from pathlib import Path
42
43
import re
43
44
from shlex import quote
44
45
import shutil
46
+ from string import Template
45
47
import subprocess
46
48
import sys
47
49
from datetime import datetime
@@ -266,7 +268,24 @@ def setup_switchers(html_root):
266
268
- Cross-link various languages in a language switcher
267
269
- Cross-link various versions in a version switcher
268
270
"""
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
+ )
270
289
for file in Path (html_root ).glob ("**/*.html" ):
271
290
depth = len (file .relative_to (html_root ).parts ) - 1
272
291
script = f""" <script type="text/javascript" src="{ '../' * depth } _static/switchers.js"></script>\n """
Original file line number Diff line number Diff line change 19
19
'2.7' : '2.7' ,
20
20
} ;
21
21
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 ;
30
23
31
24
function build_version_select ( current_version , current_release ) {
32
25
var buf = [ '<select>' ] ;
You can’t perform that action at this time.
0 commit comments