Ding Dong Translate
Ding Dong Translate is a simple VS Code extension that translates selected text using LibreTranslate.
Features
- Translate selected text using LibreTranslate.
- Show translated result in a VS Code notification popup.
- Support custom LibreTranslate API URL.
- Support configurable source and target languages.
- Default translation direction: English to Vietnamese.
Requirements
You need a running LibreTranslate server.
Default local API URL:
http://localhost:5000
This extension only sends requests to LibreTranslate. It does not include LibreTranslate inside the extension package.
LibreTranslate Source
This extension uses LibreTranslate as the translation API.
Official LibreTranslate source code:
git clone https://github.com/LibreTranslate/LibreTranslate
Repository:
https://github.com/LibreTranslate/LibreTranslate
For normal usage, you do not need to clone the LibreTranslate source code. Running LibreTranslate with Docker Compose is enough.
Clone the source code only if you want to:
- Read LibreTranslate source code.
- Modify LibreTranslate behavior.
- Debug LibreTranslate locally.
- Build your own LibreTranslate image.
Run LibreTranslate with Docker Compose
Create a docker-compose.yml file:
services:
libretranslate:
container_name: libretranslate
image: libretranslate/libretranslate:latest
ports:
- "5000:5000"
restart: unless-stopped
environment:
- LT_UPDATE_MODELS=true
- LT_LOAD_ONLY=en,vi
- LT_REQ_LIMIT=1000
healthcheck:
test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py']
interval: 10s
timeout: 4s
retries: 4
start_period: 5s
volumes:
- libretranslate_models:/home/libretranslate/.local:rw
volumes:
libretranslate_models:
Start LibreTranslate:
docker compose up -d
Check running containers:
docker ps
Open LibreTranslate in browser:
http://localhost:5000
Check supported languages:
curl http://localhost:5000/languages
Stop LibreTranslate:
docker compose down
Do not use this command unless you want to remove downloaded models:
docker compose down -v
The -v option removes Docker volumes, so LibreTranslate may need to download models again.
Extension Settings
This extension contributes the following settings:
| Setting |
Default |
Description |
dingDongTrans.apiUrl |
http://localhost:5000 |
LibreTranslate API URL |
dingDongTrans.sourceLanguage |
en |
Source language code |
dingDongTrans.targetLanguage |
vi |
Target language code |
Example VS Code settings.json:
{
"dingDongTrans.apiUrl": "http://localhost:5000",
"dingDongTrans.sourceLanguage": "en",
"dingDongTrans.targetLanguage": "vi"
}
Usage
- Start LibreTranslate.
- Open VS Code.
- Select text in the editor.
- Open Command Palette with
Ctrl + Shift + P.
- Run:
Ding Dong Translate: Translate Selection
- The translated result will appear in a VS Code notification popup.
Example popup:
ding-dong-translate: Xin chào
Development
Install dependencies:
npm install
Compile TypeScript:
npm run compile
Run the extension in development mode:
- Open this project in VS Code.
- Press
F5.
- A new Extension Development Host window will open.
- Select text and run
Ding Dong Translate: Translate Selection.
If you change TypeScript source code, run:
npm run compile
If you only change VS Code settings, you do not need to compile again.
Package Extension
Install VSCE:
npm install -g @vscode/vsce
Build package:
vsce package
This will generate a .vsix file, for example:
ding-dong-translate-0.0.1.vsix
Install the extension from .vsix:
code --install-extension ding-dong-translate-0.0.1.vsix
Or install manually in VS Code:
Extensions → ... → Install from VSIX...
Troubleshooting
Cannot connect to LibreTranslate
Make sure the container is running:
docker ps
Restart LibreTranslate:
docker compose restart
Check the API URL in VS Code settings:
{
"dingDongTrans.apiUrl": "http://localhost:5000"
}
Too many requests
If you get a rate limit error, increase LT_REQ_LIMIT in docker-compose.yml:
environment:
- LT_REQ_LIMIT=1000
Then restart LibreTranslate:
docker compose down
docker compose up -d
Model loading is slow
The first startup may take longer because LibreTranslate needs to download translation models.
This volume keeps models after restart:
volumes:
- libretranslate_models:/home/libretranslate/.local:rw
Notes
This extension currently does not use API keys by default.
If you enable API key protection in LibreTranslate, you must update the extension code to send api_key in the request body.
Do not set this value if the extension does not send API keys:
LT_REQ_LIMIT=0
LT_REQ_LIMIT=0 blocks requests without API keys.
Release Notes
0.0.1
Initial release.