define icon indicating copy to clipboard operation
define copied to clipboard

Feature - Local macOS dictionary as a source

Open Rican7 opened this issue 7 years ago • 3 comments

Currently, define uses all remote (online) sources. A local, expandable dictionary is available on macOS, which would be a great source if it was accessible.

Unfortunately, it seems that the only way to access the dictionary's data is through Core Services, which would require Cocoa bindings to Go and native-compilation (think cgo). There may be another way around this, though.

Also, the only public APIs that exist return the definition in a formatted string format, not in a structured model, which would be a nightmare (if not potentially impossible) to consistently parse.

More information here (for later reference):

  • https://developer.apple.com/documentation/coreservices/dictionary_services
  • http://nshipster.com/dictionary-services/
  • https://github.com/mattt/DictionaryKit
  • https://gist.github.com/mattt/9453538
  • https://apple.stackexchange.com/questions/90040/look-up-a-word-in-dictionary-app-in-terminal
  • https://discussions.apple.com/thread/2679911

Rican7 avatar Mar 22 '18 21:03 Rican7

is it possible to make an offline copy if these online sources?

An offline copy of the entirety of a language dictionary? Not that I know of.

If it was possible, it'd likely be expensive (API calls), or massive.

Rican7 avatar Jul 26 '20 08:07 Rican7

On my computer, if I load ~/Library/Caches/com.apple.DictionaryServices/DictionaryCache.plist it looks like this:

image

The first dictionary is one I installed myself. Looking at the next one:

$ tree $(pbpaste)
/System/Library/AssetsV2/com_apple_MobileAsset_DictionaryServices_dictionaryOSX/1700888691b981116bc46e57553cf4e4f41f2bc3.asset/AssetData/Traditional\ Chinese\ -\ English\ Idioms.dictionary
└── Contents
    ├── Info.plist
    └── Resources
        ├── Body.data
        ├── DefaultStyle.css
        ├── EntryID.data
        ├── EntryID.index
        ├── KeyText.data
        ├── KeyText.index
        ├── ar.lproj
        │   └── InfoPlist.strings
        ├── ca.lproj
        │   └── InfoPlist.strings
        ├── cs.lproj
        │   └── InfoPlist.strings
        ├── da.lproj
        │   └── InfoPlist.strings
        ├── de.lproj
        │   └── InfoPlist.strings
        ├── el.lproj
        │   └── InfoPlist.strings
        ├── en.lproj
        │   └── InfoPlist.strings
        ├── en_AU.lproj
        │   └── InfoPlist.strings
        ├── en_GB.lproj
        │   └── InfoPlist.strings
        ├── es.lproj
        │   └── InfoPlist.strings
        ├── es_419.lproj
        │   └── InfoPlist.strings
        ├── fi.lproj
        │   └── InfoPlist.strings
        ├── fr.lproj
        │   └── InfoPlist.strings
        ├── fr_CA.lproj
        │   └── InfoPlist.strings
        ├── he.lproj
        │   └── InfoPlist.strings
        ├── hi.lproj
        │   └── InfoPlist.strings
        ├── hr.lproj
        │   └── InfoPlist.strings
        ├── hu.lproj
        │   └── InfoPlist.strings
        ├── id.lproj
        │   └── InfoPlist.strings
        ├── it.lproj
        │   └── InfoPlist.strings
        ├── ja.lproj
        │   └── InfoPlist.strings
        ├── ko.lproj
        │   └── InfoPlist.strings
        ├── ms.lproj
        │   └── InfoPlist.strings
        ├── nl.lproj
        │   └── InfoPlist.strings
        ├── no.lproj
        │   └── InfoPlist.strings
        ├── pl.lproj
        │   └── InfoPlist.strings
        ├── pt.lproj
        │   └── InfoPlist.strings
        ├── pt_PT.lproj
        │   └── InfoPlist.strings
        ├── ro.lproj
        │   └── InfoPlist.strings
        ├── ru.lproj
        │   └── InfoPlist.strings
        ├── sk.lproj
        │   └── InfoPlist.strings
        ├── sv.lproj
        │   └── InfoPlist.strings
        ├── th.lproj
        │   └── InfoPlist.strings
        ├── tr.lproj
        │   └── InfoPlist.strings
        ├── uk.lproj
        │   └── InfoPlist.strings
        ├── vi.lproj
        │   └── InfoPlist.strings
        ├── zh_CN.lproj
        │   └── InfoPlist.strings
        ├── zh_HK.lproj
        │   └── InfoPlist.strings
        └── zh_TW.lproj
            └── InfoPlist.strings

41 directories, 46 files

Poking around online, it seems like these dictionaries were originally plain XML, and then at some point Apple changed it to being a custom compressed format. Some put an old version of Apple's Dictionary Development Kit on Github: https://github.com/SebastianSzturo/Dictionary-Development-Kit Maybe looking a that would tell you how to open the .data files.

earthboundkid avatar Feb 24 '23 21:02 earthboundkid

Yeah it would be cool if local dictionaries were accessible

gedw99 avatar Mar 03 '23 07:03 gedw99