How to Convert .mdx Dictionary to AppleDict Format

How to Convert .mdx Dictionary to AppleDict Format

When you got a third-party dictionary database and want to use it in Apple’s own dictionary software on MacOS, you can follow this guide.

Highly recommend an open source dict: ECDICT, developed by Skywind

Install the necessary packages

Tips: if you run the follow commands on Apple Silicon platform, you need to replace `/usr/local` to `/opt/homebrew`

# install base packages
pip3 install lxml beautifulsoup4 html5lib
brew install lzo

# config ENV
export C_INCLUDE_PATH=/usr/local/Cellar/lzo/2.10/include/lzo:/usr/local/Cellar/lzo/2.10/include/
export LIBRARY_PATH=/usr/local/lib

# install python-lzo
pip3 install python-lzo

Download Dictionary Development Kit

git clone https://github.com/SebastianSzturo/Dictionary-Development-Kit

Download the key tool: pyglossary

git clone https://github.com/ilius/pyglossary

Convert *.mdx to AppleDict format

python3 ~/Developer/ConvertDict/pyglossary/main.py --write-format=AppleDict

Wait for a while when processing…

Build and install the dict

  1. Enter into the directory created by the last command above, e.g.

2. Modify the Makefile, set the value of DICT_BUILD_TOOL_DIR to the path of Dictionary-Development-Kit which you just downloaded before.
MUST be an ABSOLUTE path.
For me, it looks like below:

3. Run command: `make`, after that, the target is under directory: `./objects`.
The process will hang for a long time on the step of ‘Adding body data’(for me, it took nearly 20 hours fro [ECDICT](https://github.com/skywind3000/ECDICT) with a size of 150MB), wait again…

4. Copy css file into `objects` and rename it to DefaultStyle.css (overwrite DefaultStyle.css)

5. Set display name. Modify fields `Bundle name` and `Bundle display name` in `info.plist` to the target dictionary name.

6. Run command `make install` and then the dictionary will be installed in `~/Library/Dictionaries`

Finally, you can add the dictionary in Dictonary.app

Refer: https://www.readern.com/convert-mdict-to-macos-dictionary.html