Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locale: Only try to load locales that exist #2971

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tornado/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import csv
import datetime
import gettext
import glob
import os
import re

Expand Down Expand Up @@ -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]
)
Expand Down