苹果字典制作(使用 pyglossary no ui模式)

一、总体步骤

  1. 使用 pyglossary 创建 苹果字典的源数据
  2. 使用Dictionary-Development-Kit 创建苹果字典

二、环境搭建

  1. 字典文件获取
    比如
    新牛津英汉双解大词典第2版
    牛津高阶英汉双解词典(第9版)
    或者直接 google 搜索你想用的字典,我比较喜欢用这个字典。

字典库 huzhengmdx.mdict.org

  1. 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 上制作字典。

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

三、制作过程

  1. 使用 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
  1. 使用 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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值