docs: 更新LibreTranslate简体中文语言标识

2026-08-02 09:03:23 +08:00
parent 9884043371
commit bb2d74db52
+22 -4
@@ -1,5 +1,7 @@
# LibreTranslate Conda 部署方案(Ubuntu)
> 中文语言标识:简体中文使用 `zh-Hans`(部分版本也接受 `zh`),繁体中文使用 `zh-Hant`。本项目是简体中文,因此自定义接口应使用 `zh-Hans`,不是 `zh-Hant`。
## 1. 方案说明
国内服务器通常无法直接拉取 Docker Hub 镜像,因此本方案使用:
@@ -111,7 +113,7 @@ Running on http://127.0.0.1:5001
```bash
curl -X POST http://127.0.0.1:5001/translate \
-H "Content-Type: application/json" \
-d '{"q":"我喜欢篮球","source":"zh","target":"es"}'
-d '{"q":"我喜欢篮球","source":"zh-Hans","target":"es"}'
```
正常返回:
@@ -122,6 +124,8 @@ curl -X POST http://127.0.0.1:5001/translate \
测试完成后按 `Ctrl+C` 停止。
> 如果 `/languages` 只返回 `zh-Hans`、`zh-Hant`,可以把 `--load-only zh,es,en` 改为 `--load-only zh-Hans,es,en` 后再启动。
## 7. 创建服务运行用户
```bash
@@ -243,7 +247,7 @@ sudo -u libretranslate /opt/miniconda3/envs/libretranslate/bin/ltmanage keys \
curl -X POST http://127.0.0.1:5001/translate \
-H "Authorization: Bearer 你的APIKey" \
-H "Content-Type: application/json" \
-d '{"q":"我喜欢篮球","source":"zh","target":"es"}'
-d '{"q":"我喜欢篮球","source":"zh-Hans","target":"es"}'
```
## 11. 一键管理脚本
@@ -346,6 +350,14 @@ sudo systemctl reload nginx
}
```
项目现在默认向自定义接口发送 `zh-hans`。如果接口要求其他写法,可在扩展配置中增加:
```json
{
"zh_code": "zh"
}
```
## 14. 国内网络模型下载说明
如果首次启动时模型下载失败:
@@ -395,6 +407,12 @@ sudo chown -R libretranslate:libretranslate /opt/libretranslate
LT_LOAD_ONLY=zh,es,en
```
如果 `/languages` 显示的是 `zh-Hans` / `zh-Hant`,可改为:
```ini
LT_LOAD_ONLY=zh-Hans,es,en
```
### 15.3 API Key 文件无权限
```bash
@@ -405,7 +423,7 @@ sudo systemctl restart libretranslate
### 15.4 模型下载慢
- 配置 HTTPS 代理
- 只加载 `zh,es,en` 三个模型
- 只加载简体中文 `zh-Hans`、西语 `es`、英语 `en` 三个模型(部分版本也可写 `zh,es,en`)
- 保证磁盘剩余 5GB 以上
## 16. 总结
@@ -414,7 +432,7 @@ sudo systemctl restart libretranslate
1. 安装 Miniconda
2. 创建 python=3.10 环境
3. pip install libretranslate
4. 手动下载 zh,es,en 模型
4. 手动下载简体中文 zh-Hans、西语 es、英语 en 模型
5. 创建 /opt/libretranslate 目录
6. 创建 systemd 服务并开机自启
7. 使用 ltmanage 创建/查看/删除 API Key