From 9551f021eccee094398dc5de6da3cbf3b41bebac Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:17:46 +0200 Subject: [PATCH 1/3] fix incorrectly relative paths 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 --- src/calibre/spell/import_from.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/spell/import_from.py b/src/calibre/spell/import_from.py index be4be5d98b..58287e8f32 100644 --- a/src/calibre/spell/import_from.py +++ b/src/calibre/spell/import_from.py @@ -158,8 +158,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) From a43d86a0afa5260958c7299c7456757fd33b8764 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:46:32 +0200 Subject: [PATCH 2/3] fix alternative string-list representation in xcu A alternative representation for string-list use tag for each item of the list, for example: https://github.com/LibreOffice/dictionaries/tree/master/tr_TR --- src/calibre/spell/import_from.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/spell/import_from.py b/src/calibre/spell/import_from.py index 58287e8f32..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 From 8374353d515bd4ffcf4473c6aaecbcf6b1823793 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:19:29 +0200 Subject: [PATCH 3/3] fix script variante includes in the lang_code Some dictionaries add a script variante in their lang_code, for example: https://github.com/LibreOffice/dictionaries/tree/master/mn_MN --- src/calibre/spell/__init__.py | 3 +++ 1 file changed, 3 insertions(+) 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()