A tool for converting dictionary files aka glossaries.
Project description
PyGlossary
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.
Screenshots
Linux - Gtk3-based interface
Windows - Tkinter-based interface
Linux - command-line interface
Android Termux - interactive command-line interface
Web interface
Supported formats
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-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 | โ | |
DIKT JSON | ๐ | (.json) | โ | |
EDICT2 (CEDICT) (Chinese) | ๐ | (.u8) | โ | โ |
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 | โ | โ |
QuickDic version 6 | ๐ | .quickdic | โ | โ |
SQL | ๐ | .sql | โ | โ |
StarDict | ๐ | (๐.ifo) | โ | โ |
StarDict Textual File | ๐ | (.xml) | โ | โ |
Tabfile | ๐ | .txt, .tab | โ | โ |
Wiktextract | ๐ | .jsonl | โ | |
Wordset.org | ๐ | โ | ||
XDXF | ๐ | .xdxf | โ | โ |
Yomichan | ๐ฆ | (.zip) | โ | |
Zim (Kiwix) | ๐ข | .zim | โ |
Legend:
- ๐ Directory
- ๐ Text file
- ๐ฆ Package/archive file
- ๐ข Binary file
- โ Supported
- โ Will not be supported
Note: SQLite-based formats are not detected by extension (.db
);
So you need to select the format (with UI or --read-format
flag).
Also don't confuse SQLite-based formats with SQLite mode.
Requirements
PyGlossary requires Python 3.10 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 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 pkgs.gobject-introspection python38Packages.pygobject3 python38Packages.pycairo
- Debian/Ubuntu:
-
Tkinter-based interface, meant to be used in the lack of Gtk. Specially on Windows where Tkinter library is installed with 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
./main.py --help
orpyglossary --help
- Interactive command-line interface
- Requires:
pip 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:
./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
UI (User Interface) selection
When you run PyGlossary without any command-line arguments or options/flags, PyGlossary will try to run the first available interface in this order:
- It tries to find PyGI+Gtk3 and open Gtk3-based interface.
- It tries to find PyGI+Gtk4 and open Gtk4-based interface.
- It tries to find Tkinter and open Tkinter-based interface.
- If it's run in command line (with stdin connected to a terminal) it tries to find
prompt_toolkit
and run interactive command-line interface. - It runs a HTTP server and opens the web interface in your browser.
But you can explicitly select user interface type using --ui
./main.py --ui=gtk
./main.py --ui=gtk4
./main.py --ui=tk
./main.py --ui=web
./main.py --ui=cmd
Installation on Windows
- Download and install Python (3.10 or above)
- 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:
Feature-specific requirements
-
Using Sort by Locale feature requires PyICU
-
Using
--remove-html-all
flag requires:pip install lxml beautifulsoup4
Some formats have additional requirements. If you have trouble with any format, please check the link given for that format to see its documentations.
Using Termux on Android? See doc/termux.md
Configuration
See doc/config.rst.
Direct and indirect modes
Indirect mode means that input glossary is completely read and loaded into RAM, then converted into output format. This was the only method available in old versions (before 3.0.0).
Direct mode means entries are one-at-a-time read, processed and written into output glossary.
Direct mode was added to limit memory usage for large glossaries; But it may reduce the conversion time for most cases as well.
Converting glossaries into these formats requires sorting entries:
That's why direct mode will not work for these formats, and PyGlossary has to switch to indirect mode (or it previously had to, see SQLite mode).
For other formats, direct mode will be default. You may override this by --indirect
flag.
SQLite mode
As mentioned above, converting glossaries to some specific formats will need them to loaded into RAM.
This can be problematic if the glossary is too big to fit into RAM. That's when
you should try adding --sqlite
flag to your command. Then it uses SQLite3 as intermediate
storage for storing, sorting and then fetching entries. This fixes the memory issue, and may
even reduce running time of conversion (depending on your home directory storage).
The temporary SQLite file is stored in cache directory then
deleted after conversion (unless you pass --no-cleanup
flag).
SQLite mode is automatically enabled for writing these formats if auto_sqlite
config parameter is true
(which is default).
This also applies to when you pass --sort
flag for any format.
You may use --no-sqlite
to override this and switch to indirect mode.
Currently you can not disable alternates in SQLite mode (--no-alts
is ignored).
Sorting
There are two things than can activate sorting entries:
- Output format requires sorting (as explained above)
- You pass
--sort
flag in command line.
In the case of passing --sort
, you can also pass:
-
--sort-key
to select sort key aka sorting order (including locale), see doc/sort-key.md -
--sort-encoding
to change the encoding used for sort- UTF-8 is the default encoding for all sort keys and all output formats (unless mentioned otherwise)
- This will only effect the order of entries, and will not corrupt words / definition
- Non-encodable characters are replaced with
?
byte (only for sorting)
Cache directory
Cache directory is used for storing temporary files which are either moved or deleted
after conversion. You can pass --no-cleanup
flag in order to keep them.
The path for cache directory:
- Linux or BSD:
~/.cache/pyglossary/
- Mac:
~/Library/Caches/PyGlossary/
- Windows:
C:\Users\USERNAME\AppData\Local\PyGlossary\Cache\
User plugins
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\
Linux packaging status
Using PyGlossary as a library
See doc/lib-usage.md for how to use PyGlossary as a Python library.
Internals
See doc/internals.md for information about internal glossary structure and entry filters.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyglossary-5.0.2.tar.gz
.
File metadata
- Download URL: pyglossary-5.0.2.tar.gz
- Upload date:
- Size: 437.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f19bb1c84aed8ec561c562c46bd555ae7aa6aa9abe1c506dd9b25c72c78cdc63 |
|
MD5 | fae4a90145ff52e9afba64965656214a |
|
BLAKE2b-256 | 223cb55a701d63b1785e54e188642706f93eb88f5ce0a41db3f4ed9af2287421 |
File details
Details for the file pyglossary-5.0.2-py3-none-any.whl
.
File metadata
- Download URL: pyglossary-5.0.2-py3-none-any.whl
- Upload date:
- Size: 574.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75b25b1b511fbf4ad2e83acadc7c74789c6cf6048e0641393307a164671328e2 |
|
MD5 | 9be86093534eebac50dd5564fc966a59 |
|
BLAKE2b-256 | 71388a6099dffbe12a339f405cb8625f51d4d57375de62234ae7b446d5c0ee8a |