(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs)
return data if is_detail_result else ' '.join(item['beams'][0]['postprocessed_sentence'] for item in data['result']['translations'])
https://www.deepl.com
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or dict
https://www.deepl.com
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or dict
https : // www . deepl . com : param query_text : str must . : param from_language : str default auto . : param to_language : str default en . : param ** kwargs : : param if_ignore_limit_of_length : boolean default False . : param is_detail_result : boolean default False . : param timeout : float default None . : param proxies : dict default None . : param sleep_seconds : float default random . random () . : return : str or dict
def deepl_api(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs) -> Union[str,dict]:
        """
        https://www.deepl.com
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or dict
        """
        is_detail_result = kwargs.get('is_detail_result', False)
        timeout = kwargs.get('timeout', None)
        proxies = kwargs.get('proxies', None)
        sleep_seconds = kwargs.get('sleep_seconds', random.random())
        if_ignore_limit_of_length = kwargs.get('if_ignore_limit_of_length', False)
        query_text = self.check_query_text(query_text, if_ignore_limit_of_length)
        delete_temp_language_map_label = 0

        with requests.Session() as ss:
            host_html = ss.get(self.host_url, headers=self.host_headers, timeout=timeout, proxies=proxies).text
            if not self.language_map:
                self.language_map = self.get_language_map(host_html)
            if not self.language_map:
                delete_temp_language_map_label += 1
                self.language_map = self.make_temp_language_map(from_language, to_language)
            from_language, to_language = self.check_language(from_language, to_language, language_map=self.language_map,
                                                             output_zh=self.output_zh, output_auto='auto')
            from_language = from_language.upper() if from_language != 'auto' else from_language
            to_language = to_language.upper() if to_language != 'auto' else to_language

            ss_params, ss_data = self.split_sentences_param(query_text, from_language)
            _ = ss.options(self.api_url, params=ss_params, headers=self.api_headers, timeout=timeout, proxies=proxies)
            r_ss = ss.post(self.api_url, params=ss_params, json=ss_data, headers=self.api_headers, timeout=timeout, proxies=proxies)
            r_ss.raise_for_status()
            ss_data = r_ss.json()
            ss_sentences = ss_data['result']['splitted_texts'][0]

            cs_params, cs_data = self.context_sentences_param(ss_sentences, from_language, to_language)
            _ = ss.options(self.api_url, params=cs_params, headers=self.api_headers, timeout=timeout, proxies=proxies)
            r_cs = ss.post(self.api_url, params=cs_params, json=cs_data, headers=self.api_headers, timeout=timeout, proxies=proxies)
            r_cs.raise_for_status()
            data = r_cs.json()

        if delete_temp_language_map_label != 0:
            self.language_map = None
        time.sleep(sleep_seconds)
        self.query_count += 1
        return data if is_detail_result else ' '.join(item['beams'][0]['postprocessed_sentence'] for item in data['result']['translations'])
def deepl_api ( self , query_text : str , from_language : str = 'auto' , to_language : str = 'en' , * * kwargs ) -> Union [ str , dict ] : is_detail_result = kwargs . get ( 'is_detail_result' , False ) timeout = kwargs . get ( 'timeout' , None ) proxies = kwargs . get ( 'proxies' , None ) sleep_seconds = kwargs . get ( 'sleep_seconds' , random . random ( ) ) if_ignore_limit_of_length = kwargs . get ( 'if_ignore_limit_of_length' , False ) query_text = self . check_query_text ( query_text , if_ignore_limit_of_length ) delete_temp_language_map_label = 0 with requests . Session ( ) as ss : host_html = ss . get ( self . host_url , headers = self . host_headers , timeout = timeout , proxies = proxies ) . text if not self . language_map : self . language_map = self . get_language_map ( host_html ) if not self . language_map : delete_temp_language_map_label += 1 self . language_map = self . make_temp_language_map ( from_language , to_language ) from_language , to_language = self . check_language ( from_language , to_language , language_map = self . language_map , output_zh = self . output_zh , output_auto = 'auto' ) from_language = from_language . upper ( ) if from_language != 'auto' else from_language to_language = to_language . upper ( ) if to_language != 'auto' else to_language ss_params , ss_data = self . split_sentences_param ( query_text , from_language ) _ = ss . options ( self . api_url , params = ss_params , headers = self . api_headers , timeout = timeout , proxies = proxies ) r_ss = ss . post ( self . api_url , params = ss_params , json = ss_data , headers = self . api_headers , timeout = timeout , proxies = proxies ) r_ss . raise_for_status ( ) ss_data = r_ss . json ( ) ss_sentences = ss_data [ 'result' ] [ 'splitted_texts' ] [ 0 ] cs_params , cs_data = self . context_sentences_param ( ss_sentences , from_language , to_language ) _ = ss . options ( self . api_url , params = cs_params , headers = self . api_headers , timeout = timeout , proxies = proxies ) r_cs = ss . post ( self . api_url , params = cs_params , json = cs_data , headers = self . api_headers , timeout = timeout , proxies = proxies ) r_cs . raise_for_status ( ) data = r_cs . json ( ) if delete_temp_language_map_label != 0 : self . language_map = None time . sleep ( sleep_seconds ) self . query_count += 1 return data if is_detail_result else ' ' . join ( item [ 'beams' ] [ 0 ] [ 'postprocessed_sentence' ] for item in data [ 'result' ] [ 'translations' ] )