initial commit
This commit is contained in:
commit
856c65919e
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "LibreTranslate"]
|
||||
path = LibreTranslate
|
||||
url = https://github.com/LibreTranslate/LibreTranslate
|
1
LibreTranslate
Submodule
1
LibreTranslate
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 1bc6a3061c28a8f45200eb5d2fa4e099b37c4cb7
|
28
README.md
Normal file
28
README.md
Normal file
@ -0,0 +1,28 @@
|
||||
# LibreTranslate API
|
||||
|
||||
## Your own translation API
|
||||
|
||||
### Install
|
||||
|
||||
```
|
||||
$ git clone --recurse-submodules https://gitlab.com/manalejandro/libretranslate-api
|
||||
$ cd libretranslate-api/
|
||||
$ docker compose pull libretranslate-api
|
||||
$ docker compose build libretranslate
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
```
|
||||
$ docker compose up -d
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
$ curl "http://libretranslate-api:5080/?target=es&text=help"
|
||||
```
|
||||
|
||||
### License
|
||||
|
||||
MIT
|
37
docker-compose.yml
Normal file
37
docker-compose.yml
Normal file
@ -0,0 +1,37 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
libretranslate:
|
||||
image: libretranslate
|
||||
build:
|
||||
context: ./LibreTranslate
|
||||
args:
|
||||
with_models: true
|
||||
dockerfile: docker/Dockerfile
|
||||
restart: always
|
||||
hostname: libretranslate
|
||||
container_name: libretranslate
|
||||
expose:
|
||||
- "5000"
|
||||
networks:
|
||||
libretranslatenet:
|
||||
|
||||
libretranslate-api:
|
||||
image: node:21-slim
|
||||
restart: always
|
||||
hostname: libretranslate-api
|
||||
container_name: libretranslate-api
|
||||
working_dir: /libretranslate-api
|
||||
user: node
|
||||
entrypoint:
|
||||
- node
|
||||
- index.js
|
||||
volumes:
|
||||
- ./libretranslate-api:/libretranslate-api
|
||||
ports:
|
||||
- "5080:3000"
|
||||
networks:
|
||||
libretranslatenet:
|
||||
|
||||
networks:
|
||||
libretranslatenet:
|
25
libretranslate-api/index.js
Normal file
25
libretranslate-api/index.js
Normal file
@ -0,0 +1,25 @@
|
||||
const http = require('http')
|
||||
|
||||
http.createServer(async (req, res) => {
|
||||
const params = new URLSearchParams(req.url.replace(/^\//, ''))
|
||||
if (params.has('text') && params.has('target')) {
|
||||
const response = await fetch("http://libretranslate:5000/translate", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
q: params.get('text'),
|
||||
source: "auto",
|
||||
target: params.get('target'),
|
||||
format: "text",
|
||||
api_key: ""
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" }
|
||||
}),
|
||||
result = await response.json()
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain; charset=UTF-8' })
|
||||
res.end(result.translatedText)
|
||||
} else {
|
||||
res.statusCode = 404
|
||||
res.end()
|
||||
}
|
||||
}).listen(3000)
|
||||
|
Loading…
Reference in New Issue
Block a user