Skip to content

Commit

Permalink
Issue tornadoweb#2954: prevent logging error messages for not existin…
Browse files Browse the repository at this point in the history
…g translation files

Every not existing translation file for the existing locales logged an error message:
Cannot load translation for 'ps': [Errno 2] No such file or directory: '/usr/share/locale/ps/LC_MESSAGES/foo.mo'
  • Loading branch information
spaceone committed Nov 19, 2020
1 parent b120df9 commit 7cce0fb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 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,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]
)
Expand Down

0 comments on commit 7cce0fb

Please sign in to comment.