What is LibreTranslate?
LibreTranslate
Free open source machine translationAPI
, fully self-hosted. Unlike othersAPI
, it does not rely on proprietary providers such asAzure
to perform translations. Its translation engine isArgos Translate
powered by open source libraries.
This software was tested in 2022
year and month, but the container would stop at that time. From the article below, it seems that there may be insufficient memory.3
https://www.reddit.com/r/selfhosted/comments/yrdeyc/libretranslate_free_and_open_source_machine
After all, translation models and language models are very resource-consuming. Of course, in addition to memory, it is best to have GPU
support.
I bought a memory stick this year 618
, so I took it out again. Although it was new 8G
, it did run. It may also be because Su chose few language models.
Some of the screenshots in this article are still old pictures, but they will not affect your understanding;
If you don’t want to build it yourself, you can check out the official website: https://libretranslate.com
Install
Install using Docker on Synology.
Search in the registry libretranslate
, select the first one libretranslate/libretranslate
, version selection latest
.
- For this toss,
latest
the corresponding version isv1.3.11
;- If your host has
nvidia
a graphics card, you can chooselatest-cuda
to try it;
port
As long as the local port does not conflict, if you are not sure, you can check it with the command
# 查看端口占用
netstat -tunlp | grep 端口号
local port | container port |
---|---|
5353 |
5000 |
environment
LibreTranslate
There are many command line parameters, you can refer to the official documentation: https://github.com/LibreTranslate/LibreTranslate#arguments
[Note]: Each parameter has an equivalent environment variable that can be used instead. environment. Variables override default values but have lower priority than command arguments and are
Docker
particularly useful when used with . Environment variable names are uppercase letters of the equivalent command parameter names, prefixedLT
.
Lao Su did not use environment variables, but entered them in the command line --load-only en,zh
, which meant that only Chinese and English were loaded. If you want to use environment variables, you can useLT_LOAD_ONLY
Run from command line
In the command line mode, Lao Su
CPU
limits the maximum memory usage and occupation of the container; of course, if the machine is powerful enough, there is no need to impose limits;
docker cli installation
If you are familiar with the command line, it may be docker cli
faster to use
# 运行容器(低调内敛模式)
docker run -d \
--restart unless-stopped \
--name libretranslate \
--cpu-shares="700" \
--memory 4096m \
-p 5353:5000 \
libretranslate/libretranslate \
--load-only en,zh
# 运行容器(火力全开模式)
docker run -d \
--restart unless-stopped \
--name libretranslate \
-p 5353:5000 \
libretranslate/libretranslate \
--load-only en,zh
Parameter Description:
--cpus-shares="700"
: Provide a smaller proportion ofCPU
cycles to the container, the default is1024
;--memory 4096m
; Set a hard limit for the container's memory usage that cannot be exceeded;
As you can see from the picture above, when running for the first time, the language model we set will be downloaded.
docker-compose installation
This method of installation is not recommended, as you will not be able to see the container logs for unknown reasons; this will result in you not knowing whether the language model was downloaded successfully, and thus you will not know when you can access it normally.
You can also use to docker-compose
install and save the following content as docker-compose.yml
a file
version: '3'
services:
libretranslate:
image: libretranslate/libretranslate
container_name: libretranslate
restart: unless-stopped
# mem_limit: 4096m
# cpu_shares: 700
ports:
- 5353:5000
healthcheck:
test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py']
command: --load-only en,zh
If you want to enable resource limits, you can uncomment
#
the number;
Then execute the following command
# 新建文件夹 libretranslate
mkdir -p /volume1/docker/libretranslate
# 进入 libretranslate 目录
cd /volume1/docker/libretranslate
# 将 docker-compose.yml 放入当前目录
# 一键启动
docker-compose up -d
run
The first run will require downloading the language model.
When you see in the log Running on http://0.0.0.0:5000
, you can type in the browser http://群晖IP:5353
and see the main interface
I copied the following English paragraph and tried it英翻中
Free and Open Source Machine Translation API. Self-hosted, offline capable and easy to setup.
I tried it again using the following Chinese paragraph:中翻英
Plane 是一个简单的、可扩展的、开源的项目和产品管理工具。
LibreTranslate
translated
Plane is a simple, expanded, open-source project and product management tool
Baidu translated
Plane is a simple, scalable, open-source project and product management tool.
It seems that the effect is okay, right? In addition, it also supports translation files and the formats are relatively rich.
As for the fact that API
ordinary people can’t use it, I won’t mention it.
Reference documentation
LibreTranslate/LibreTranslate: Free and Open Source Machine Translation API. 100% self-hosted, offline capable and easy to setup.
地址:https://github.com/LibreTranslate/LibreTranslate
Docker Container Memory & CPU Limit: Set Up and Manage Resources
地址:https://phoenixnap.com/kb/docker-memory-and-cpu-limit