Skip to content

πŸ“” An adapter to import your lookups from GoldenDict to Anki.

License

Notifications You must be signed in to change notification settings

everbird/ohmyvocabulary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“– oh-my-vocabulary

An adapter to import your lookups from GoldenDict to Anki. It also exports your learned words to a plain text file managed by Dropbox.

What problem does it solve?

GoldenDict is a customizable dictionary lookup program. Anki is a powerful flashcard program. Both of them are great, but the experience of putting them together is meh :(

As a user of both, I would like to:

  1. Use GoldenDict to look up a new word.
  2. Import the new word into Anki automagically.
  3. Mark the new word as known when learned in Anki.
  4. Maintain a list of my "known" words for further usage.
  5. Sync between devices (mbp, ubuntu@thinkpad, iOS, etc.)

Furthermore, it would be great if I can do the above in a program-friendly, automatable way.

Unfortunately, I didn't find an out-of-box solution to meet my needs yet. So I build this on my own :)

How does it work?

1) Collect my lookup history from GoldenDict

When you look up a word in GoldenDict, it runs a script named tosink with input %GDWORD% as this word. tosink is configured in Dictionaries->Sources->Programs beforehand. It appends this word in sink.txt, which is a plain text file managed in Dropbox.

2) Import new words from above into Anki

ECDICT is a well-maintained open-source En-Zh dictionary. First, We can use mdict-utils to extracts an SQLite database from the mdx file as a cache to speed up the query. Then omv queries each word in the sink.txtto get the HTML of paraphrases. Finally, omv calls apy to add a new Note to Anki for each word. The Note uses the word as the front and the HTML-format paraphrase as the back.

3) Sync Anki to AnkiWeb

omv calls apy sync to do so. (Credits to apy)

4) Update the known.txt

For a learned word, you can mark it as "suspended" in Anki so that it won't show up in further reviews. omv calls apy list to get all suspended words. Then it appends new suspened words to the known.txt.

Getting Started

Prerequisites

  • A Unix-like operating system: macOS, Linux, BSD.
  • Anki should be installed (compatible with 2.1.42 as of March 2021)
  • GoldenDict should be installed (compatible with 1.5.0-RC2 as of March 2021)
  • git should be installed
  • wget should be installed
  • pyenv is optional but recommended
  • Python >=3.8 is required by the anki package

Installation

Hook in GoldenDict

Configure tosink in "Dictionaries->Sources->Programs" GoldenDict, such as:

/home/everbird/bin/tosink "%GDWORD%"

So far ~ can not be expanded to the user's home yet in GoldenDict. Please use an absolute path here.

You might want create the dictionary to store the sink.txt, such as:

mkdir -p ~/Dropbox/vocabulary

Run Install

pyenv virtualenv 3.9.2 ohmyvocabulary-run  # optional
pyenv activate ohmyvocabulary-run  # optional
git clone https://github.com/everbird/ohmyvocabulary.git
cd ohmyvocabulary
make install
make fetch-and-init-db
cp ohmyvocabularyrc ~/.ohmyvocabularyrc
# Change .ohmyvocabularyrc to set your Anki base, profile, deck, and paths for *.txt, etc.
pyenv deactivate  # optional

Addtional Styling

To apply the styling from ECDICT, you can get the css below:

cat cache/concise-enhanced.css

Copy & paste the css to the Styling of your Card Type. (Find the Styling editor at Tools->Manage Note Types->Select default "Basic" and click "Cards..."->Styling)

Using Oh My Vocabulary

Close your Anki to avoid the SQLite database lock first. Let's lookup a word in GoldenDict. Ensure the word appears in the sink.txt.

cat ~/Dropbox/vocabulary/sink.txt
# Output:
# invincible

Run omv (I use pyenv so I wrap the omv with virtualenv activate/deactivate as below)

pyenv activate ohmyvocabulary-run; omv; pyenv deactivate
# Output:
# Checking dependencies ...
#   mdict-utils       1.0.11
# apy               0.8.0
# ---===[oh-my-vocabulary]===---
# Database was modified.
# Remember to sync!
# Syncing deck ... done!
# Syncing media ... done!
# No new learned update. Skipping ...
# Update learning ...
# done!

Check your Anki and browse your target deck. The new word should be imported with decent paraphrase.

image

FAQ

Q: Why not use ~/.goldendict/history instead of sink.txt?

GoldenDict doesn't follow symlink to write but overwrite with a new file instead. That makes it hard to sync via Dropbox.

About

πŸ“” An adapter to import your lookups from GoldenDict to Anki.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published