Skip to main content

Converts a tab-separated dictionary text file into a macOS .dictionary bundle.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macos_dictionary_builder-0.9.1.tar.gz (169.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

macos_dictionary_builder-0.9.1-py3-none-any.whl (171.8 kB view details)

Uploaded Python 3

File details

Details for the file macos_dictionary_builder-0.9.1.tar.gz.

File metadata

  • Download URL: macos_dictionary_builder-0.9.1.tar.gz
  • Upload date:
  • Size: 169.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for macos_dictionary_builder-0.9.1.tar.gz
Algorithm Hash digest
SHA256 92104b86a7c06b69ef891ac052850c06e52c94187e62d19f7497e6ae2843690f
MD5 012f37978296468413a2138ffd9455a1
BLAKE2b-256 7a54cb6411033385c8ca0172544be2d7cf161f4bdf968fe7b2ffb5f6a4e9a87e

See more details on using hashes here.

File details

Details for the file macos_dictionary_builder-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for macos_dictionary_builder-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8dab654db88e9ed86d12314c95917967b33007a1b386fb072f5372307534b2d5
MD5 739bf0267bb7c28d48c977fced9c5dab
BLAKE2b-256 f9ae30db55a3c7f31925a3581054e94e581b2d9d33ae56adb6b2fffacb747486

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page