diff --git a/tornado/locale.py b/tornado/locale.py index adb1f77420..533ce4d41c 100644 --- a/tornado/locale.py +++ b/tornado/locale.py @@ -41,6 +41,7 @@ import csv import datetime import gettext +import glob import os import re @@ -198,13 +199,12 @@ def load_gettext_translations(directory: str, domain: str) -> None: global _supported_locales global _use_gettext _translations = {} - for lang in os.listdir(directory): - if lang.startswith("."): - continue # skip .svn, etc - if os.path.isfile(os.path.join(directory, lang)): - continue + + for filename in glob.glob( + os.path.join(directory, "*", "LC_MESSAGES", domain + ".mo") + ): + lang = os.path.basename(os.path.dirname(os.path.dirname(filename))) try: - os.stat(os.path.join(directory, lang, "LC_MESSAGES", domain + ".mo")) _translations[lang] = gettext.translation( domain, directory, languages=[lang] )