一、总体步骤
- 使用
pyglossary
创建 苹果字典的源数据 - 使用
Dictionary-Development-Kit
创建苹果字典
二、环境搭建
- 字典文件获取
比如
新牛津英汉双解大词典第2版
牛津高阶英汉双解词典(第9版)
或者直接 google 搜索你想用的字典,我比较喜欢用这个字典。
字典库 huzheng 和mdx.mdict.org
- pyglossary 获取
# pyglossary 是 python 的一个模块,我们直接使用pip安装即可
$ pip install pyglossary
$ pip install lxml beautifulsoup4 html5lib # 安装依赖库
$ pip install prompt_toolkit # 安装命令行版本的依赖库
$ pyglossary --help
Note: 苹果设备上使用 python 的版本要大于3.10。
安装python 可以使用brew 安装,也可以找另外一台linux电脑(或虚拟机)制作字典的源数据,再拿到 mac 上制作字典。
- Dictionary-Development-Kit 获取
git clone https://github.com/SebastianSzturo/Dictionary-Development-Kit.git
三、制作过程
- 使用 pyglossary 制作字典源数据 保存到
新牛津英汉双解大词典第2版.apple
文件夹中
$ pyglossary 新牛津英汉双解大词典第2版.mdx 新牛津英汉双解大词典第2版.apple
[INFO] Found 0 mdd files with 0 entries
[INFO] extracting links...
[INFO] extracting links done, sizeof(linksDict)=64
[INFO] wordCount = 124821
[INFO] Failed to detect sourceLang and targetLang from glossary name '新牛津英汉双解大词典'
[INFO] Writing to AppleDict file '/home/vicking/新牛津英汉双解大词典第2版.apple'
/home/vicking/python-venv/lib/python3.11/site-packages/pyglossary/plugins/appledict/_normalize.py:120: MarkupResemblesLocatorWarning: The input looks more like a filename than markup. You may want to open this file and pass the filehandle into Beautiful Soup.
title = BeautifulSoup.BeautifulSoup(
Converting | |█████████████████████████████████████████████████████|%100.0 Time: 0:06:08
[INFO] Writing file '/home/vicking/新牛津英汉双解大词典第2版.apple' done.
[INFO] Running time of convert: 371.2 seconds
- 使用
Dictionary-Development-Kit
制作苹果字典需要的格式
$ cd 新牛津英汉双解大词典第2版.apple
$ # 修改 Makefile 文件中的
DICT_BUILD_TOOL_DIR ="/Applications/Utilities/Dictionary Development Kit"
# 变成
DICT_BUILD_TOOL_DIR ="/Users/test/Dictionary-Development-Kit"
# 注意:后面字串中的内容是刚刚下载的 Dictionary-Development-Kit 的路径
# 要根据实际所在的路径去替换
$ make
$ make install
四、结果
关闭词典,重新打开,偏好设置,添加词典
如果没有错误的话,字典就添加成功了!如下:
参考链接: https://sspai.com/post/43155#!
https://www.readern.com/convert-mdict-to-macos-dictionary.html