This couple of scripts use dunst and xsel and the CEDICT text based dictionary to provide definitions of mandarin chinese characters. Currently at a very basic but functional state. Inspired by the Zhongwen browser extension. Supports simplified chinese, although it can be set to recognize traditional characters with a little bit of tweaking.
This program has the advantage of working outside and inside of the browser, so for example on a pdf reader or anywhere where mandarin text can be selected with the mouse.
-
dunst notifications daemon with
dunstify
.Other daemons might work, you could also run dunst and nvhair in parallel with some
dbus-run-session
magic, probably. -
xsel, the tool used by the script to get your text selection.
-
GNU awk
-
some linux literacy
- Clone the repo and place the files
nvhair
andnv.awk
somewhere in your$PATH
, I use$HOME/.local/bin
. (usechmod +x
to grant them execution permission) - Download the CEDICT free dictionary (CEDICT) in
.gz
format. - Unpack it and tweak it with it with:
cat cedict_1_0_ts_utf-8_mdbg.txt.gz | gzip -d | dos2unix | cat - <(echo) > cedict_1_0_ts_utf-8_mdbg.txt
- Dictionary needs sorting, use the sorting script
sortit.py
to generate a sorted version:python sortit.py #generates file dicout mkdir -p "$HOME/.local/share/cedict" mv dicout "$HOME/.local/share/cedict/cedict.txt" # put the dictionary where nvhair expects it
- done, now just set up a keyboard shortcut to run the command
nvhair
after you select some chinese text
- Select some chinese text with your mouse
- Run the program
nvhair
(most practically by a keyboard shortcut) - That's it, a popup notification should appear with different defintions lifted from the CEDICT dictionary.