mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Merge branch 'fix-dictionaries' of https://github.com/un-pogaz/calibre
This commit is contained in:
commit
0979c1a25c
@ -23,6 +23,9 @@ def parse_lang_code(raw):
|
||||
if lc is None:
|
||||
raise ValueError('Invalid language code: %r' % raw)
|
||||
cc = None
|
||||
for sc in ['Cyrl', 'Latn']:
|
||||
if sc in parts:
|
||||
parts.remove(sc)
|
||||
if len(parts) > 1:
|
||||
ccodes, ccodemap = get_codes()[:2]
|
||||
q = parts[1].upper()
|
||||
|
@ -45,6 +45,8 @@ def parse_xcu(raw, origin='%origin%'):
|
||||
paths = [c.text.replace('%origin%', origin) for v in value for c in v.iterchildren('*') if c.text]
|
||||
aff, dic = paths if paths[0].endswith('.aff') else reversed(paths)
|
||||
locales = ''.join(XPath('descendant::prop[@oor:name="Locales"]/value/text()')(node)).split()
|
||||
if not locales:
|
||||
locales = [str(item) for item in XPath('descendant::prop[@oor:name="Locales"]/value/it/text()')(node)]
|
||||
ans[(dic, aff)] = locales
|
||||
return ans
|
||||
|
||||
@ -158,8 +160,16 @@ def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'):
|
||||
def import_from_online(directory, name, dest_dir=None, prefix='dic-'):
|
||||
br = browser(timeout=30)
|
||||
def read_file(key):
|
||||
try:
|
||||
rp = br.open('/'.join((ONLINE_DICTIONARY_BASE_URL, directory, key)))
|
||||
return rp.read()
|
||||
except:
|
||||
# Some dictionaries apparently put the dic and aff file in a
|
||||
# sub-directory dictionaries and incorrectly make paths relative
|
||||
# to that directory instead of the root, for example:
|
||||
# https://github.com/LibreOffice/dictionaries/tree/master/ca
|
||||
rp = br.open('/'.join((ONLINE_DICTIONARY_BASE_URL, directory, 'dictionaries', key)))
|
||||
return rp.read()
|
||||
|
||||
return _import_from_virtual_directory(read_file, name, dest_dir=dest_dir, prefix=prefix)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user