Browse Source

conf: Fix handling of composite language codes with regional specifier

And fix another bug where I used `en` instead of a string.
Rémi Verschelde 5 years ago
parent
commit
66d185d5d2
1 changed files with 17 additions and 4 deletions
  1. 17 4
      conf.py

+ 17 - 4
conf.py

@@ -49,6 +49,7 @@ if env_tags is not None:
         tags.add(tag.strip())  # noqa: F821
         tags.add(tag.strip())  # noqa: F821
 
 
 # Language / i18n
 # Language / i18n
+
 supported_languages = {
 supported_languages = {
     "en": "Godot Engine (%s) documentation in English",
     "en": "Godot Engine (%s) documentation in English",
     "de": "Godot Engine (%s) Dokumentation auf Deutsch",
     "de": "Godot Engine (%s) Dokumentation auf Deutsch",
@@ -59,11 +60,23 @@ supported_languages = {
     "ja": "Godot Engine (%s)の日本語のドキュメント",
     "ja": "Godot Engine (%s)の日本語のドキュメント",
     "ko": "Godot Engine (%s) 문서 (한국어)",
     "ko": "Godot Engine (%s) 문서 (한국어)",
     "pl": "Dokumentacja Godot Engine (%s) w języku polskim",
     "pl": "Dokumentacja Godot Engine (%s) w języku polskim",
-    "pt-br": "Documentação da Godot Engine (%s) em Português Brasileiro",
+    "pt_BR": "Documentação da Godot Engine (%s) em Português Brasileiro",
     "ru": "Документация Godot Engine (%s) на русском языке",
     "ru": "Документация Godot Engine (%s) на русском языке",
     "uk": "Документація до Godot Engine (%s) українською мовою",
     "uk": "Документація до Godot Engine (%s) українською мовою",
-    "zh-cn": "Godot Engine (%s) 简体中文文档",
+    "zh_CN": "Godot Engine (%s) 简体中文文档",
+}
+
+# Some language codes used on Weblate/RTD and in the docs URL differ,
+# so we need to remap them.
+languages_remap = {
+    "pt_BR": "pt-br",
+    "zh_CN": "zh-cn",
 }
 }
+languages_url = sorted(
+    [l for l in supported_languages.keys() if l not in languages_remap.keys()]
+    + list(languages_remap.values())
+)
+
 language = os.getenv("READTHEDOCS_LANGUAGE", "en")
 language = os.getenv("READTHEDOCS_LANGUAGE", "en")
 if not language in supported_languages.keys():
 if not language in supported_languages.keys():
     print("Unknown language: " + language)
     print("Unknown language: " + language)
@@ -71,7 +84,7 @@ if not language in supported_languages.keys():
     print(
     print(
         "The configured language is either wrong, or it should be added to supported_languages in conf.py. Falling back to 'en'."
         "The configured language is either wrong, or it should be added to supported_languages in conf.py. Falling back to 'en'."
     )
     )
-    language = en
+    language = "en"
 
 
 is_i18n = tags.has("i18n")  # noqa: F821
 is_i18n = tags.has("i18n")  # noqa: F821
 
 
@@ -120,7 +133,7 @@ html_context = {
     "github_version": "master",  # Version
     "github_version": "master",  # Version
     "conf_py_path": "/",  # Path in the checkout to the docs root
     "conf_py_path": "/",  # Path in the checkout to the docs root
     "godot_inject_language_links": True,
     "godot_inject_language_links": True,
-    "godot_docs_supported_languages": list(supported_languages.keys()),
+    "godot_docs_supported_languages": languages_url,
     "godot_docs_basepath": "https://docs.godotengine.org/",
     "godot_docs_basepath": "https://docs.godotengine.org/",
     "godot_docs_suffix": ".html",
     "godot_docs_suffix": ".html",
     "godot_default_lang": "en",
     "godot_default_lang": "en",