mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix import of dictionaries that define a locale with no country code
This commit is contained in:
parent
2d7330d2a9
commit
b34fcc1daf
@ -68,6 +68,7 @@ def import_from_libreoffice_source_tree(source_path):
|
|||||||
raise Exception('Failed to find dictionaries for some wanted locales: %s' % want_locales)
|
raise Exception('Failed to find dictionaries for some wanted locales: %s' % want_locales)
|
||||||
|
|
||||||
def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'):
|
def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'):
|
||||||
|
from calibre.spell.dictionary import parse_lang_code
|
||||||
dest_dir = dest_dir or os.path.join(config_dir, 'dictionaries')
|
dest_dir = dest_dir or os.path.join(config_dir, 'dictionaries')
|
||||||
if not os.path.exists(dest_dir):
|
if not os.path.exists(dest_dir):
|
||||||
os.makedirs(dest_dir)
|
os.makedirs(dest_dir)
|
||||||
@ -79,6 +80,9 @@ def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'):
|
|||||||
for (dic, aff), locales in parse_xcu(zf.open(xcu).read(), origin='').iteritems():
|
for (dic, aff), locales in parse_xcu(zf.open(xcu).read(), origin='').iteritems():
|
||||||
dic, aff = dic.lstrip('/'), aff.lstrip('/')
|
dic, aff = dic.lstrip('/'), aff.lstrip('/')
|
||||||
d = tempfile.mkdtemp(prefix=prefix, dir=dest_dir)
|
d = tempfile.mkdtemp(prefix=prefix, dir=dest_dir)
|
||||||
|
locales = [x for x in locales if parse_lang_code(x).countrycode]
|
||||||
|
if not locales:
|
||||||
|
continue
|
||||||
metadata = [name] + locales
|
metadata = [name] + locales
|
||||||
with open(os.path.join(d, 'locales'), 'wb') as f:
|
with open(os.path.join(d, 'locales'), 'wb') as f:
|
||||||
f.write(('\n'.join(metadata)).encode('utf-8'))
|
f.write(('\n'.join(metadata)).encode('utf-8'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user