A translator’s companion for desktop. Select fragments of a text document and quickly look them up in online dictionaries
Coditra is a locally run web application intended as support in translation of text. Its main feature are quick dictionary lookups, whereby results are pulled from various online dictionaries and presented in a clear form directly in the user interface.
Coditra comes with several built-in lookup sources. Adding a custom source requires writing an adapter and compiling it together the server portion of the program as well as writing a UI component for the client portion of the program to display the results.
Supports Linux, Windows, and (theoretically — untested) macOS.
Binary releases are not currently available. The program must be built from the source:
Requirements: Yarn 1
(or equivalent), go
.
-
Clone
git clone "https://github.com/fauu/Coditra"
-
Build the client
cd Coditra/client yarn install yarn build
-
Build the server
cd .. ./scripts/server-prebuild.sh cd server go build -o target/coditra cmd/coditra/main.go
The self-contained executable for the program is now ready at
server/target/coditra[.exe]
.
The web interface will be accessible at http://localhost:1291.
On first launch, the program will create a default configuration file
(config/config.sample.nt
) in:
Linux
$XDG_CONFIG_HOME/coditra/config.nt
(usually ~/.config/coditra/config.nt
)
Windows
%APPDATA%\coditra\config.nt
(usually C:\Users\<username>\AppData\Roaming\coditra\config.nt
)
macOS
~/Library/Application Support/coditra/config.nt
Before using Coditra, this file must be edited: a value for the key
documentsDir
must be specified.
The configuration file is a NestedText file. Below is an annotated example describing its expected shape.
# Path of the directory containing HTML documents to be read by Coditra
documentsDir: /home/<user>/documents/translation-texts
# The user agent used by the lookup adapters to access internet resources. When
# this entry is absent, a defualt defined in the file `server/config.go` is
# used
userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
# Simple lookup sources that do not need to be programmed as all they do is
# open the specified URL in a new browser tab
lookups:
-
# Used to refer to this source in other places in the configuration file
id: bob
# Displayed in the user interface
name: Bob
# {input} is substituted with the user’s query string and the resulting URL
# is navigated to in a new browser tab
url: https://www.google.com/search?q={input}
params:
# Determines the flag displayed in the corresponding button in the UI
sourceLang: fr
# Sets of lookup buttons displayed on the left side of the lookup panel
setups:
-
# Displayed in the UI
name: Français 🡒 Polski
# List of buttons
lookups:
# Refers to the entry with id `bob` defined in the `lookups` field above
- bob
# Refers to the key referencing the wordreference.com lookup source as
# defined in the `LookupSources` map in the file `server/server.go`. "fr"
# and "en" refer, respectively, to the `sourceLang` and `targetLang`
# parameters which are handled in the lookup source implementation (in
# this case in the `server/lookups/wr.go` file).
- wr(fr, en)
Coditra uses HTML files as input. For best results, however, a Markdown file should be fed to it first in order to produce a HTML file specifically tailored for use with it. This enables features that make it easier for you to remain oriented within the text while constantly context-switching between it and the lookup results. Specifically, those features are: displaying each sentence in its own paragraph and letting you highlight a sentence you are currently working on by clicking on it.
To convert a Markdown input file to a prepared HTML file, run:
coditra --prepare <filename>.md <filename>.html
-
Initiating text selection by with double click instead of a single click makes it snap to full words.
-
You can use
pandoc
to easily create an input Markdown file directly from a text selection made in web browser. For example (Linux Wayland version):wl-paste -t text/html | pandoc -r html -w markdown-raw_html-native_divs-native_spans-fenced_divs-bracketed_spans > <filename>.md
-
Successful lookup requests are cached in memory until the program is restarted.
-
SJP PWN lookup: some results as well as “internal” cross-references not picked up. For example of both see https://sjp.pwn.pl/sjp/szukaj/mistrz (under “wielki mistrz”).
-
Lingea lookup: unhandled cases: https://slowniki.lingea.pl/wlosko-polski/nella, https://slowniki.lingea.pl/francusko-polski/la (
lex_ful_desc2
).
Terminal #1:
-
go install github.com/cortesi/modd/cmd/modd@latest
orpacman -S modd
etc. -
cd server
-
modd
The program will automatically rebuild and relaunch on any .go
file change.
Terminal #2:
-
cd client
-
yarn dev
The client will be hot-reloaded on modification.
In development, be sure to access the web UI through the address http://localhost:5000, and not localhost:1291, as the latter address will contain a stale version of the client, not the fresh one served by the development server.
-
Create a new
.go
file inserver/lookup/
. You need to implement the typeSource
defined inserver/lookup/lookup.go
. Refer to other files inserver/lookup/
for examples. -
Add an entry for your source to the
LookupSources
map defined at the top of theRunServer()
function in the fileserver/server.go
. -
Create a new
<Lookup Source Name>LookupResult.svelte
file inclient/src/lookup
. You need to implement a Svelte component that receives alookupResult
prop with the data returned by your Go code. Refer to other files inclient/src/lookup
for examples. -
Add your component to the
sourceToLookupResultComponent
map defined near the top of theclient/src/LookupPanel.svelte
file. -
Build the program as described in the Installation section.
Coditra
Copyright (C) 2020-2022 Piotr Grabowski
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Coditra includes the following third-party components:
Component | License |
---|---|
axios | MIT |
bluemonday | BSD-3-Clause |
chi | MIT |
goldmark | MIT |
goquery | BSD-3-Clause |
Line Awesome | MIT |
nt-go | MIT |
rs/cors | MIT |
Svelte | MIT |