LibreTranslate is a free and open-source machine translation API that can be fully self-hosted. Unlike other translation services, it doesn't rely on proprietary providers like Google or Azure. The translation engine is powered by the open-source Argos Translate library.
Prerequisites
This guide assumes you have Docker installed in both online and offline environments. If Docker is unavailable in your offline network or file transfers are completely restricted, this approach won't work.
Step 1: Launch Container in Online Environment
Start the LibreTranslate container on a server with internte access:
docker run -d \
--restart unless-stopped \
--name translator \
-p 5000:5000 \
libretranslate/libretranslate \
--load-only en,zh
The --load-only en,zh parameter loads only English and Chinese language models. Modify this based on your requirements.
Step 2: Create Docker Image from Container
Convert the running container into a reusable image:
docker commit -m "custom/libretranslate" -a "custom" container_id custom/libretranslate:latest
Replace container_id with the actual container identifier from the previous step.
Step 3: Export Docker Image
Save the image to a tar archive for transfer:
docker save -o /data/libretranslate-offline.tar custom/libretranslate
Step 4: Transfer and Load Image in Offline Environment
Copy the tar file to your offline server and load the image:
docker load < libretranslate-offline.tar
Step 5: Deploy Container in Offline Environment
Run the container using your custom image:
docker run -d \
--restart unless-stopped \
--name translator \
-p 5000:5000 \
custom/libretranslate
Usage
Access the translation service at:
http://server_ip:5000
API Integration
Send translation requests via HTTP POST:
curl --location --request POST 'http://server_ip:5000/translate' \
--header 'Content-Type: application/json' \
--data-raw '{
"q": "Text to translate",
"source": "auto",
"target": "en",
"format": "text",
"alternatives": 3,
"api_key": ""
}'
Response Format
{
"alternatives": [
"Alternative translation 1",
"Alternative translation 2",
"Alternative translation 3"
],
"detectedLanguage": {
"confidence": 95,
"language": "zh"
},
"translatedText": "Primary translation"
}