This project is a tool that supports multi-platform translation and writing translation results into Redis cache.
MySQL: 8.*
redis
Optional
graylog
- Supports translation integration with Baidu, Youdao, Google, Deepl, Tencent, ChatGPT, Volcano, iFlytek, PaPaGo, and free Google platforms
- Allows setting translation API priorities to call lower priority APIs first
- Configurable unlimited instances for the same API provider at different priority levels
- Automatically switches to the next API if the current one fails when multiple APIs are configured
- Can write translated content into
Redis
andMemory
cache to reduce repeated API calls for the same content
Platform | Batch Translation Supported | Perfectly Supported | Accurate Source Language | Remarks |
---|---|---|---|---|
Baidu | Yes | No | No | Does not support accurately returning the source language for each result |
Yes | Yes | Yes | ||
Youdao | Yes | No | No | Inaccurate source language recognition |
Volcano | Yes | Yes | Yes | |
Deepl | Yes | No | No | Inaccurate source language recognition |
iFlytek | Yes | Yes | Yes | Loop implementation |
PaPaGo | Yes | No | No | Based on \n split implementation and cannot recognize different source languages |
ChatGPT | Yes | Yes | Yes | |
FreeGoogle | Yes | Yes | Yes | Loop implementation |
- Persist translated content to
MySQL
- Web control panel
- ChatGPT AI translation
- iFlytek translation
- More reasonable and secure authentication
- Tencent translation
- Volcano translation
- PaPaGo
- Support for more languages
- Support for simulating
LibreTranslate
translation interface - Support for terminal interactive translation
- Free Google translation
- SQL Lite support
- More client translation features support
YouDao
Baidu
Google
Deepl
ChatGPT
XunFei
XunFeiNiu
Tencent
HuoShan
PaPaGo
FreeGoogle
# In the project directory
docker build -t uni-translate:latest .
# Then execute (it's better to create a network to put MySQL and Redis under the same network, and then access the application directly by the container name in the configuration)
docker run -d --name uniTranslate -v {local_directory}/config.yaml:/app/config.yaml -p 9431:{port_in_config.yaml} --network baseRun uni-translate:latest
After completing the config.yaml
configuration, execute
./UniTranslate translate auto en
server:
name: uniTranslate
address: "0.0.0.0:9431"
cacheMode: redis # redis, mem, off mode; mem stores translation results in program memory; off does not write to any cache
cachePlatform: false # Whether to include the platform in the cache key generation (affects the key stored during project initialization)
key: "hdasdhasdhsahdkasjfsoufoqjoje" # Key for HTTP API integration
keyMode: 1 # Mode 1: direct key verification; Mode 2: use key to encrypt and sign data for verification
Online Documentation
Open API File
import { MD5 } from "crypto-js";
/**
*
* @param key The key set on the platform
* @param params Request parameters
* @return Generated authentication code
*/
function AuthEncrypt(key: string, params: { [key: string]: any }): string {
return MD5(key + sortMapToStr(params)).toString();
}
const sortMapToStr = (map: { [key: string]: any }): string => {
let mapArr = new Array();
for (const key in map) {
const item = map[key];
if (Array.isArray(item)) {
mapArr.push(`${key}:${item.join(",")}`);
continue;
}
if (typeof item === "object") {
mapArr.push(`${key}:|${sortMapToStr(item)}|`);
continue;
}
mapArr.push(`${key}:${item}`);
}
return mapArr.sort().join("&");
};
const params: { [key: string]: any } = {
c: {
cc: 1,
cb: 2,
ca: 3,
cd: 4,
},
a: 1,
b: [4, 1, 2],
};
console.log(AuthEncrypt("123456", params));
Request Example
curl --location --request POST 'http://127.0.0.1:9431/api/translate' \
--header 'auth_key: xxxxxxxxx{AuthEncrypt function result here}' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: application/json' \
--data '{
"from": "auto",
"to": "en",
"text": "测试一下",
"platform": "YouDao"
}'
All supported languages in this program are based on the country language identifiers in the translate.json file, using Youdao translation API identifiers as the baseline.
Please refer to the identifiers supported by the Youdao translation API documentation to modify the translate.json
file.