Skip to content

KOReader plugin enabling Anki card generations for words looked up in the internal dictionary.

Notifications You must be signed in to change notification settings

Ajatt-Tools/anki.koplugin

Repository files navigation

Anki plugin for KOReader

KOReader plugin enabling Anki note generation for words looked up in the internal dictionary.

Installation

  1. Install AnkiConnect to enable this plugin to communicate with Anki.

    NOTE: as mentioned in the Anki-Connect documentation, you will not be able to connect to Anki-Connect from your e-reader without updating the default settings.

    By default, Anki-Connect will only bind the HTTP server to the 127.0.0.1 IP address, so that you will only be able to access it from the same host on which it is running. If you need to access it over a network, you can change the binding address in the configuration. Go to Tools->Add-ons->AnkiConnect->Config and change the “webBindAddress” value. For example, you can set it to 0.0.0.0 in order to bind it to all network interfaces on your host. This also requires a restart for Anki.

  2. Download the plugin, unzip it in the koreader/plugins directory, make sure the folder is named anki.koplugin, this is necessary for KOReader to load it.

    Alternatively, use KOReader's built in SSH server:

    git clone "https://github.com/Ajatt-Tools/anki.koplugin.git" ./anki.koplugin
    sshfs -p 2222 root@<IP-address>:/mnt/onboard/.adds/koreader <local_folder>
    # be careful to not add a trailing / to the source directory, this creates the folder on your device
    rsync -Pruv --exclude=".git/" ./anki.koplugin <local_folder>/plugins/

Usage

When the plugin has been installed succesfully, there will be an extra button present on the reader's dictionary popup window, allowing the user to create an Anki note.

image

When pressed, the add-on will generate a note for the looked up word.

image

Features

The information extracted from the dictionary and book is sent to separate fields on the note.

Below is a list of all fields, along with the setting that defines which field on your note it ends up on. These settings are configured via a user profile, see Profiles for more info.

Available fields

Selected word (word_field)

The word selected in the book.

Sentence context (context_field)

The full sentence that the word occured in, extracted from the book.

Translated Sentence (translated_context_field)

The translation of the sentence context mentioned above. The target language is inherited from the translation settings in KOReader itself.

Previous sentence count (prev_sentence_count)

Define the amount of sentences which should be prepended to the word you looked up. Set this to 1 to have it complete the sentence the word occured in.

Next sentence count (next_sentence_count)

Define the amount of sentences which should be appended to the word you looked up. Set this to 1 to have it complete the sentence the word occured in.

The exact context stored can be modified by pressing and holding the 'Add to Anki' button, and choosing the 'custom context' entry on the menu that pops up.

Dictionary definition (def_field)

The dictionary entry that was selected when pressing the button.

Audio (audio_field)

The plugin will query Forvo to get audio for the lookupword. The language used is determined by the dictionary's language, or by the book's language as fallback.

Metadata (meta_field)

Some information about the book: author, title and page number.

This info is retrieved from the EPUB's metadata, or by parsing the filename with a Lua pattern ("^%[([^%]]-)%]_(.-)_%[([^%]]-)%]%.[^%.]+")

The pattern expects filenames with the following format: [Author]_Title_[extra_info].epub. The extension can be anything.

Offline usage

Notes are saved locally on the device when the remotely running Anki isn't available. When it becomes available again, the user will be reminded they have unsynced notes.

This can also be done manually by pressing and holding the 'Add to Anki' button, and choosing the manual sync option.

Extra options

As mentioned earlier, when pressing and holding the 'Add to Anki' button, a separate menu is shown:

image

Sync offline notes

This option can be used to send the locally stored notes to Anki.

Custom tags

This allows the user to allows the user to create a card with custom tags.

Custom context

By default, the complete sentence the word occured in is stored on the note. In cases where this is too little or too much context, the user can modify it by pressing this button. This pops up a menu where the exact amount of text can be selected.

Undo latest note

It's also possible to undo the creation of the latest card, which can be handy when deciding you want to add some extra context to the note.

Change profile

Link the currently opened document with a different user profile.

Configuration

Configuration is done by defining profiles, See Profiles for more info.

Edit configuration within KOreader

There is code in place to create a menu, with which some of the fields can be edited on the reader itself. Adding an option in the KOreader's menu isn't possible from within a standalone plugin, but it can be done with a user patch.

Show snippet Save the code snippet below in a file with the name `2-anki-menu-patch.lua`. This file should be stored in `koreader/patches`.
local FileManagerMenuOrder = require("ui/elements/filemanager_menu_order")
local ReaderMenuOrder = require("ui/elements/reader_menu_order")

table.insert(FileManagerMenuOrder.search, 5, "anki_settings")
table.insert(ReaderMenuOrder.search, 5, "anki_settings")

If everything goes right, this should add an extra option to the search menu: 2023-03-30_19-57

When editing a profile which is not the default one, it's possible to 'unset' a setting (meaning it falls back on whatever is present in the default.lua profile). This is done by pressing and holding the setting you would like to reset.

FAQ

Plugin can't detect the language of the word When the user has defined a value for the `audio_field` in the config, the plugin needs to know the language of the word you looked up, so it can look for the correct audio file.

It looks for this language in 2 places

  • Stardict's .ifo file

    Each dictionary installed has its own folder consisting of, among other files, an .ifo file with some info about this dictionary, looking something like this:

    StarDict's dict ifo file
    version=2.4.2
    wordcount=18244
    idxfilesize=405703
    bookname=Dutch-English dictionary
    date=2009.01.30
    sametypesequence=x
    description=Copyright: Converted by swaj under GNU Public License; Version: 1.1
    

    In this case (Dutch-English), add the following line: ifo_lang=nl-en (just ifo_lang=nl would work too).

    This field is parsed by KOReader, and used by this plugin when available. This should already be present for dictionaries downloaded internally.

  • the language of the document

    In some documents, like .epub files, it is possible to define the language of the text with it. When this info is available, the plugin will use it.

    KOReader also allows you to edit a document's metadata manually, by opening the top menu > Hamburger menu > Book information > Tap and hold "Language" > Set custom.

    The expected format of this language is, like above, the ISO2 code. For example, to specify French, fill in 'fr'

If you don't care about having audio, you can leave the audio_field blank. This will cause this step to be skipped completely.

About

KOReader plugin enabling Anki card generations for words looked up in the internal dictionary.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages