johnfactotum / foliate

Read e-books in style
https://johnfactotum.github.io/foliate/
GNU General Public License v3.0
6.38k stars 293 forks source link

How do I add dictionaries? #704

Closed afranke closed 3 years ago

afranke commented 3 years ago

Question: When I select a word, a menu comes up. It offers looking up in a dictionary. The default one is the English wiktionary, which is fine for English texts. There is a combo to select other sources, but I fail to find how to add another source (e.g. the French wiktionary, as I’m currently reading a book in French).

Version:

johnfactotum commented 3 years ago

English Wiktionary does support looking up French words.

Currently, other than English Wiktionary, Foliate only supports additional dictionaries through dictd or sdcv. Folaite will automatically pick up all dictionaries listed in dict --dbs and sdcv --list-dicts. Note that Foliate runs dictd and sdcv on the host, so you need to install them on your host system.

afranke commented 3 years ago

English Wiktionary does support looking up French words.

I’m not sure the list of French words on the English wiktionary is as extensive as looking up directly on the French one. The definition would also come up in English, and while I am fluent in both languages, it may not be the cause of all users. :-)

Note that Foliate runs dictd and sdcv on the host, so you need to install them on your host system.

Weird then that it works here when both commands are not found if I run them in a terminal.

afranke commented 3 years ago

Weird then that it works here when both commands are not found if I run them in a terminal.

Oh nevermind, I read that wrong. So the English wiktionary is there any way, and those are additional sources.

johnfactotum commented 3 years ago

I’m not sure the list of French words on the English wiktionary is as extensive as looking up directly on the French one. The definition would also come up in English, and while I am fluent in both languages, it may not be the cause of all users. :-)

Yeah, well, unfortunately other Wiktionaries don't have an official word definition API, and each of them structures their content differently. So getting data out of them is kind of a very big problem.

It would be much better if each Wiktionary could provide their own official API. After all, no one knows how to process WikiText properly (not even themselves, apparently, as the English Wiktionary's definition API often demonstrates), and parsing the HTML can be equally problematic.

In the future I will probably add an API for adding custom dictionary plugins at some point. For now, though, there's only dictd and sdcv.

BoboTiG commented 1 year ago

I'm wondering if such project could be useful https://github.com/BoboTiG/ebook-reader-dict? We created offline dictionaries using the same rendering as done on the Wiktionary, locale-dependent.

Going even further, an idea could be to use the provided marisa-trie to lookup for words, same as done on Kobo devices. As we provide 3 types of dictionaries (one for Kobo devices, a dictfile, and stardict file), maybe one could be better suited here :thinking:

I'm just writing here my 2 cents, if it ever gives a hint for future work.

johnfactotum commented 1 year ago

Thanks! I did come across your project, which is awesome.

I think in the future, it would be nice if Foliate could have a sort of system of plugins, or the ability to call external scripts (which could, e.g. return HTML that could be displayed in the popover in Foliate; see #791). Though for now I guess DICT and StarDict dictionaries are still the most convenient standards.