diff --git a/tornado/locale.py b/tornado/locale.py index adb1f77420..8b5fde4af9 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,10 @@ 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 = filename.split('/LC_MESSAGES/', 1)[0].split(directory, 1)[1].strip('/') try: - os.stat(os.path.join(directory, lang, "LC_MESSAGES", domain + ".mo")) _translations[lang] = gettext.translation( domain, directory, languages=[lang] )