diff --git a/src/calibre/spell/__init__.py b/src/calibre/spell/__init__.py index e6c2b4265f..8755460c09 100644 --- a/src/calibre/spell/__init__.py +++ b/src/calibre/spell/__init__.py @@ -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() diff --git a/src/calibre/spell/import_from.py b/src/calibre/spell/import_from.py index be4be5d98b..0d49687425 100644 --- a/src/calibre/spell/import_from.py +++ b/src/calibre/spell/import_from.py @@ -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): - rp = br.open('/'.join((ONLINE_DICTIONARY_BASE_URL, directory, key))) - return rp.read() + 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)