Skip to main content

macOS Dictionary Builder

Python script to convert a tabular text file into a macOS .dictionary bundle.

  • Special feature: translations in Spotlight results

Install

pip3 install macos-dictionary-builder

Build your own dictionary

Download your own copy of the Vocabulary Database from dict.cc. Then run this script on the extracted txt file.

Easy-usage script

Choose one, both of these are equivalent:

macos-dictionary-builder de-en.txt
python3 -m macos_dictionary_builder de-en.txt

Python module usage

from macos_dictionary_builder import parse, meta, devkit

# step 1: parse translation entries
with open('sample.txt', 'r') as fp:
    count = parse.makeDictXML(fp, 'data.xml')
    print(count, 'entries')

# step 2: create metadata
plist = meta.makeMetaPlistDict('bundleId', name='...', ...)
meta.writeMetaPlist('meta.plist', plist)

# step 3: create dictionary
devkit.callDevKitScript('Sample.dictionary', xml='data.xml', plist='meta.plist', compress=True)

or call the individual modules separately:

python3 -m macos_dictionary_builder.parse sample.txt -o data.xml
python3 -m macos_dictionary_builder.meta meta.plist -b uid -n Sample ...
python3 -m macos_dictionary_builder.devkit Sample data.xml meta.plist --compress

About this project

I've been using the pre-compiled dictionary by dict.cc. My workflow: type a word into Spotlight and immediately get a translation for the word. But ever since macOS 10.15 (or so), Spotlight stopped doing that. The Spotlight entry would just show my searched word, but no translation. Till now, I was forced to open the Dictionary app to see the translation.

So, after years of postponing, I finally found time to follow up on this project. Initially, I hoped to rebuild a new dictionary with the old python script by bernie43. However, the script is very old (Python 2) and does not work anymore. I've also seen the new repo by LeChatParle who ported the code to Python 3, but even this repo does not show the translation in Spotlight.

After a few modifications to the old code, I threw away everything and started from scratch. My code is a bit more modular but still restricted to the dict.cc style of formatting (one line per translation). E.g. the beolingus format won't work because each line contains multiple translations and plurals.

Future work: additional parsers for other formats.

Dictionary Development Kit

This project relies on the Dictionary Development Kit by Apple. The bundled version is extracted from Additional Tools for Xcode 12.5 (latest for macOS 10.15). If you want a newer version, download via the link above and place it in:

~/.config/macos_dictionary_builder/Dictionary Development Kit

Metadata

Release files for macos-dictionary-builder 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for macos-dictionary-builder 0.9.3
File Size Uploaded Provenance
macos_dictionary_builder-0.9.3.tar.gz 170.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for macos-dictionary-builder 0.9.3
File Interpreter ABI Platform
macos_dictionary_builder-0.9.3-py3-none-any.whl Python 3 none any Details

Total release size: 342.1 kB

Release files / macos_dictionary_builder-0.9.3.tar.gz

Download URL macos_dictionary_builder-0.9.3.tar.gz
Size 170.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d6e6510fa0bded5731be0903287a36880b538a1c0aec24c159cb2dd814c51b85
BLAKE2b-256 checksum
How to use checksums
c9df34ab16f579e58d378b9d7f881eecd8c49866f050e64b6159ef29654405c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / macos_dictionary_builder-0.9.3-py3-none-any.whl

Download URL macos_dictionary_builder-0.9.3-py3-none-any.whl
Size 172.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
435f4087066f2b2d5a9b3860f7dd7f86f91116d287931aea02951f759c4a23a5
BLAKE2b-256 checksum
How to use checksums
230ab5132b21594095dfc4f19d09fa601d74e353660f2580bd27b8f6f0b425c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for macos-dictionary-builder 0.9.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page