- Introduction
- Disclaimer
- Other choices
- Prerequisites
- Features
- Installation
- Usage
- How to use it in Neovim
- Configuration
- TODOs
- LICENSE
- Table of Contents
Yet another simple dictionary application. Support multiple sources, including Longman online dictionary, and user-loaded MDX/MDD dictionary files.
It is trying to be just a dictionary, which you may need during your English study or writing some English posts.
It is NOT a "translator", in which scenario an LLM model based tool is more suitable in modern days.
Web mode is RECOMMENDED, because both the online engine and MDX engine are based on HTML/CSS stuff. So when you need its output to be rendered as markdown, a independent parser and renderer need to written for each source, that's quite a lot of work and almost impossible.
I just write a simple markdown renderer for Longman Dictionary of Contemporary English MDX dictionary, which I uploaded in some releases, so that you can roughly use its markdown rendered output in some cases, such as working as a TUI(which has no "web core") editor plugin, or just using it in the terminal.
There are some similar products. They are all mature products, but may not suit me(or you) in some cases. Compared to these, this application is not yet so well polished, but it has its own advantages.
- It can serve as a CLI application, conforming to the UNIX stdout convention. So you can further process the output, or embed it into any UNIX-like CLI tools, then integrate it into your CLI/TUI based workflow very easily.
- The output can be plain text(such as Markdown format), so feel free to render it with any renderer. You can also embed it into your extensible editor. I provide neovim integration out of the box.
- The raw output(for MDX dictionaries especially) are just HTML/CSS/JavaScript, so your can just use it to build a server, which you can access anywhere by your browser, without having to install any other apps. E.g. Demo Website
- Easy to cross platform. The core is written in Go.
- It's free and open source, just fork/PR/issue it if you like!
- Go version >=1.16, and add $GOBIN in your $PATH
- Neovim version >= 0.9.1 (recommended, because I developed it on this version, but previous versions may also use it, only some "lsp" utils (not lsp feature itself) are required. So it can also be ported to Vim with little effort theoretically, but I am not quite familiar with vim's popup feature yet)
- You can deploy it on your own server in Web/HTTP mode, no telemetry.
- Online query support based on Longman online dictionary
- Integrated with (n)vim, feel free to use it in whatever editor you are using!
- In the offline mode(do not need extra online queries itself), MDX engine is supported. The online engine may be more comprehensive and updated, but they are slow since an HTTP request is made for the first time. The offline mode, however, can work without internet connection, but pre-loaded dictionary files are needed.
go install github.com/ChaosNyaruko/ondict@latest
or
git clone https://github.com/ChaosNyaruko/ondict.git
make install
For your convenience, the config directory in the container is remapped/mounted to your host config directory, so all generated content(such as query history) will be dumped into this directory. No other pollution.
docker build . -t ondict
docker run --rm --name ondict-app --publish 1345:1345 --mount type=bind,source={your $HOME/.config/ondict},target=/root/.config/ondict ondict
docker run --rm --name ondict-app --publish 1345:1345 --mount type=bind,source={your $HOME/.config/ondict},target=/root/.config/ondict chaosnyaruko/ondict:latest
go install github.com/ChaosNyaruko/ondict/cmd/dumpdict@latest
It is used to install a "standalone" CLI tool that can decode MDX files, and dump them into a sqlite3 datebase file. See schema for more (the "vocab" table).
If you just want a decoder to parse your MDX files, this would be enough!
ondict
ondict -h
A.K.A. Web mode, recommended.
This app can also serve as a HTTP server, allowing remote fetch and query, with cache and acceleration.
ondict -serve -listen=localhost:1345 -e=mdx
Launch a http request
curl "http://localhost:1345/?query=apple&engine=mdx&format=x"
Or just open your browser, vist localhost:1345 and you'll see! If you are visiting the URL with a web browser, setting format to "html" is recommended. The browser will automatically render a more beautiful page than it is in the "CLI" interface.
You can also deploy it on your server, as an upstream of Nginx/, or just exposing it with a suitable ip/port.
You can run make serve
locally for an easy example. My front-end skill is poor, so the page is ugly and rough, don't hate it :(.
There are still a lot of TODOs, feel free to give me PRs and contribute to the immature project, thanks in advance.
A one-shot query, it will take some time when you call it the first time, it needs some loading work. It will launch an local server using unix domain socket.
ondict -q <word> [-e anything]
ondict -q <word> -e mdx
ondict -q <word> -remote localhost:1345
ondict -i -e mdx
input .help
for commands that can be used.
For MacOS, work with hammerspoon
If you use hammerspoon's "task" feature, i.e. "hs.task.new" and then "xx::start", some word queries will block the process, and can't see the result(because it hasn't returned yet), such as "test". But no such problems in real web mode, it only happens with hammerspoon.
Don't know why yet, the same word queries also works normally in Neovim integration, which also uses Lua as its async runtime. So I guess maybe it has something to do with the implementation, and it might be a bug of hammerspoon.
Using hs.execute instead of hs.task(Be careful with the shell-escaping), which is a "synchronous" method of executing a task. Normal query is fast enough and you won't notice the difference and will see the result "immediately". See for example
ondict -fzf
You should have FZF installed and have your ondict server listening on localhost:1345 (for now, developing)
Use lazy.nvim, Recommended
require("lazy").setup({
spec = {
-- add your plugins here
{
"ChaosNyaruko/ondict",
event = "VeryLazy",
build = function(plugin)
require("ondict").install(plugin.dir)
end,
dev = false,
config = function()
require("ondict").setup("localhost:1345") -- If you already have a running ondict server, you can just specify the address.
end
},
},
-- Configure any other settings here. See the documentation for more details.
-- colorscheme that will be used when installing plugins.
-- automatically check for plugin updates
checker= { enabled = false },
})
cd ~/.local/share/nvim/site/pack/packer/start/
git clone https://github.com/ChaosNyaruko/ondict.git
cd ondict
go install .
nnoremap <leader>d <cmd>lua require("ondict").query()<cr>
vnoremap <leader>d <cmd>lua require("ondict").query()<cr>
vim.keymap.set("n", "<leader>d", require("ondict").query)
vim.keymap.set("v", "<leader>d", require("ondict").query)
Put dictionary files in $HOME/.config/ondict/dicts, support formats are:
// cd ~/.config/ondict
.
├── config.json
├── dicts
│ ├── LDOCE5++ V 1-35.mdd
│ ├── LDOCE5++ V 1-35.mdx
│ ├── LM5style.css
│ ├── LM5style_vanilla.css
│ ├── Longman Dictionary of Contemporary English.css
│ ├── Longman Dictionary of Contemporary English.mdx
│ ├── ODE_Zh.css
│ ├── ahd3af.css
│ ├── oald9.css
│ ├── oald9.mddx
│ └── oald9.mdx
└── history.table
{
"dicts": [
{
"name": "LDOCE5++ V 1-35",
"type": "LONGMAN5/Online"
},
{
"name": "Longman Dictionary of Contemporary English",
"type": "LONGMAN/Easy"
},
{
"name": "oald9"
}
]
}
There are still a lot of TODOs, feel free to give me PRs and contribute to the immature project, thanks in advance.