Skip to content

Piyush-sri11/FAQ-Translation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FAQ Translation API

This is a Django REST Framework (DRF) based API for managing FAQs with automatic translations and caching using Redis. The API allows users to retrieve FAQs in multiple languages efficiently.

🚀 Features

  • Rich Text Support: FAQs include formatted text (bullets, numbering, etc.).
  • Automatic Translations: FAQs are automatically translated into multiple languages upon creation.
  • Fast Retrieval with Caching: Translations are cached using Redis to improve performance.
  • Admin Panel: Manage FAQs using Django Admin.

🛠️ Installation Guide

1. Clone the Repository

 git clone https://github.com/Piyush-sri11/FAQ-Translation.git

2. Set Up a Virtual Environment

 python -m venv env
 source env/bin/activate  # On Windows use: env\Scripts\activate

3. Install Dependencies

 pip install -r requirements.txt

4. Run Migrations

 python manage.py migrate

5. Create a Superuser (For Django Admin Access)

 python manage.py createsuperuser

6. Start Redis Server

Ensure Redis is installed and running before starting the Django server.

On Ubuntu/Debian

sudo apt update
sudo apt install redis-server
sudo systemctl enable redis-server.service
sudo systemctl start redis-server.service

On macOS

brew install redis
brew services start redis

On Windows

  1. Download Redis from the official website.
  2. Extract the zip file and run redis-server.exe.

On WSL

sudo apt update
sudo apt install redis-server
sudo service redis-server start

Ensure Redis is running by executing:

redis-cli ping

You should see PONG as the response.

7. Run the Django Server

 python manage.py runserver

📌 API Usage

1. Get All FAQs (Default: English)

GET /api/faqs/

Response:

[
  {
    "id": 1,
    "question": "What is instgram",
    "answer": "<p>its a social media platform</p>\r\n\r\n<p>&nbsp;</p>",
  }
]

2. Get FAQs in a Specific Language

GET /api/faqs/?lang=fr

Response:

[
  {
    "id": 1,
    "question": "Qu'est-ce qu'Instagram",
    "answer": "<p>C'est une plate-forme de médias sociaux</p>\n<p> </p>"
  }
]

3. Add a New FAQ (Admin Only)

POST /admin/faq/faq/add/

Admins can add new FAQs through the Django Admin Panel.

4. Retrieve Translated FAQ (Cached)

Translations are cached in Redis for faster retrieval.


Testing

Running Tests

1. Pytest

We use pytest for running tests. To run the tests, execute:

pytest --disable-warnings

2. Flake8

We use flake8 for linting the code. To check for linting errors, execute:

flake8

Defined Pytests

  • Test for FAQ Retrieval
  • Test for Adding a New FAQ
  • Test for Cached Translation Retrieval

🐳 Docker Usage

Building Docker Images

To build the Docker images for your application, use the following command:

docker-compose build

Starting Containers

To start the containers defined in your compose.yaml file, use:

docker-compose up

This command will start all the services defined in the compose.yaml file. You can add the -d flag to run the containers in detached mode:

docker-compose up -d

Stopping and Removing Containers

To stop and remove the containers, networks, and volumes defined in your compose.yaml file, use:

docker-compose down

This command will stop and remove all the resources created by docker-compose up.


🛠️ Contribution Guidelines

We welcome contributions! To contribute:

  1. Fork the repository.
  2. Create a new branch for your feature/fix.
  3. Commit your changes and push to your fork.
  4. Submit a pull request.

Coding Guidelines

  • Follow PEP8 for Python code.
  • Use meaningful commit messages.
  • Ensure tests pass before submitting a PR.

Reporting Issues

If you find a bug or have a feature request, please open an issue.


⚡ Future Enhancements

  • Containerizing the application using Dockerfile and docker-compose.yml
  • Deploying on AWS or Heroku

📝 License

This project is licensed under the MIT License.