This project provides translation services.
This project aims to provide a robust and scalable translation service that can be integrated into various applications.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
You need to have Python and pip installed on your machine.
sudo apt-get install python3
sudo apt-get install python3-pip
A step by step series of examples that tell you how to get a development environment running.
- Clone the repository
git clone https://github.com/tutz/translation-service.git
cd translation-service
- Install the required packages
pip install -r requirements.txt
- Run the server
python src/main.py
To get the language of a text:
curl -X 'POST' \
'http://localhost:8000/detect' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"text": "Hello world!"
}'
To translate a text from German to English:
curl -X 'POST' \
'http://localhost:8000/translate' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"text": "Hallo Welt!",
"source_language": "de",
"target_language": "en"
}'
To run the automated tests for this system, use pytest
.
End to end tests ensure that the entire application flow works as expected.
pytest tests/end-to-end
Coding style tests ensure that the code adheres to the defined style guidelines using pre-commit
hooks.
pre-commit run --all-files
To use the translation service, follow these steps:
-
Ensure the server is running by following the instructions in the Getting Started section.
-
To detect the language of a text, send a POST request to the
/detect
endpoint:
curl -X 'POST' \
'http://localhost:8000/detect' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"text": "Hello world!"
}'
- To translate a text from one language to another, send a POST request to the
/translate
endpoint:
curl -X 'POST' \
'http://localhost:8000/translate' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"text": "Hallo Welt!",
"source_language": "de",
"target_language": "en"
}'
Replace "Hallo Welt!"
, "de"
, and "en"
with the text you want to translate and the appropriate source and target language codes.
To deploy this project on a live system using Docker and Docker Compose, follow these steps:
Ensure you have Docker and Docker Compose installed on your machine.
sudo apt-get install docker
sudo apt-get install docker-compose
- Clone the repository
git clone https://github.com/tutz/translation-service.git
cd translation-service
- Build the Docker images
docker-compose build
- Start the services
docker-compose up -d
This will start the application and its dependencies in the background.
- Verify the services are running
docker-compose ps
You should see the translation service and its dependencies listed and running.
The translation service will be available at http://localhost:8000
. You can use the same curl
commands mentioned in the Usage section to interact with the service.
To stop the services, run:
docker-compose down
This will stop and remove the containers, networks, and volumes created by Docker Compose.
- FastAPI - Web Framework
- Uvicorn - ASGI Server
- Docker - Containerization
- pytest - Testing Framework
- pre-commit - Git Hook Scripts
- mypy - Static Type Checker
- Ruff - Linter
- @TatjanaUtz - Idea & Initial work