Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader

Notices

Reply
 
Thread Tools Search this Thread
Old 07-20-2023, 10:13 AM   #1
Legrumsx
Junior Member
Legrumsx began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2023
Device: Kobo Sage
Anyone managed to use converted Apple Dict?

Hi, new joiner here

On iPad/mac/iPhone there are really good built-in dictionaries. I managed to get the dictionaries data from my iPad, then I used pyglossary to convert them to dicthtml-XX.zip and add them to the \.kobo\custom-dict folder
The dictionary is detected, but most of the time it doesn't find the word and when it does, there is no CSS formatting so it's unusable.

Has anyone ever managed to properly convert them to Kobo format?

Later, I saw that KOreader supports Stardict format so I installed it on my device and because I am also using those Apple Dictionaries with GoldenDict on my PC I knew the conversion was successful, even the CSS formatting is like on my iPad.

But here again, after putting the converted dict to \.adds\koreader\data\dict, I see that there is a new entry in the list, but I never got it to display a definition, let alone a properly formatted one.

I managed to install open source dictionaries instead, but they are far inferior, even compared to the stock dictionaries. So I would appreciate some help.

(I can provide the files on demand as there would be probably copyright issues.)

Legrumsx is offline   Reply With Quote
Old 07-21-2023, 11:10 PM   #2
woaitsbren
Junior Member
woaitsbren began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jul 2023
Device: Kobo Clara HD
I’m interested in this as well, could you send over the raw apple dictionary files? I’ll take a look tomorrow and see what I can do!
woaitsbren is offline   Reply With Quote
Advert
Old 07-30-2023, 04:22 PM   #3
Legrumsx
Junior Member
Legrumsx began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2023
Device: Kobo Sage
If anyone is interest, I did manage the conversion to Stardict format to use with KOreader, which I found way better.
I first converted the apple dictionaries to the Stardict XML format using pyglossary. This format is human readable and I could see some things which were suspicious compared to working Wiki dictionaries.
I wrote this Python script to do some clean-up:
Code:
import sys
import re
import fileinput
import shutil
import os

def replace_in_xml(xml_file_path):
    # Define the regular expression patterns and replacement strings
    patterns_to_replace = {
        r'<d:': '<',
        r'</d:': '</',
        r'soundFile="(.+?)" ': ' ',
        r'soundFile="(.+?)">': '>',
        r'source="(.+?)" ': ' ',
        r'source="(.+?)">': '>',
        r'<!DOCTYPE html><html><head><link rel="stylesheet" href="style.css"></head>': '',
        r' href="(.+?)"': ' ',
        r'<span d:': '<span '
        # Add more patterns and replacements as needed
    }

    try:
        # Create a temporary file for writing the updated content
        with open(xml_file_path + '.tmp', mode='w', encoding='utf-8') as tmp_file:
            with fileinput.FileInput(xml_file_path, openhook=fileinput.hook_encoded("utf-8")) as file:
                for line in file:
                    for pattern, replacement in patterns_to_replace.items():
                        line = re.sub(pattern, replacement, line)
                    tmp_file.write(line)

        # Replace the original file with the updated content
        shutil.move(xml_file_path + '.tmp', xml_file_path)

    except FileNotFoundError:
        print(f"Error: File '{xml_file_path}' not found.")
    except Exception as e:
        print(f"Error occurred: {str(e)}")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python cleanse_apple_xml.py <xml_file_path>")
    else:
        xml_file_path = sys.argv[1]
        replace_in_xml(xml_file_path)

And then I converted the files to the Stardict ifo format.
For the formatting, I took the css from apple and did some clean up with various tools.

Here a link to the CSS file (there are still some quirks), it should be in the same folder as the .ifo and have the same name.
https://pastebin.com/u2puYFRZ
Legrumsx is offline   Reply With Quote
Reply

Tags
kobo sage, koreader, pyglossary, stardict

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CBR images converted to greyscale in EPUB/AZW3 converted files csscribus Conversion 5 12-27-2020 08:59 PM
PRS-T2 German dict licinio Sony Reader 0 06-25-2015 06:04 PM
Saving a converted epub file for upload to Kobo or Apple rhking Library Management 1 05-16-2014 09:38 AM
dict.cc Wörterbuch Moredread PocketBook 18 02-08-2011 03:44 AM


All times are GMT -4. The time now is 09:01 PM.


MobileRead.com is a privately owned, operated and funded community.