Skip to content

Commit d515559

Browse files
committed
tag can be deduced from iso-tag.
1 parent 2a9e24f commit d515559

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

build_docs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,16 @@ def __gt__(self, other):
206206

207207
@dataclass(frozen=True, order=True)
208208
class Language:
209-
tag: str
210209
iso639_tag: str
211210
name: str
212211
in_prod: bool
213212
sphinxopts: tuple
214213
html_only: bool = False
215214

215+
@property
216+
def tag(self):
217+
return self.iso639_tag.replace("_", "-").lower()
218+
216219
@staticmethod
217220
def filter(languages, language_tags=None):
218221
"""Filter a sequence of languages according to --languages."""
@@ -1024,11 +1027,10 @@ def parse_languages_from_config():
10241027
config = tomlkit.parse((HERE / "config.toml").read_text(encoding="UTF-8"))
10251028
languages = []
10261029
defaults = config["defaults"]
1027-
for name, section in config["languages"].items():
1030+
for iso639_tag, section in config["languages"].items():
10281031
languages.append(
10291032
Language(
1030-
name,
1031-
section.get("iso639_tag", name),
1033+
iso639_tag,
10321034
section["name"],
10331035
section.get("in_prod", defaults["in_prod"]),
10341036
sphinxopts=section.get("sphinxopts", defaults["sphinxopts"]),

config.toml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[defaults]
22
# name has no default, it is mandatory.
3-
# iso639_tag defaults to section key.
43
in_prod = true
54
html_only = false
65
sphinxopts = [
@@ -72,8 +71,7 @@ sphinxopts = [
7271
name = "Polish"
7372
in_prod = false
7473

75-
[languages.pt-br]
76-
iso639_tag = "pt_BR"
74+
[languages.pt_BR]
7775
name = "Brazilian Portuguese"
7876

7977
[languages.tr]
@@ -84,17 +82,15 @@ name = "Ukrainian"
8482
in_prod = false
8583
html_only = true
8684

87-
[languages.zh-cn]
88-
iso639_tag = "zh_CN"
85+
[languages.zh_CN]
8986
name = "Simplified Chinese"
9087
sphinxopts = [
9188
'-D latex_engine=xelatex',
9289
'-D latex_elements.inputenc=',
9390
'-D latex_elements.fontenc=\\usepackage{xeCJK}',
9491
]
9592

96-
[languages.zh-tw]
97-
iso639_tag = "zh_TW"
93+
[languages.zh_TW]
9894
name = "Traditional Chinese"
9995
sphinxopts = [
10096
'-D latex_engine=xelatex',

0 commit comments

Comments
 (0)