Commit d0a50418 authored by dmMaze's avatar dmMaze
Browse files

try to fix deepl free (#254)

parent 580ecca8
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ from ..textdetector.textblock import TextBlock
from ..base import BaseModule, DEVICE_SELECTOR
from utils.registry import Registry
from utils.io_utils import text_is_empty
from utils.logger import logger as LOGGER

TRANSLATORS = Registry('translators')
register_translator = TRANSLATORS.register_module
@@ -152,7 +153,12 @@ class BaseTranslator(BaseModule):
            text_trans = self.text2textlist(text_trans)
            
        if is_list:
            try:
                assert len(text_trans) == len(text)
            except:
                LOGGER.error('This translator seems to messed up the translation which resulted in inconsistent translated line count.\n \
                             Set concate_text to False or change textblk_break in the source code may solve the problem.')
                raise
            # for ii, t in enumerate(text_trans):
            #     for callback in self._postprocess_hooks:
            #         text_trans[ii] = callback(t)
+7 −1
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ import json
import httpx
from langdetect import detect

from utils.logger import logger as LOGGER


deeplAPI = "https://www2.deepl.com/jsonrpc"
headers = {
@@ -179,10 +181,12 @@ class DeepLX(BaseTranslator):
    params: Dict = {
        'delay': 0.0,
    }
    concate_text = True
    
    def _setup_translator(self):
        self.lang_map['简体中文'] = 'zh'
        self.lang_map['日本語'] = 'ja'
        self.lang_map['English'] = 'EN-US'
        self.lang_map['English'] = 'en'
        self.lang_map['Français'] = 'fr'
        self.lang_map['Deutsch'] = 'de'
        self.lang_map['Italiano'] = 'it'
@@ -207,6 +211,7 @@ class DeepLX(BaseTranslator):
        self.lang_map['Indonesia'] = 'id'
        self.lang_map['украї́нська мо́ва'] = 'uk'
        self.lang_map['한국어'] = 'ko'
        self.textblk_break = '\n'

    def _translate(self, src_list: List[str]) -> List[str]:
        result = []
@@ -224,5 +229,6 @@ class DeepLX(BaseTranslator):
            #     t1 = e
            tl = translate(t,source,target)
            result.append(tl)
            
        return result