https://github.com/zouari-oss/chunk-translator
FastAPI endpoint for chunked text translation
https://github.com/zouari-oss/chunk-translator
api fastapi json open-source python rest rest-api translator
Last synced: 1 day ago
JSON representation
FastAPI endpoint for chunked text translation
- Host: GitHub
- URL: https://github.com/zouari-oss/chunk-translator
- Owner: zouari-oss
- License: gpl-3.0
- Created: 2026-03-16T00:13:21.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-17T03:05:15.000Z (4 months ago)
- Last Synced: 2026-03-17T12:40:14.922Z (4 months ago)
- Topics: api, fastapi, json, open-source, python, rest, rest-api, translator
- Language: Python
- Homepage: https://chunk-translator.vercel.app
- Size: 823 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Authors: AUTHORS
Awesome Lists containing this project
README
[](https://github.com/ZouariOmar/AgriGO/graphs/contributors)
[](https://github.com/ZouariOmar/AgriGO/network/members)
[](https://github.com/ZouariOmar/AgriGO/stargazers)
[](https://github.com/ZouariOmar/AgriGO/issues)
[](LICENSE)
[](https://www.linkedin.com/in/zouari-omar-143239283)
chunk-translator
FastAPI endpoint for chunked text translation
Overview •
Key Features •
Usage •
Emailware •
License •
Contact •
Acknowledgments
## Overview
**chunk-translator** is a lightweight API built with **FastAPI** that translates large text safely by splitting it into manageable chunks.
Many translation models or APIs fail when processing very large inputs. This project solves that by:
- Splitting large text into chunks
- Translating each chunk independently
- Reassembling the translated output in the correct order
> The result is reliable translation **without losing lines or breaking formatting**.
## Key Features
- **FastAPI powered REST API**
- **Automatic text chunking**
- **Supports large document translation**
- **Reassembles chunks in correct order**
- **Prevents dropped lines during translation**
- **Simple JSON API interface**
- **Easy to integrate into pipelines**
## Usage
### 1. Install dependencies
```bash
pip install -r requirements.txt
```
### 2. Run the API
```bash
fastapi run
```
### 3. Use `/translate`
curl
```bash
curl -s \
--header "Content-Type: application/json" \
--request "POST" \
--data '{
"text": "Hello world",
"source_lang": "en",
"target_lang": "fr"
}' \
http://127.0.0.1:8000/translate
```
JavaScript (js)
```js
const response = await fetch("http://127.0.0.1:8000/translate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text: "Hello world",
source_lang: "en",
target_lang: "fr",
}),
});
const data = await response.json();
console.log(data);
```
Java
```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class TranslateClient {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"text": "Hello world",
"source_lang": "en",
"target_lang": "fr"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://127.0.0.1:8000/translate"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
```
C
```c
#include
int main(void) {
CURL *curl = curl_easy_init();
if (!curl) return 1;
const char *json =
"{\"text\":\"Hello world\",\"source_lang\":\"en\",\"target_lang\":\"fr\"}";
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:8000/translate");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return 0;
}
```
C++ (cpp)
```cpp
#include
#include
int main() {
CURL* curl = curl_easy_init();
if (!curl) return 1;
std::string json =
R"({"text":"Hello world","source_lang":"en","target_lang":"fr"})";
struct curl_slist* headers = nullptr;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:8000/translate");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return 0;
}
```
### 4. Example Response
```JSON
{
"status": 200,
"translated_text": "Translated output..."
}
```
## Emailware
chunk-translator is an [emailware](https://en.wiktionary.org/wiki/emailware). Meaning, if you liked using this app or it has helped you in any way, I'd like you send me an email at about anything you'd want to say about this software. I'd really appreciate it!
## License
This repository is licensed under the **GPL-3.0 License**. You are free to use, modify, and distribute the content. See the [LICENSE](LICENSE) file for details.
## Contact
For questions or suggestions, feel free to reach out:
- **GitHub**: [ZouariOmar](https://github.com/ZouariOmar)
- **Email**:
- **LinkedIn**: [Zouari Omar](https://www.linkedin.com/in/zouari-omar)
## Acknowledgments
Built with ❤️ for the open source community
> **Happy Coding!**