(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs)
return data if is_detail_result else ''.join([item[0] for item in data[0] if isinstance(item[0],str)])
https://translate.google.com, https://translate.google.cn.
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_use_cn_host: boolean, default None.
                :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 list
https://translate.google.com, https://translate.google.cn.
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_use_cn_host: boolean, default None.
                :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 list
https : // translate . google . com https : // translate . google . cn . : param query_text : str must . : param from_language : str default auto . : param to_language : str default en . : param ** kwargs : : param if_use_cn_host : boolean default None . : 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 list
def google_api(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs) -> Union[str,list]:
        """
        https://translate.google.com, https://translate.google.cn.
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_use_cn_host: boolean, default None.
                :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 list
        """

        use_cn_condition = kwargs.get('if_use_cn_host', None) or self.request_server_region_info.get('countryCode')=='CN'
        self.host_url = self.cn_host_url if use_cn_condition else self.en_host_url
        self.host_headers = self.get_headers(self.cn_host_url, if_api=False)
        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)

        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, ss, timeout, proxies)
            from_language,to_language = self.check_language(from_language,to_language,self.language_map,output_zh=self.output_zh)

            if not self.tkk:
                self.tkk = self.get_tkk(host_html, ss, timeout, proxies)

            tk = self.acquire(query_text, self.tkk)
            self.api_url = (self.host_url + '/translate_a/single?client={0}&sl={1}&tl={2}&hl=zh-CN&dt=at&dt=bd&dt=ex'
                + '&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&source=bh&ssel=0&tsel=0&kc=1&tk='
                + str(tk) + '&q=' + urllib.parse.quote(query_text)).format('webapp', from_language,to_language)  # [t,webapp]
            r = ss.get(self.api_url, headers=self.host_headers, timeout=timeout, proxies=proxies)
            r.raise_for_status()
            data = r.json()
        time.sleep(sleep_seconds)
        self.query_count += 1
        return data if is_detail_result else ''.join([item[0] for item in data[0] if isinstance(item[0],str)])
def google_api ( self , query_text : str , from_language : str = 'auto' , to_language : str = 'en' , * * kwargs ) -> Union [ str , list ] : use_cn_condition = kwargs . get ( 'if_use_cn_host' , None ) or self . request_server_region_info . get ( 'countryCode' ) == 'CN' self . host_url = self . cn_host_url if use_cn_condition else self . en_host_url self . host_headers = self . get_headers ( self . cn_host_url , if_api = False ) 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 ) 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 , ss , timeout , proxies ) from_language , to_language = self . check_language ( from_language , to_language , self . language_map , output_zh = self . output_zh ) if not self . tkk : self . tkk = self . get_tkk ( host_html , ss , timeout , proxies ) tk = self . acquire ( query_text , self . tkk ) self . api_url = ( self . host_url + '/translate_a/single?client={0}&sl={1}&tl={2}&hl=zh-CN&dt=at&dt=bd&dt=ex' + '&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&source=bh&ssel=0&tsel=0&kc=1&tk=' + str ( tk ) + '&q=' + urllib . parse . quote ( query_text ) ) . format ( 'webapp' , from_language , to_language ) # [t,webapp] r = ss . get ( self . api_url , headers = self . host_headers , timeout = timeout , proxies = proxies ) r . raise_for_status ( ) data = r . json ( ) time . sleep ( sleep_seconds ) self . query_count += 1 return data if is_detail_result else '' . join ( [ item [ 0 ] for item in data [ 0 ] if isinstance ( item [ 0 ] , str ) ] )