LibreTranslate is a neat feature that will translate posts between languages. Unfortunately, it’s usage is not well documented so here are some hints to get it working with Mastodon. These instructions are written for Podman and adapted from this posting from fixermark.com. The original posting was written for Docker.
These instructions involve several steps but are not complicated to do. First we have to pull the image by typing podman pull docker.io/libretranslate/libretranslate
. Once this is done, we have to create some two volumes.
podman volume create libretranslate_api_keys
podman volume create libretranslate_local
Once the volumes are created, we have to create an environment file called libretranslate.env
. This file holds the environment variables for the proper operation of LibreTranslate.
LT_HOST=127.0.0.1
LT_PORT=5000
LT_DEBUG=False
LT_SSL=False
In case you are wondering why SSL has been set to False, it is because LibreTranslate is operating locally, and therefore, SSL is not really necessary. Once this environment file has been created, we can run the LibreTranslate container by doing the following:
podman run -d -it --replace --name lt --pod mastodon --env-file /path/to/libretranslate.env -v libretranslate_api_keys:/app/db -v libretranslate_local:/home/libretranslate/.local docker.io/libretranslate/libretranslate
Once the container has started up, we have to go into the container to download the lagnuage packs. This is perhaps the most time consuming part of the entire procedure. It took me almost 5 minutes to download the language packs.
podman exec -it lt bash
for i in `/app/venv/bin/argospm list`;do /app/venv/bin/argospm install $i;done
You won’t see any text pop up but the language packs are downloading. Once this is done, exit the container.
After exiting the container, you have to edit your Mastodon .production.env file with the following variables to enable LibreTranslate integration.
DEFAULT_LOCALE=en
ALLOWED_PRIVATE_ADDRESSES=127.0.0.1
LIBRE_TRANSLATE_ENDPOINT=http://127.0.0.1:5000
Finally, restart the Mastodon web service and look for a post in a language other than English. You should see a handy translate link.