From 0937f7df5150d8a35ec8eae90a449ecf1b81f6b4 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Fri, 8 Oct 2021 16:45:24 +0200 Subject: [PATCH] fix translation installation for locales with script name (#2565) when a locale like zh_CN is parsed by babel.core.Locale, the result Locale is zh_Hans_CN which is then used to find out if translations exist for this locale name the Hans part is the guessed script name part of the babel Locale but is almost never contributed as translation locale name so we have to make sure what we look for the language + territory locale name instead of the fully parsed name from babel --- mkdocs/localization.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mkdocs/localization.py b/mkdocs/localization.py index 42ddbd6ac7..6f772ec3d4 100644 --- a/mkdocs/localization.py +++ b/mkdocs/localization.py @@ -56,9 +56,13 @@ def _get_merged_translations(theme_dirs, locales_dir, locale): merged_translations = None log.debug(f"Looking for translations for locale '{locale}'") + if locale.territory: + locale_str = f"{locale.language}_{locale.territory}" + else: + locale_str = locale.language for theme_dir in reversed(theme_dirs): dirname = os.path.join(theme_dir, locales_dir) - translations = Translations.load(dirname, [locale]) + translations = Translations.load(dirname, [locale_str]) if type(translations) is NullTranslations: log.debug(f"No translations found here: '{dirname}'")