Installing libretranslate using Docker
Why?
The main use of this Libretranslate is to translate mastodon toots.
What do I need to install?
You need a Linux Server with Docker, and Docker-compose installed.
What's my setup?
- ProxMox
- KVM
- Ubuntu 20.04
- Docker
- Docker-compose
- External Nginx
- Reverse Proxy Configuration
- LetsEncrypt Certificate
Where I can find more about the project?
How I can install it?
first, let's create the directories
mkdir -p /opt/libretranslate/docker
mkdir -p /opt/libretransalte/data/{key,local}
now let's configure the permissions
chown 1032:1032 /opt/libretransalte/data
chown 1032:1032 /opt/libretransalte/data/key
chown 1032:1032 /opt/libretransalte/data/local
then, let's create the docker-compose file
cd /opt/libretranslate/docker
vim docker-compose.yaml
here follows the content, change the parameters for you setup
version: "3"
services:
libretranslate:
container_name: libretranslate
image: libretranslate/libretranslate:v1.3.11
restart: unless-stopped
dns:
- 1.1.1.1
- 8.8.8.8
ports:
- "5000:5000"
healthcheck:
test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py']
env_file:
- libretranslate.env
volumes:
- libretranslate_api_keys:/app/db
- libretranslate_local:/home/libretranslate/.local
volumes:
libretranslate_api_keys:
driver_opts:
type: none
device: /opt/libretranslate/data/keys
o: bind
libretranslate_local:
driver_opts:
type: none
device: /opt/libretranslate/data/local
o: bind
then, let's create the libetranslate env file
vim libretranslate.env
here follows the content, change the parameters for you setup
LT_DEBUG=true
LT_UPDATE_MODELS=true
LT_SSL=true
LT_SUGGESTIONS=false
LT_METRICS=true
LT_API_KEYS=true
LT_THREADS=12
LT_FRONTEND_TIMEOUT=2000
#LT_REQ_LIMIT=400
#LT_CHAR_LIMIT=1200
LT_API_KEYS_DB_PATH=/app/db/api_keys.db
all right, let's spin up the libretranslate
docker-compose up -d
installing the model files
you should enter the container
docker exec -it libretranslate bash
and run the command to install all languages
for i in `/app/venv/bin/argospm list`;do /app/venv/bin/argospm install $i;done
it will took some time to install, go drink a coffee, then check the directory in your host
$ exit
$ ls -1 /opt/libretranslate/data/local/share/argos-translate/packages/
ar_en
de_en
en_ar
en_de
en_es
en_fi
en_fr
en_ga
en_hi
en_hu
en_id
en_it
en_ja
en_ko
en_nl
en_pl
en_pt
en_sv
en_uk
es_en
fi_en
fr_en
ga_en
hi_en
hu_en
id_en
it_en
ja_en
ko_en
nl_en
pl_en
pt_en
ru_en
sv_en
translate-az_en-1_5
translate-ca_en-1_7
translate-cs_en-1_5
translate-da_en-1_3
translate-el_en-1_5
translate-en_az-1_5
translate-en_ca-1_7
translate-en_cs-1_5
translate-en_da-1_3
translate-en_el-1_5
translate-en_eo-1_5
translate-en_fa-1_5
translate-en_he-1_5
translate-en_ru-1_7
translate-en_sk-1_5
translate-en_th-1_0
translate-en_tr-1_5
translate-en_zh-1_7
translate-eo_en-1_5
translate-fa_en-1_5
translate-he_en-1_5
translate-sk_en-1_5
translate-th_en-1_0
translate-tr_en-1_5
translate-zh_en-1_7
uk_en
Awesome it's all there.
creating the api key
Since we're using “LTAPIKEYS=true” we need to create an API KEY to be able to use libretranslate via API. Let's go to the container again
docker exec -it libretranslate bash
let's create a key with permission to run 120 requests per minute.
/app/venv/bin/ltmanage keys add 120
example of the expected output
libretranslate@ba7f705d97b9:/app$ /app/venv/bin/ltmanage keys
ecae7db0-bolha-us-is-cool-c84c14d2117a: 1200
nice, everything is ready to be used, now let's configure your nginx!
testing the api
curl -XPOST -H "Content-type: application/json" -d '{
"q": "Bolha.io is the most cool project in the fediverso",
"source": "en",
"target": "pt"
}' 'http://localhost:5000/translate'
expected output
{"translatedText":"Bolha.io é o projeto mais legal no fediverso"}
external nginx
In our case, libretranslate is behind an External NGINX Reverse Proxy.
Here follows the config snippet used
upstream libretranslate {
server your_docker_host_ip:your_libretranslate_port fail_timeout=0;
}
server {
listen 144.217.95.91:80;
server_name libretranslate.domain.tld;
return 301 https://libretranslate.domain.tld$request_uri;
}
server {
listen 144.217.95.91:443 ssl http2;
server_name libretranslate;
access_log /var/log/nginx/libretranslate-domain-tld.log;
error_log /var/log/nginx/libretranslate-domain-tld.log;
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/letsencrypt/dh-param.pem;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
location / {
proxy_pass http://libretranslate;
}
}
Now you can access your libretranstale via web
That's it :)
[s]
Did you like our content?
We have a lot to share; visit our site!
Our fediverse services ;)
- mastodon => https://bolha.us
- mastopoet => https://poet.bolha.us
- elk => https://elk.bolha.us
- pinafore => https://pinafore.bolha.us
- pixelfed => https://bolha.photos
- lemmy => https://bolha.social
- writefreely => https://bolha.blog
- bookwyrm => https://bolha.review
- funkwhale => https://bolha.studio
- friendica => https://bolha.network
Chat and video? We have it!
- matrix => https://bolha.chat
- jitsi => https://bolha.video
Translation tools
- libretranslate => https://libretranslate.bolha.tools
- lingva => https://translate.bolha.tools
Video Platform Frontends
- invidious => https://bolha.in
Text Editors
- hedgeDoc => https://notes.bolha.tools
- wise Mapping => https://mindmap.bolha.tools
- overleaf => https://overleaf.bolha.tools
- mermaid => https://mermaid.bolha.tools
You can also visit our hacking space!
Follow our founder!
- https://bolha.us/@gutocarvalho
- https://bolha.photos/@gutocarvalho
- https://bolha.forum@gutocarvalho
- https://bolha.blog/@gutocarvalho
- https://bolha.review/@gutocarvalho
- https://bolha.studio/@gutocarvalho
- https://bolha.network/@gutocarvalho
- matrix => @bolha.chat@gutocarvalho
Follow the status of our tools
Do you want to support us? You can!
- https://www.patreon.com/bolha
- https://apoia.se/bolha
- pix@bolha.us (local brazilian wire transfer)
See you!
[s]