From c0450e2014a88812dde21340f838613ac9eb0734 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Sun, 13 Dec 2015 05:09:41 +0800 Subject: [PATCH] [utils] Capture the error that mo files not found in LOCALE_DATA.ZIP --- youtube_dl/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 4e4435e16..7e94bddeb 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -2547,8 +2547,13 @@ class I18N(object): locale_data_zip = _load_exe_resource('LOCALE_DATA', 'LOCALE_DATA.ZIP') f = io.BytesIO(locale_data_zip) zipf = zipfile.ZipFile(f) - with zipf.open('share/locale/%s/LC_MESSAGES/%s.mo' % (lang, self.domain)) as mo_file: - t = gettext.GNUTranslations(mo_file) + try: + zinfo = zipf.getinfo('share/locale/%s/LC_MESSAGES/%s.mo' % (lang, self.domain)) + except KeyError: + zinfo = None + if zinfo is not None: + with zipf.open(zinfo) as mo_file: + t = gettext.GNUTranslations(mo_file) zipf.close() if t is None: