23
23
from __future__ import annotations
24
24
25
25
from argparse import ArgumentParser , Namespace
26
- from collections .abc import Sequence
26
+ from collections .abc import Iterable , Sequence
27
27
from contextlib import suppress , contextmanager
28
28
from dataclasses import dataclass
29
29
import filecmp
42
42
from pathlib import Path
43
43
from string import Template
44
44
from time import perf_counter , sleep
45
- from typing import Iterable , Literal
45
+ from typing import Literal
46
46
from urllib .parse import urljoin
47
47
48
48
import jinja2
@@ -196,6 +196,7 @@ def __gt__(self, other):
196
196
class Language :
197
197
iso639_tag : str
198
198
name : str
199
+ translated_name : str
199
200
in_prod : bool
200
201
sphinxopts : tuple
201
202
html_only : bool = False
@@ -214,6 +215,12 @@ def repo_url(self):
214
215
)
215
216
return f"https://github.com/python/{ repo_name } .git"
216
217
218
+ @property
219
+ def switcher_label (self ):
220
+ if self .translated_name :
221
+ return f"{ self .name } | { self .translated_name } "
222
+ return self .name
223
+
217
224
@staticmethod
218
225
def filter (languages , language_tags = None ):
219
226
"""Filter a sequence of languages according to --languages."""
@@ -398,7 +405,7 @@ def setup_switchers(
398
405
- Cross-link various languages in a language switcher
399
406
- Cross-link various versions in a version switcher
400
407
"""
401
- language_pairs = sorted ((l .tag , l .name ) for l in languages if l .in_prod )
408
+ language_pairs = sorted ((l .tag , l .switcher_label ) for l in languages if l .in_prod )
402
409
version_pairs = [(v .name , v .picker_label ) for v in reversed (versions )]
403
410
404
411
switchers_template_file = HERE / "templates" / "switchers.js"
@@ -482,15 +489,15 @@ def version_info():
482
489
"""Handler for --version."""
483
490
try :
484
491
platex_version = head (
485
- subprocess .check_output (["platex" , "--version" ], universal_newlines = True ),
492
+ subprocess .check_output (["platex" , "--version" ], text = True ),
486
493
lines = 3 ,
487
494
)
488
495
except FileNotFoundError :
489
496
platex_version = "Not installed."
490
497
491
498
try :
492
499
xelatex_version = head (
493
- subprocess .check_output (["xelatex" , "--version" ], universal_newlines = True ),
500
+ subprocess .check_output (["xelatex" , "--version" ], text = True ),
494
501
lines = 2 ,
495
502
)
496
503
except FileNotFoundError :
@@ -719,7 +726,7 @@ def build(self):
719
726
f"-D locale_dirs={ locale_dirs } " ,
720
727
f"-D language={ self .language .iso639_tag } " ,
721
728
"-D gettext_compact=0" ,
722
- # "-D translation_progress_classes=1",
729
+ "-D translation_progress_classes=1" ,
723
730
)
724
731
)
725
732
if self .language .tag == "ja" :
@@ -1160,13 +1167,15 @@ def parse_languages_from_config() -> list[Language]:
1160
1167
"""Read config.toml to discover languages to build."""
1161
1168
config = tomlkit .parse ((HERE / "config.toml" ).read_text (encoding = "UTF-8" ))
1162
1169
defaults = config ["defaults" ]
1170
+ default_translated_name = defaults .get ("translated_name" , "" )
1163
1171
default_in_prod = defaults .get ("in_prod" , True )
1164
1172
default_sphinxopts = defaults .get ("sphinxopts" , [])
1165
1173
default_html_only = defaults .get ("html_only" , False )
1166
1174
return [
1167
1175
Language (
1168
1176
iso639_tag = iso639_tag ,
1169
1177
name = section ["name" ],
1178
+ translated_name = section .get ("translated_name" , default_translated_name ),
1170
1179
in_prod = section .get ("in_prod" , default_in_prod ),
1171
1180
sphinxopts = section .get ("sphinxopts" , default_sphinxopts ),
1172
1181
html_only = section .get ("html_only" , default_html_only ),
0 commit comments