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
PYGLOSSARY_HOME=~/projects/pyglossary
usage="Convert Lingvo DSL source to AppleDict\n
USAGE:\n
=====\n
\t${0##*/} <dictionary.dsl|dictionary.dsl.dz> \n
\n
Assumptions:\n
===========
\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 .dsl.dz files are accepted\n
\n
Dependencies:\n
============\n
- PyGlossary from https://github.com/ilius/pyglossary\n
\tget it from git:\n
\t\tgit clone https://github.com/ilius/pyglossary.git\n
- Command Line Tools for Xcode http://developer.apple.com/downloads\n
- Dictionary Development Kit as part of Auxillary Tools for Xcode <http://developer.apple.com/downloads>_. Extract to /Developer/Extras/Dictionary Development Kit\n
\n
- dictzip, if you need to work with compressed .dz files\n
\n
Also see the pyglossary readme file:\n
https://github.com/ilius/pyglossary/blob/master/README.rst
"
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$#" != "1" ] ; then
echo -e $usage
exit ;
fi
utf16dsl="$1"
is_dictzip=false
if [[ "${utf16dsl}" == *.dz ]] ; then
is_dictzip=true
echo File is compressed! Uncompressing...
dictzip -k -v -d "$utf16dsl"
utf16dsl=${utf16dsl%.dz}
fi
utf8dsl="${utf16dsl%.dsl}_utf8.dsl"
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 ...
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"
fi
echo All Finished!

finnbaer commented Dec 10, 2016 edited

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

FinnbaersMac:projects finnbaer$ ./convert_dsl_to_appledict.sh 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"/build_dict.sh" "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/make_line.pl line 38, <> chunk 4.
    Use of uninitialized value $_ in pattern match (m//) at /Developer/Extras/Dictionary Development Kit/bin/make_line.pl line 39, <> chunk 4.
    Died at /Developer/Extras/Dictionary Development Kit/bin/make_line.pl line 39, <> chunk 4.
    Error.
    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!

Hi,
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 https://drive.google.com/drive/folders/0B6bJQUIZURGpQWF2S3hHT0ppYVE
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