mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Even better error message when loading .mo file fails
This commit is contained in:
parent
98ec15b970
commit
a38758ca68
@ -136,13 +136,18 @@ def get_all_translators():
|
|||||||
def get_single_translator(mpath, which='messages'):
|
def get_single_translator(mpath, which='messages'):
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf:
|
with ZipFile(P('localization/locales.zip', allow_user_override=False), 'r') as zf:
|
||||||
buf = io.BytesIO(zf.read(mpath + '/%s.mo' % which))
|
path = '{}/{}.mo'.format(mpath, which)
|
||||||
|
data = zf.read(path)
|
||||||
|
buf = io.BytesIO(data)
|
||||||
try:
|
try:
|
||||||
return GNUTranslations(buf)
|
return GNUTranslations(buf)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise ValueError('Failed to load translations for: {} with error: {}'.format(mpath, e))
|
import hashlib
|
||||||
|
sig = hashlib.sha1(data).hexdigest()
|
||||||
|
raise ValueError('Failed to load translations for: {} (size: {} and signature: {}) with error: {}'.format(
|
||||||
|
path, len(data), sig, e))
|
||||||
|
|
||||||
|
|
||||||
def get_iso639_translator(lang):
|
def get_iso639_translator(lang):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user