使用 PyGlosssary 將 StarDict 轉為 Mac Dictionary

環境: macOS Big Sur (Apple M1)

安裝 Dictionary Development Kit

從以下網址 下載 Additional Tools for Xcode

https://developer.apple.com/download/all/

得到 Additional_Tools_for_Xcode_13_Release_Candidate.dmg

開啟 .dmg

將 Utilities/Dictionary Development Kit 資料夾 移到: /Applications/Utilities/

安裝 PyGlossary

install python3


$ pip3 install lxml beautifulsoup4 html5lib

download pyglossary from GitHub: https://github.com/ilius/pyglossary

使用 PyGlossary 從 StarDict 轉 Apple Dict Source

準備 工作資料夾,以下假設資料夾名稱 BASE

將下載的 pyglossary 放到 BASE/pyglossary

$ cd BASE/pyglossary

查看 PyGlossary 支援的 輸入檔案格式、輸出檔案格式

$ python3 main.py --help

假設 StarDict 辭典檔放在 BASE/stardict/test

將 StarDict 檔 轉為 Apple Dict Source

$ python3 main.py ../stardict/test/test.dict.ifo ../apple-dict-source/test --write-format=AppleDict

實際操作時,將上面的 test.dict.ifo 改為真正的 .ifo 檔名,
並將輸出的 ../apple-dict-source/test 的 test 改為將來的 Apple Dictionary 名稱.

Build

$ cd BASE/apple-dict-source/test

檢查 Makefile 裡的 DICT_BUILD_TOOL_DIR 指到:

"/Applications/Utilities/Dictionary Development Kit"

The dictionary name is the same as CFBundleName in the Info.plist,

and the bundle name is DICT_NAME in the Makefile.

$ make

Finished building ./objects/test.dictionary.

安裝辭典

在 Finder 中,按一下選單列中的「前往」選單,

按住 Option 鍵,選擇「資源庫」並將找到「Dictionaries」資料夾,

將剛剛製作的 .dictionary 字典檔複製到「Dictionaries」資料夾,現在字典已經安裝好了。

在應用程式資料夾中找到「辭典」並執行,

在偏好設定中將「剛剛安裝的字典檔」打勾並拖曳順序,之後查詢時就會按照排序顯示自訂的辭典。