import json

import requests


class Detector:

    def __init__(self):
        self.url = "https://google-translate1.p.rapidapi.com/language/translate/v2/detect"
        self.headers = headers = {
            "content-type": "application/x-www-form-urlencoded",
            "Accept-Encoding": "application/gzip",
            "X-RapidAPI-Host": "google-translate1.p.rapidapi.com",
            "X-RapidAPI-Key": "9956beec72msh8f5b5e09b33da88p1d8b8cjsneac0d0fcdcea"
        }

    def detect_language(self, text):
        payload = "q=" + text
        payload.replace(" ", "%20")
        payload.replace(",", "%2C")
        response = requests.request("POST", self.url, data=payload, headers=self.headers)
        json_data = json.loads(response.text)
        formatted_string = json.dumps(json_data, indent=2)
        return formatted_string

