Skip to content

Commit 6d295f7

Browse files
committed
conf.py: Fix regression with composite language codes
RTD decided to normalize language codes such as `zh_CN` and `pt_BR` to `zh-cn` and `pt-br`, apparently because it makes URLs prettier... https://blog.readthedocs.com/language-codes-are-now-normalized/ But they didn't take into account that Sphinx doesn't do the same, and still requires `zh_CN` and `pt_BR` for its `language` config value. So we have to convert it back in `conf.py`, otherwise this breaks our i18n logic, notably to handle the localized class reference and images.
1 parent 1088ee3 commit 6d295f7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@
117117
"zh_TW": "Godot Engine %s 正體中文 (台灣) 文件",
118118
}
119119

120+
# RTD normalized their language codes to ll-cc (e.g. zh-cn),
121+
# but Sphinx did not and still uses ll_CC (e.g. zh_CN).
122+
# `language` is the Sphinx configuration so it needs to be converted back.
120123
language = os.getenv("READTHEDOCS_LANGUAGE", "en")
124+
if "-" in language:
125+
(lang_name, lang_country) = language.split("-")
126+
language = lang_name + "_" + lang_country.upper()
127+
121128
if not language in supported_languages.keys():
122129
print("Unknown language: " + language)
123130
print("Supported languages: " + ", ".join(supported_languages.keys()))
@@ -127,6 +134,7 @@
127134
language = "en"
128135

129136
is_i18n = tags.has("i18n") # noqa: F821
137+
print("Build language: {}, i18n tag: {}".format(language, is_i18n))
130138

131139
exclude_patterns = ["_build"]
132140

0 commit comments

Comments
 (0)