Portainer Templates logo

Portainer Templates

LibreTranslate LibreTranslate

Stack

ToolsAI

Machine translation server with a page for translating text and documents, plus a JSON API for other apps to call. Runs its own models, so nothing you translate leaves the box. Source: https://github.com/LibreTranslate/LibreTranslate

Image details

Pulls: 10.1M
Architecture: amd64, arm64
Image size: 1.8 GB
Latest: v1.9.6-cuda
User: libretranslate
Created: Dec 29, 2020
Updated: 5 days ago
Status: active

Source details

Stars: 17.1k
Forks: 2k
Language: Python
License: AGPL-3.0
Updated: 5 days ago

Configuration

Type
Compose
Platform
linux
Image
libretranslate/libretranslate:latest
Ports
${LIBRETRANSLATE_PORT:-5100}:5000
Volumes
/home/libretranslate/.local : libretranslate-models
Env vars
LT_LOAD_ONLY=${LIBRETRANSLATE_LANGUAGES:-en,es,fr,de}LT_UPDATE_MODELS=trueLIBRETRANSLATE_LANGUAGES=en,es,fr,deLIBRETRANSLATE_PORT=5100
Restart
unless-stopped
Source

Notes

Open http://<your-host>:5100 (or whichever port you picked). The first start downloads models for the languages you listed, about 900 MB for the default four, so give it a minute or two before the page answers. There are no accounts, so anyone who can reach it can use it and its API (reference at /docs). Keep it on your LAN, or see the docs for API keys and rate limits. To add languages later, change the list and update the stack, and the new ones download on the next start. Each start also checks for model updates. The models live in the libretranslate-models volume. Codes: supported languages. Docs: docs.libretranslate.com

Standalone Install

Select an install method, to see config/commands for deploying LibreTranslate

Installation method

Install on Portainer

Import all app templates into your Portainer instance, for easy 1-click deploys

  1. Ensure both Docker and Portainer are installed, and up-to-date
  2. Log into your Portainer web UI
  3. Under Settings → App Templates, paste the below URL
  4. Head to Home → App Templates, and the list of apps will show up
  5. Select LibreTranslate, fill in any config options, and hit Deploy

Template Import URL

https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json
Show Me demo
Original stackfile

The compose file this template deploys, straight from its repo:

services:
  libretranslate:
    image: libretranslate/libretranslate:latest
    restart: unless-stopped
    ports:
      - "${LIBRETRANSLATE_PORT:-5100}:5000"
    environment:
      LT_LOAD_ONLY: ${LIBRETRANSLATE_LANGUAGES:-en,es,fr,de}
      LT_UPDATE_MODELS: "true"
    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

volumes:
  libretranslate-models:

Or deploy it directly from the source:

git clone https://github.com/NotAFlightRisk/portainer-templates-extras
cd portainer-templates-extras
docker compose -f apps/libretranslate/compose.yml up -d

More install options in our documentation, or see LibreTranslate/LibreTranslate for app-specific guidance.

LibreTranslate

Try it online! | API Docs | Community Forum
Python versions Run tests Publish to DockerHub Publish to GitHub Container Registry Awesome Humane Tech
Free and Open Source Machine Translation API, entirely self-hosted. Unlike other APIs, it doesn't rely on proprietary providers such as Google or Azure to perform translations.
image
Try it online! | API Docs

API Examples

Request:
const res = await fetch("https://libretranslate.com/translate", {
	method: "POST",
	body: JSON.stringify({
		q: "Hello!",
		source: "en",
		target: "es"
	}),
	headers: { "Content-Type": "application/json" }
});

console.log(await res.json());

Response:
{
    "translatedText": "¡Hola!"
}

Install and Run

You can run your own API server in just a few lines of setup!
Make sure you have installed Python (3.8 or higher is recommended), then simply issue:
pip install libretranslate
libretranslate [args]

Then open a web browser to http://localhost:5000
If you're on Windows, we recommend you Run with Docker instead.
On Ubuntu 20.04 you can also use the install script available on https://github.com/argosopentech/LibreTranslate-init

Build and Run

If you want to make some changes to the code, you can build from source, and run the API:
git clone https://github.com/uav4geo/LibreTranslate
cd LibreTranslate
pip install -e .
libretranslate [args]

# Or
python main.py [args]

Then open a web browser to http://localhost:5000

Run with Docker

Simply run:
docker run -ti --rm -p 5000:5000 libretranslate/libretranslate

Then open a web browser to http://localhost:5000

Build with Docker

docker build [--build-arg with_models=true] -t libretranslate .

If you want to run the Docker image in a complete offline environment, you need to add the --build-arg with_models=true parameter. Then the language models get downloaded during the build process of the image. Otherwise these models get downloaded on the first run of the image/container.
Run the built image:
docker run -it -p 5000:5000 libretranslate [args]

Or build and run using docker-compose:
docker-compose up -d --build

Feel free to change the docker-compose.yml file to adapt it to your deployment needs, or use an extra docker-compose.prod.yml file for your deployment configuration.

Arguments

ArgumentDescriptionDefaultEnv. name
--hostSet host to bind the server to127.0.0.1LTHOST
--portSet port to bind the server to5000LTPORT
--char-limitSet character limitNo limitLTCHARLIMIT
--req-limitSet maximum number of requests per minute per clientNo limitLTREQLIMIT
--batch-limitSet maximum number of texts to translate in a batch requestNo limitLTBATCHLIMIT
--ga-idEnable Google Analytics on the API client page by providing an IDNo trackingLTGAID
--debugEnable debug environmentFalseLTDEBUG
--sslWhether to enable SSLFalseLTSSL
--frontend-language-sourceSet frontend default language - sourceenLTFRONTENDLANGUAGESOURCE
--frontend-language-targetSet frontend default language - targetesLTFRONTENDLANGUAGETARGET
--frontend-timeoutSet frontend translation timeout500LTFRONTENDTIMEOUT
--api-keysEnable API keys database for per-user rate limits lookupDon't use API keysLTAPIKEYS
--require-api-key-originRequire use of an API key for programmatic access to the API, unless the request origin matches this domainNo restrictions on domain originLTREQUIREAPIKEYORIGIN
--load-onlySet available languagesall from argostranslateLTLOADONLY

Note that each argument has an equivalent env. variable that can be used instead. The env. variables overwrite the default values but have lower priority than the command aguments. They are particularly useful if used with Docker. Their name is the upper-snake case of the command arguments' ones, with a LT prefix.

Run with Gunicorn

pip install gunicorn
gunicorn --bind 0.0.0.0:5000 'wsgi:app'

You can pass application arguments directly to Gunicorn via:
gunicorn --bind 0.0.0.0:5000 'wsgi:app(api_keys=True)'

Manage API Keys

LibreTranslate supports per-user limit quotas, e.g. you can issue API keys to users so that they can enjoy higher requests limits per minute (if you also set --req-limit). By default all users are rate-limited based on --req-limit, but passing an optional api_key parameter to the REST endpoints allows a user to enjoy higher request limits.
To use API keys simply start LibreTranslate with the --api-keys option.

Add New Keys

To issue a new API key with 120 requests per minute limits:
ltmanage keys add 120

Remove Keys

ltmanage keys remove <api-key>

View Keys

ltmanage keys

Language Bindings

You can use the LibreTranslate API using the following bindings:
- Rust: https://github.com/DefunctLizard/libretranslate-rs - Node.js: https://github.com/franciscop/translate - .Net: https://github.com/sigaloid/LibreTranslate.Net - Go: https://github.com/SnakeSel/libretranslate - Python: https://github.com/argosopentech/LibreTranslate-py
More coming soon!

Discourse Plugin

You can use this discourse translator plugin to translate Discourse topics. To install it simply modify /var/discourse/containers/app.yml:
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/LibreTranslate/discourse-translator
	  ...

Then issue ./launcher rebuild app. From the Discourse's admin panel then select "LibreTranslate" as a translation provider and set the relevant endpoint configurations.

Mirrors

This is a list of online resources that serve the LibreTranslate API. Some require an API key. If you want to add a new URL, please open a pull request.
URL |API Key Required|Contact|Cost --- | --- | --- | --- libretranslate.com|:heavycheckmark:|UAV4GEO| $9 / month, 80 requests / minute limit libretranslate.de|-|- translate.mentality.rip|-|- translate.astian.org|-|- translate.argosopentech.com|-|-

Roadmap

Help us by opening a pull request!

FAQ

Can I use your API server at libretranslate.com for my application in production?

The API on libretranslate.com should be used for testing, personal or infrequent use. If you're going to run an application in production, please get in touch to get an API key or discuss other options.

Can I use this behind a reverse proxy, like Apache2?

Yes, here is an example Apache2 config that redirects a subdomain (with HTTPS certificate) to LibreTranslate running on a docker at localhost.
sudo docker run -ti --rm -p 127.0.0.1:5000:5000 libretranslate/libretranslate
You can remove 127.0.0.1 on the above command if you want to be able to access it from domain.tld:5000, in addition to subdomain.domain.tld (this can be helpful to determine if there is an issue with Apache2 or the docker container).
Add --restart unless-stopped if you want this docker to start on boot, unless manually stopped.
Apache config
Replace YOURDOMAIN with your full domain; for example, translate.domain.tld or libretranslate.domain.tld.
Remove # on the ErrorLog and CustomLog lines to log requests.
#Libretranslate

#Redirect http to https
<VirtualHost *:80>
    ServerName http://[YOUR_DOMAIN]
    Redirect / https://[YOUR_DOMAIN]
    # ErrorLog ${APACHE_LOG_DIR}/error.log
    # CustomLog ${APACHE_LOG_DIR}/tr-access.log combined
 </VirtualHost>

#https
<VirtualHost *:443>
    ServerName https://[YOUR_DOMAIN]
    
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/[YOUR_DOMAIN]/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/[YOUR_DOMAIN]/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/[YOUR_DOMAIN]/fullchain.pem
    
    # ErrorLog ${APACHE_LOG_DIR}/tr-error.log
    # CustomLog ${APACHE_LOG_DIR}/tr-access.log combined
</VirtualHost>

Add this to an existing site config, or a new file in /etc/apache2/sites-available/new-site.conf and run sudo a2ensite new-site.conf.
To get a HTTPS subdomain certificate, install certbot (snap), run sudo certbot certonly --manual --preferred-challenges dns and enter your information (with subdomain.domain.tld as the domain). Add a DNS TXT record with your domain registrar when asked. This will save your certificate and key to /etc/letsencrypt/live/{subdomain.domain.tld}/. Alternatively, comment the SSL lines out if you don't want to use HTTPS.

Credits

This work is largely possible thanks to Argos Translate, which powers the translation engine.

License

GNU Affero General Public License v3

Check the logs first

Nine times out of ten the logs tell you exactly what went wrong.

  • In Portainer, go to Containers, click the container, then Logs. Or run docker logs <container>
  • Exit codes help too: 137 means killed, usually out of memory. 126 or 127 means the command inside the image is broken.

Image won't pull

Test the pull directly on the host: docker pull libretranslate/libretranslate:latest

  • "manifest unknown" means the tag no longer exists. This template uses latest, so try pinning a specific version instead.
  • "toomanyrequests" is the Docker Hub rate limit. Log in with docker login to raise it.
  • "no space left on device" means a full disk. Reclaim space with docker system prune

"exec format error"

This means the image was built for a different CPU architecture than your server.

  • This image supports: amd64, arm64
  • Check yours with uname -m: x86_64 is amd64, aarch64 is arm64. Raspberry Pi and other ARM boards are the usual culprits.

Container keeps restarting

The unless-stopped restart policy relaunches the app after every crash, so the real error can scroll past.

  • Check the logs right after a restart, the last few lines before it died are the useful ones.
  • Get the exit code with docker inspect <container> --format '{{.State.ExitCode}}'
  • Still stuck? Redeploy once with the restart policy set to no so the failure stays visible.

Stack won't deploy

Compose stacks fail fast on small mistakes, and Portainer shows the reason just above the editor.

  • YAML only accepts spaces for indentation, a single tab breaks the whole file.

Raise an issue

Found something which isn't working as it should? Here's how to report it.

A Compose stack

LibreTranslate is a Compose stack, a set of containers defined in one file and brought up together by Portainer, then started and stopped as a single app.

The app image

An image is the app packed up ready to go, everything LibreTranslate needs bundled into one download. This template pulls libretranslate/libretranslate:latest, which Docker fetches once (about 1.8 GB) and then starts your own copy from.

Where the image comes from

Docker pulls its images from registries, public libraries of ready-built apps. LibreTranslate's comes from Docker Hub, published by libretranslate.

Version tags

The bit after the colon in the image name is the version tag. Here it's latest, which always points at the newest build, so a redeploy can bump you to a newer release without you asking. Newest right now is v1.9.6-cuda. Pin a specific tag if you would rather stay on one version.

Which machines it runs on

Every image is built for particular CPU types. This one ships for amd64, arm64, so it runs on both regular x86 servers and ARM boards like a Raspberry Pi.

Volumes

A volume is where LibreTranslate keeps its files so they survive an update or a restart. Without one, anything it saves would sit inside the container and vanish the moment it's recreated. This template mounts:

  • /home/libretranslate/.local kept in the libretranslate-models volume Docker manages

Environment variables

Environment variables are the settings you hand over when you deploy, things like a password or a timezone. LibreTranslate takes 4 of them, all with defaults you can leave alone or tweak:

  • LT_LOAD_ONLY, defaults to en,es,fr,de
  • LT_UPDATE_MODELS, defaults to true
  • LIBRETRANSLATE_LANGUAGES, defaults to en,es,fr,de. Two-letter codes, comma separated, like en,es,fr,de,it,ja. Each one is a couple of hundred MB of models to download.
  • LIBRETRANSLATE_PORT, defaults to 5100. Host port for the web UI

Restart policy

The restart policy here is unless-stopped, so Docker restarts LibreTranslate after a crash or reboot, but leaves it off when you stop it on purpose. You can change this on the deploy screen. The choices are no (never restart), on-failure (only after a crash), unless-stopped (restart unless you stop it), and always (bring it back no matter what).

Health check

A health check is how Docker tells whether LibreTranslate is really working, not just switched on. It runs ./venv/bin/python scripts/healthcheck.py every 10s and flags the container as unhealthy if that keeps failing.

Networking

Nothing custom is set, so LibreTranslate sits on Docker's default bridge network: its own private space that reaches the outside world only through the ports it publishes.

Container name

Once it's deployed, Portainer names the container libretranslate. That's what you'll spot in the containers list and use in commands like docker logs libretranslate.

Platform

The platform is linux, the kind of system the container is built to run on. Docker and Portainer handle this on a normal Linux server.

Open source license

LibreTranslate is open source, released under the AGPL-3.0 license. In plain terms the code is out in the open, so you're free to run it and change it to fit what you need.

Portainer app templates

Zooming out, this whole page comes from a Portainer app template: a short recipe telling Portainer how to set LibreTranslate up. Add the template list to Portainer once, then deploying LibreTranslate is a click rather than a wall of config.