move to Github
show how to use fzf+anthy+sdcv
explain how to convert to Kana
Some simple tools for learning Japanese in the terminal.
You can use sdcv as a terminal dictionary. Install it from your package manager and download JMDict-ja-en and Kanjidic2 from https://web.archive.org/web/20230808110043/http://download.huzheng.org/ja/ to ~/.local/share/stardict/dic
.
Once you reach a high enough level, you will want the monolingual daijirin dictionary since it has the most information, but this requires some work since it's copyrighted and in an exoteric format:
convert-daijirin.php
stardict-tools-git
, but it no longers works due to huzheng.org being dead. On Debian you can apt install stardict-tools
.stardict-tabfile daijirin.tab
(Arch) / tabfile daijirin.tab
(Debian)mv daijirin.{dict,idx,ifo} ~/.local/share/stardict/dic
This consists of a zsh script that parses the RADKFILE, and a shell function that lets you select a kanji with fzf, and looks it up in sdcv.
curl http://ftp.edrdg.org/pub/Nihongo/radkfile.gz | gunzip | iconv -f EUC-JP -t UTF-8 -o ${XDG_DATA_HOME:-~/.local/share}/radkfile
radicals.zsh
to ~/.local/lib
zshrc
/bashrc
: radicals() { ~/.local/lib/radicals.zsh $(awk '/^\$/ {print NR,$2,$3 }' ${XDG_DATA_HOME-~/.local/share}/radkfile | fzf -m --with-nth=2,3 --bind=ctrl-l:jump --preview='~/.local/lib/radicals.zsh {+1}' | cut -d ' ' -f 1) | fzf --bind=ctrl-l:jump-accept | sdcv --color; }
You use this by selecting the radicals of the kanji you want to look up and pressing Tab. You can filter the selections by typing the stroke count, and can move down with Ctrl+j or by showing labels you can jump to with Ctrl+l (mnemonic: label). As you select radicals, the preview window will the show the kanji that contain them. Once you find your kanji, press enter, select it in the new fzf instance, and sdcv will show its definition.
A lightweight alternative to IBus that interacts with Anthy on standard input and output. This converts one word + one particle at a time, so it's only viable if you mostly just read Japanese rather than writing it.
anthy.patch
with patch -p1 < /path/to/japanese-cli/anthy.patch
. This removes most printf calls and makes it read from standard input./configure && make
CARGO_HOME=~/.local/share/cargo cargo install to-kana
for a program that converts romaji to hiraganawtype $(fzfmenu --disabled --bind='change:reload(cd /path/to/anthy/test; ~/.local/share/cargo/bin/to-kana hira {q} | ./anthy),ctrl-l:jump-accept' < /dev/null)
change:reload(~/.local/share/cargo/bin/to-kana hira {q})
and change:reload(~/.local/share/cargo/bin/to-kana hira {q})
can be used to convert romaji to Hiragana and Katana insteadThis modified Anthy can then also used to convert romaji to Japanese programamtically in scripts. For example, this lets you select a Kanji conversion with fzf and shows its sdcv's translation in fzf's preview window: fzf --disabled --bind='change:reload(cd /path/to/anthy/test; ~/.local/share/cargo/bin/to-kana hira {q} | ./anthy),ctrl-l:jump' --preview='sdcv -n --color {}' --preview-window='85%,border-left,wrap,<60(75%,down,border-top)' < /dev/null