A tool for converting dictionary files aka glossaries.
The primary purpose is to be able to use our offline glossaries in any Open Source dictionary we like on any OS/device.
There are countless formats, and my time is limited, so I implement formats that seem more useful for myself, or for Open Source community. Also diversity of languages is taken into account. Pull requests are welcome.
Linux - Gtk3-based interface
Windows - Tkinter-based interface
Linux - command-line interface
Android Termux - interactive command-line interface
Format | Extension | Read | Write | |
---|---|---|---|---|
Aard 2 (slob) | π’ | .slob | β | β |
ABBYY Lingvo DSL | π | .dsl | β | |
Almaany.com (SQLite3, Arabic) | π’ | .db | β | |
AppleDict Binary | π’ | .dictionary | β | β |
AppleDict Source | π | β | ||
Babylon BGL | π’ | .bgl | β | β |
CC-CEDICT (Chinese) | π | β | β | |
cc-kedict (Korean) | π | β | β | |
CSV | π | .csv | β | β |
Dict.cc (SQLite3, German) | π’ | .db | β | |
DICT.org / Dictd server | π | (π.index) | β | β |
DICT.org / dictfmt source | π | (.dtxt) | β | |
dictunformat output file | π | (.dictunformat) | β | |
DictionaryForMIDs | π | (π.mids) | β | β |
DigitalNK (SQLite3, N-Korean) | π’ | .db | β | |
EDLIN | π | .edlin | β | β |
EPUB-2 E-Book | π¦ | .epub | β | β |
FreeDict | π | .tei | β | β |
Gettext Source | π | .po | β | β |
HTML Directory (by file size) | π | β | β | |
JMDict (Japanese) | π | β | β | |
JSON | π | .json | β | |
Kobo E-Reader Dictionary | π¦ | .kobo.zip | β | β |
Kobo E-Reader Dictfile | π | .df | β | β |
Lingoes Source | π | .ldf | β | β |
Mobipocket E-Book | π’ | .mobi | β | β |
Octopus MDict | π’ | .mdx | β | β |
Sdictionary Binary | π’ | .dct | β | |
Sdictionary Source | π | .sdct | β | |
SQL | π | .sql | β | β |
StarDict | π | (π.ifo) | β | β |
Tabfile | π | .txt, .tab | β | β |
Wiktionary Dump | π | .xml | β | β |
Wordset.org | π | β | ||
XDXF | π | .xdxf | β | β |
Zim (Kiwix) | π’ | .zim | β |
Legend:
- π Directory
- π Text file
- π¦ Package/archive file
- π’ Binary file
- β Supported
- β Will not be supported
Note: SQLite3 .db
files are not detected by extension; So you need to specify the format.
PyGlossary requires Python 3.7 or higher, and works in practically all modern operating systems. While primarily designed for GNU/Linux, it works on Windows, Mac OS X and other Unix-based operating systems as well.
As shown in the screenshots, there are multiple User Interface types (multiple ways to use the program).
-
Gtk3-based interface, uses PyGI (Python Gobject Introspection) You can install it on:
- Debian/Ubuntu:
apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0
- openSUSE:
zypper install python3-gobject gtk3
- Fedora:
dnf install pygobject3 python3-gobject gtk3
- ArchLinux:
pacman -S python-gobject gtk3
- https://aur.archlinux.org/packages/pyglossary/
- Mac OS X:
brew install pygobject3 gtk 3
- Nix / NixOS:
nix-shell -p gnome3.gobjectIntrospection python38Packages.pygobject3 python38Packages.pycairo
- Debian/Ubuntu:
-
Tkinter-based interface, works in the lack of Gtk. Specially on Windows where Tkinter library is installed with the Python itself. You can also install it on:
- Debian/Ubuntu:
apt-get install python3-tk tix
- openSUSE:
zypper install python3-tk tix
- Fedora:
yum install python3-tkinter tix
- Mac OS X: read https://www.python.org/download/mac/tcltk/
- Nix / NixOS:
nix-shell -p python38Packages.tkinter tix
- Debian/Ubuntu:
-
Command-line interface, works in all operating systems without any specific requirements, just type:
python3 main.py --help
- Interactive command-line interface
- Requires:
pip3 install prompt_toolkit
- Perfect for mobile devices (like Termux on Android) where no GUI is available
- Automatically selected if output file argument is not passed and one of these:
- On Linux and
$DISPLAY
environment variable is empty or not set- For example when you are using a remote Linux machine over SSH
- On Mac and no
tkinter
module is found
- On Linux and
- Manually select with
--cmd
or--ui=cmd
- Minimally:
python3 main.py --cmd
- You can still pass input file, or any flag/option
- Minimally:
- If both input and output files are passed, non-interactive cmd ui will be default
- If you are writing a script, you can pass
--no-interactive
to force disable interactive ui- Then you have to pass both input and output file arguments
- Don't forget to use Up/Down or Tab keys in prompts!
- Up/Down key shows you recent values you have used
- Tab key shows available values/options
- You can press Control C (on Linux/Windows) at any prompt to exit
- Requires:
- Interactive command-line interface
When you run PyGlossary without any command-line arguments or options/flags,
PyGlossary tries to find PyGI and open the Gtk3-based interface. If it fails,
it tries to find Tkinter and open the Tkinter-based interface. If that fails,
it tries to find prompt_toolkit
and run interactive command-line interface.
And if none of these libraries are found, it exits with an error.
But you can explicitly determine the user interface type using --ui
python3 main.py --ui=gtk
python3 main.py --ui=tk
python3 main.py --ui=cmd
- Download and install Python (3.8 or 3.9 is recommended)
- Open Start -> type Command -> right-click on Command Prompt -> Run as administrator
- To ensure you have
pip
, run:python -m ensurepip --upgrade
- To install, run:
pip install --upgrade pyglossary
- Now you should be able to run
pyglossary
command - If command was not found, make sure Python environment variables are set up:
-
Using
--remove-html-all
flagsudo pip3 install lxml beautifulsoup4
Some formats have additional requirements. Please check the links given for each format to see documentations.
Using Termux on Android? See doc/termux.md
If you want to add your own plugin without adding it to source code directory, or you want to use a plugin that has been removed from repository, you can place it in this directory:
- Linux or BSD:
~/.pyglossary/plugins/
- Mac:
~/Library/Preferences/PyGlossary/plugins
- Windows:
C:\Users\USERNAME\AppData\Roaming\PyGlossary\plugins
A glossary contains a number of entries.
Each entry contains:
- Headword (title or main phrase for lookup)
- Alternates (some alternative phrases for lookup)
- Definition
In PyGlossary, headword and alternates together are accessible as a single Python list entry.l_word
entry.defi
is the definition as a Python Unicode str
. Also entry.b_defi
is definition in UTF-8 byte array.
entry.defiFormat
is definition format. If definition is plaintext (not rich text), the value is m
. And if it's in HTML (contains any html tag), then defiFormat
is m
. The value x
is also allowed for XFXF, but XDXF is not widely supported in dictionary applications.
There is another type of Entry
which is called Data Entry, and generally contains image files, TTL or other audio files, or any file that was included in input glossary. For data entries:
entry.s_word
is file name (andl_word
is still a list containing this string),entry.defiFormat
isb
entry.data
gives the content of file inbytes
.