(html_text:str, to_language:str='en', translator:Callable='auto', n_jobs:int=-1, **kwargs)
return pattern.sub(repl=_get_result_func, string=html_text)
Translate the displayed content of html without changing the html structure.
    :param html_text: str, html format.
    :param to_language: str, default: 'en'.
    :param translator: translator, default 'auto', means ts.bing
    :param n_jobs: int, default -1, means os.cpu_cnt().
    :param **kwargs:
        :param if_ignore_limit_of_length: boolean, default False.
        :param timeout: float, default None.
        :param proxies: dict, default None.
    :return: str, html format.
Translate the displayed content of html without changing the html structure.
    :param html_text: str, html format.
    :param to_language: str, default: 'en'.
    :param translator: translator, default 'auto', means ts.bing
    :param n_jobs: int, default -1, means os.cpu_cnt().
    :param **kwargs:
        :param if_ignore_limit_of_length: boolean, default False.
        :param timeout: float, default None.
        :param proxies: dict, default None.
    :return: str, html format.
Translate the displayed content of html without changing the html structure . : param html_text : str html format . : param to_language : str default : en . : param translator : translator default auto means ts . bing : param n_jobs : int default - 1 means os . cpu_cnt () . : param ** kwargs : : param if_ignore_limit_of_length : boolean default False . : param timeout : float default None . : param proxies : dict default None . : return : str html format .
def translate_html(html_text:str, to_language:str='en', translator:Callable='auto', n_jobs:int=-1, **kwargs) -> str:
    """
    Translate the displayed content of html without changing the html structure.
    :param html_text: str, html format.
    :param to_language: str, default: 'en'.
    :param translator: translator, default 'auto', means ts.bing
    :param n_jobs: int, default -1, means os.cpu_cnt().
    :param **kwargs:
        :param if_ignore_limit_of_length: boolean, default False.
        :param timeout: float, default None.
        :param proxies: dict, default None.
    :return: str, html format.
    """
    if kwargs:
        for param in ('query_text', 'to_language', 'is_detail_result'):
            assert param not in kwargs, f'{param} should not be in `**kwargs`.'
    kwargs.update({'sleep_seconds': 0})

    n_jobs = os.cpu_count() if n_jobs <= 0 else n_jobs
    translator = bing if translator == 'auto' else translator

    pattern = re.compile(r"(?:^|(?<=>))([\s\S]*?)(?:(?=<)|$)") #TODO: <code></code> <div class="codetext notranslate">
    sentence_list = set(pattern.findall(html_text))
    _map_translate_func = lambda sentence: (sentence,translator(query_text=sentence, to_language=to_language, **kwargs))
    result_list = pathos.multiprocessing.ProcessPool(n_jobs).map(_map_translate_func, sentence_list)
    result_dict = {text: ts_text for text,ts_text in result_list}
    _get_result_func = lambda k: result_dict.get(k.group(1), '')
    return pattern.sub(repl=_get_result_func, string=html_text)
def translate_html ( html_text : str , to_language : str = 'en' , translator : Callable = 'auto' , n_jobs : int = - 1 , * * kwargs ) -> str : if kwargs : for param in ( 'query_text' , 'to_language' , 'is_detail_result' ) : assert param not in kwargs , f'{param} should not be in `**kwargs`.' kwargs . update ( { 'sleep_seconds' : 0 } ) n_jobs = os . cpu_count ( ) if n_jobs <= 0 else n_jobs translator = bing if translator == 'auto' else translator pattern = re . compile ( r"(?:^|(?<=>))([\s\S]*?)(?:(?=<)|$)" ) #TODO: <code></code> <div class="codetext notranslate"> sentence_list = set ( pattern . findall ( html_text ) ) _map_translate_func = lambda sentence : ( sentence , translator ( query_text = sentence , to_language = to_language , * * kwargs ) ) result_list = pathos . multiprocessing . ProcessPool ( n_jobs ) . map ( _map_translate_func , sentence_list ) result_dict = { text : ts_text for text , ts_text in result_list } _get_result_func = lambda k : result_dict . get ( k . group ( 1 ) , '' ) return pattern . sub ( repl = _get_result_func , string = html_text )