Loading modules/translators/base.py +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) Loading modules/translators/trans_deeplx.py +7 −1 Original line number Diff line number Diff line Loading @@ -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 = { Loading Loading @@ -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' Loading @@ -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 = [] Loading @@ -224,5 +229,6 @@ class DeepLX(BaseTranslator): # t1 = e tl = translate(t,source,target) result.append(tl) return result Loading
modules/translators/base.py +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) Loading
modules/translators/trans_deeplx.py +7 −1 Original line number Diff line number Diff line Loading @@ -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 = { Loading Loading @@ -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' Loading @@ -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 = [] Loading @@ -224,5 +229,6 @@ class DeepLX(BaseTranslator): # t1 = e tl = translate(t,source,target) result.append(tl) return result