Introduction
Yet another simple dictionary application. Support multiple sources, including Longman online dictionary, and user-loaded MDX/MDD dictionary files.
Disclaimer
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 working as a TUI editor(which has no "web core") plugin, or just using it in a terminal.
Other choices
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's 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.
- 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 output can also be internally rendered as HTML, and your can just use it to build a server, which you can access anywhere by your browser, without having to install any other apps.
- Easy to cross platform. The core is written in Go.
- It's free and open source, just fork/PR/issue it if you like!
Prerequisites
- 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) is required. So it can also be ported to Vim, but I am not quite familiar with vim's popup feature yet]
Installation
go install github.com/ChaosNyaruko/ondict@latest
Usage
CLI
Help
ondict
ondict -h
Examples
One-shot query
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.
online engine (you don't have to specify the -e option):
ondict -q <word> [-e anything]
mdx engine (ldoce5):
ondict -q <word> -e mdx
One-shot query, but from remote server
ondict -q <word> -remote localhost:1345
A "repl" querier
ondict -i -e mdx
input .help
for commands that can be used.
Work as a server
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"
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.
Work with Neovim
See Integrated with Neovim
Integrated with Neovim
- Install the plugin with a plugin manager or manually.
- Use
:lua require("ondict").query()
to query <cword>.
- Define a mapping for yourself to call it easier. NOTE: in visual mode, use "<cmd>lua require("ondict").query()<cr>" instead. It will capture the "SELECTED" word. Otherwise, the "mode" will be changed and only "<cword>" can be queried.
Install the "ondict" binary automatically with lazy.
{
"ChaosNyaruko/ondict",
event = "VeryLazy",
build = function(plugin)
require("ondict").install(plugin.dir)
end
}
Manually
cd ~/.local/share/nvim/site/pack/packer/start/
git clone https://github.com/ChaosNyaruko/ondict.git
cd ondict
go install .
Mapping examples
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)
Offline dictionary files
Put dictionary files in $HOME/.config/ondict/dicts, support formats are:
- "key-value" organized pairs JSON files.
- MDX files, refer to mdict or pdawiki.
Configuration
file tree
// cd ~/.config/ondict
.
├── config.json
└── dicts
└── Longman\ Dictionary\ of\ Contemporary\ English.mdx
config.json
{
"dicts": [
"Longman Dictionary of Contemporary English",
"xxx",
"yyy"
]
}
Features
- 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, 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.
LICENSE
LICENSE