Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Convert dictionaries in Lingvo DSL format to AppleDict format. Depends on pyglossary, iconv, OSX Command Line Tools for Xcode, dictzip, and OSX Dictionary Development Kit
#!/usr/bin/env bash
usage="Convert Lingvo DSL source to AppleDict\n
\t${0##*/} <dictionary.dsl|> \n
- pyglossary is located in ~/projects/pyglossary/pyglossary.pyw (edit this script to modify the value)\n
- DSL input file is UTF-16\n
- .dsl and files are accepted\n
- PyGlossary from\n
\tget it from git:\n
\t\tgit clone\n
- Command Line Tools for Xcode\n
- Dictionary Development Kit as part of Auxillary Tools for Xcode <>_. Extract to /Developer/Extras/Dictionary Development Kit\n
- dictzip, if you need to work with compressed .dz files\n
Also see the pyglossary readme file:\n
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$#" != "1" ] ; then
echo -e $usage
exit ;
if [[ "${utf16dsl}" == *.dz ]] ; then
echo File is compressed! Uncompressing...
dictzip -k -v -d "$utf16dsl"
echo utf8dsl= "$utf8dsl"
echo converting "$utf16dsl" to "$utf8dsl"...
iconv -f UTF-16 -t UTF-8 "$utf16dsl" > "$utf8dsl"
echo conversion to UTF-8 done!
echo converting "$utf8dsl" to AppleDictFormat
python3 "$PYGLOSSARY_HOME/pyglossary.pyw" --read-format=ABBYYLingvoDSL --write-format=AppleDict "$utf8dsl" "${utf8dsl%.dsl}.xml"
cd "${utf8dsl%.dsl}"
echo Running make ...
echo running make install...
make install
read -p "run make clean? (press CTR+c to cancel)"
echo cleaning up
make clean
#cleanup and remove unpacked .dz file if exists
if [ $is_dictzip == true ] ; then
read -p "Remove generated files?"
echo deleting generated files...
rm "$utf8dsl"
rm "${utf8dsl%.dsl}.xml"
rm "${utf8dsl%.dsl}.plist"
rm "${utf8dsl%.dsl}.css"
echo removing unpacked .dz file...
rm "$utf16dsl"
echo All Finished!

finnbaer commented Dec 10, 2016

Got multiple errors while trying to convert Lingvo CollinsCobuild dictionary on a Mac:

FinnbaersMac:projects finnbaer$ ./ CollinsCobuildEnEn.lsd
utf8dsl= CollinsCobuildEnEn.lsd_utf8.dsl
converting CollinsCobuildEnEn.lsd to CollinsCobuildEnEn.lsd_utf8.dsl...

iconv: CollinsCobuildEnEn.lsd:1:229: cannot convert
conversion to UTF-8 done!
converting CollinsCobuildEnEn.lsd_utf8.dsl to AppleDictFormat
no Reader class found in ABBYYLingvoDSL plugin, falling back to indirect mode

Writing to file "/Users/finnbaer/projects/CollinsCobuildEnEn.lsd_utf8.xml"
Writing|██████████████████████████████████████████████████|100.0% Time: 00:00:00

Running time of convert: 0.0 seconds
Writing file "CollinsCobuildEnEn.lsd_utf8.xml" done.
Running make ...
"""/Developer/Extras/Dictionary Development Kit"/bin"/" "CollinsCobuildEnEn.lsd_utf8" "CollinsCobuildEnEn.lsd_utf8.xml" "CollinsCobuildEnEn.lsd_utf8.css" "CollinsCobuildEnEn.lsd_utf8.plist"

  • Building CollinsCobuildEnEn.lsd_utf8.dictionary.
  • Cleaning objects directory.
  • Preparing dictionary template.
  • Preprocessing dictionary sources.
    seek() on closed filehandle ARGV at /Developer/Extras/Dictionary Development Kit/bin/ line 38, <> chunk 4.
    Use of uninitialized value $_ in pattern match (m//) at /Developer/Extras/Dictionary Development Kit/bin/ line 39, <> chunk 4.
    Died at /Developer/Extras/Dictionary Development Kit/bin/ line 39, <> chunk 4.
    make: *** [all] Error 1
    running make install...
    echo "Installing into ~/Library/Dictionaries".
    Installing into ~/Library/Dictionaries.
    mkdir -p ~/Library/Dictionaries
    ditto --noextattr --norsrc ./objects/"CollinsCobuildEnEn.lsd_utf8".dictionary ~/Library/Dictionaries/"CollinsCobuildEnEn.lsd_utf8".dictionary
    ditto: can't get real path for source './objects/CollinsCobuildEnEn.lsd_utf8.dictionary'
    make: *** [install] Error 1
    run make clean? (press CTR+c to cancel)
    cleaning up
    /bin/rm -rf ./objects
    All Finished!

I've tried to convert a dsl file to apple dictionary but got errors. Picture is attached. I have no idea what problem is. Could you help me and convert 3 files from dsl to apple dictionary please? Files are here
screen shot 2017-08-14 at 16 55 28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment