Skip to main content

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


Linux - interactive command-line interface

Supported formats

Format Extension Read Write
Aard 2 (slob) ๐Ÿ”ข .slob โœ” โœ”
ABBYY Lingvo DSL ๐Ÿ“ .dsl โœ”
AppleDict Binary ๐Ÿ”ข .dictionary โœ” โŒ
AppleDict Source ๐Ÿ“ โœ”
Babylon ๐Ÿ”ข .bgl โœ” โŒ
CC-CEDICT (Chinese) ๐Ÿ“ โœ” โŒ
cc-kedict (Korean) ๐Ÿ“ โœ” โŒ
CSV ๐Ÿ“ .csv โœ” โœ”
Dict.cc (SQLite3, German) ๐Ÿ”ข โœ”
DICT.org / Dictd server ๐Ÿ“ (๐Ÿ“.index) โœ” โœ”
DICT.org / dictfmt source file ๐Ÿ“ (.dtxt) โœ”
dictunformat output file ๐Ÿ“ (.dictunformat) โœ”
DictionaryForMIDs ๐Ÿ“ (๐Ÿ“.mids) โœ” โœ”
DigitalNK (SQLite3, N-Korean) ๐Ÿ”ข โœ”
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 โœ” โœ”
Octopus MDict ๐Ÿ”ข .mdx โœ” โŒ
Sdictionary Binary ๐Ÿ”ข .dct โœ”
Sdictionary Source ๐Ÿ“ .sdct โœ”
SQL ๐Ÿ“ .sql โŒ โœ”
StarDict ๐Ÿ“ (๐Ÿ“.ifo) โœ” โœ”
Tabfile ๐Ÿ“ .txt, .tab โœ” โœ”
TreeDict ๐Ÿ“ โœ”
Wiktionary Dump ๐Ÿ“ .xml โœ” โŒ
Wordset.org ๐Ÿ“ โœ”
XDXF ๐Ÿ“ .xdxf โœ” โŒ
Zim (Kiwix) ๐Ÿ”ข .zim โœ”

Legend:

  • ๐Ÿ“ Directory
  • ๐Ÿ“ Text file
  • ๐Ÿ“ฆ Package/archive file
  • ๐Ÿ”ข Binary file
  • โœ” Supported
  • โŒ Will not be supported

Requirements

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:
    • Mac OS X: brew install pygobject3 gtk+3
    • Nix / NixOS: nix-shell -p gnome3.gobjectIntrospection python38Packages.pygobject3 python38Packages.pycairo
  • 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
  • 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
      • Manually select with --cmd or --ui=cmd
        • Minimally: python3 main.py --cmd
        • You can still pass input file, or any flag/option
      • 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

When you run the program without any command-line arguments or options, PyGlossary tries to find PyGI, if it's installed, opens the Gtk3-based interface, if it's not, tries to find Tkinter and open the Tkinter-based interface. And exits with an error if neither are installed.

But you can explicitly determine the user interface type using --ui, for example:

python3 main.py --ui=gtk

Or

python3 main.py --ui=tk

Feature-specific Requirements

  • Using --remove-html-all flag

    sudo pip3 install lxml beautifulsoup4

  • Reading from FreeDict, XDXF or JMDict

    sudo pip3 install lxml

  • Reading from cc-kedict

    sudo pip3 install lxml PyYAML

  • Reading from Babylon BGL: Python 3.6 to 3.7 is recommended

  • Reading or writing Aard 2 (.slob) files

    sudo pip3 install PyICU

  • Writing to Kobo E-Reader Dictionary

    sudo pip3 install marisa-trie

  • Reading from Zim (see #228)

    sudo pip3 install libzim

  • Reading from CC-CEDICT

    sudo pip3 install jinja2

  • Reading from Octopus MDict (MDX)

    python-lzo is required for some MDX glossaries. First try converting your MDX file, if failed (AssertionError probably), then try to install LZO library and Python binding.

Using Termux on Android? See doc/termux.md

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: ~/.pyglossary/plugins/
  • Mac: ~/Library/Preferences/PyGlossary/plugins
  • Windows: C:\Users\USERNAME\AppData\Roaming\PyGlossary\plugins

AppleDict

See doc/apple.md for AppleDict requirements and instructions.

Internal Glossary Structure

A glossary contains a number of entries.

Each entry contains:

  • Headword (title or main phrase for query)
  • Alternates (some alternative phrases for query)
  • 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 (and l_word is still a list containing this string),
  • entry.defiFormat is b
  • entry.data gives the content of file in bytes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyglossary-4.0.3.tar.gz (311.3 kB view hashes)

Uploaded Source

Built Distribution

pyglossary-4.0.3-py3-none-any.whl (364.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page