From 4d8b89937455728ffe669f66035824e4a8b1e91b Mon Sep 17 00:00:00 2001 From: cdhigh Date: Fri, 18 Oct 2024 13:17:46 -0300 Subject: [PATCH] minor updates --- .../lib/ebook_translator/engines/__init__.py | 6 ++-- .../lib/ebook_translator/html_translator.py | 30 ++++++++++++------- tools/gae_deploy.sh | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/application/lib/ebook_translator/engines/__init__.py b/application/lib/ebook_translator/engines/__init__.py index bbf0e8a2..d700e43c 100644 --- a/application/lib/ebook_translator/engines/__init__.py +++ b/application/lib/ebook_translator/engines/__init__.py @@ -7,6 +7,6 @@ from .baidu import BaiduTranslate from .microsoft import MicrosoftEdgeTranslate -builtin_translate_engines = (GoogleFreeTranslate, ChatgptTranslate, AzureChatgptTranslate, - GeminiPro, DeeplTranslate, DeeplProTranslate, DeeplFreeTranslate, - MicrosoftEdgeTranslate, YoudaoTranslate, BaiduTranslate) +builtin_translate_engines = (MicrosoftEdgeTranslate, GoogleFreeTranslate, ChatgptTranslate, + AzureChatgptTranslate, GeminiPro, DeeplTranslate, DeeplProTranslate, DeeplFreeTranslate, + YoudaoTranslate, BaiduTranslate) diff --git a/application/lib/ebook_translator/html_translator.py b/application/lib/ebook_translator/html_translator.py index 5a24868d..3aa5a37d 100644 --- a/application/lib/ebook_translator/html_translator.py +++ b/application/lib/ebook_translator/html_translator.py @@ -141,18 +141,26 @@ def add_translation_soup(self, soup, tag, trans, dst): position = self.params.get('position', 'below') origStyle = self.params.get('orig_style', '') transStyle = self.params.get('trans_style', '') - trans = trans.replace('<', '<').replace('>', '>') - #纯文本,不是html - if '<' not in trans or '>' not in trans: - transTagName = 'span' if tag.name in ('title', 'tr', 'td', 'th', 'thead', 'tbody', 'table', - 'ul', 'ol', 'li', 'a') else tag.name - transTag = soup.new_tag(transTagName) - transTag.string = trans + trans = trans.replace('<', '<').replace('>', '>').replace('< /', '' in trans: + transSoup = BeautifulSoup(trans, 'html.parser') #'html.parser'解析器不会自动添加 + transTag = transSoup.contents[0] if transSoup.contents else trans else: - transTag = BeautifulSoup(trans, 'html.parser') #'html.parser'解析器不会自动添加 - if not transTag.contents: - return - transTag = transTag.contents[0] + transTag = _wrapPureString(tag.name, trans) + + if isinstance(transTag, (str, NavigableString)): + transTag = _wrapPureString(tag.name, transTag) + if origStyle: old = tag.get('style') tag['style'] = f'{old};{origStyle}' if old else origStyle diff --git a/tools/gae_deploy.sh b/tools/gae_deploy.sh index d1029b30..377405a7 100644 --- a/tools/gae_deploy.sh +++ b/tools/gae_deploy.sh @@ -29,7 +29,7 @@ mv -f ${KE_DIR}/calibre/recipes/*.recipe ${KE_DIR}/application/recipes/ rm -rf ${KE_DIR}/calibre python3 -m venv ${KE_DIR}/myenv source ${KE_DIR}/myenv/bin/activate -pip3 install --upgrade pip +#pip3 install --upgrade pip pip3 install --no-cache-dir -q -r ${KE_DIR}/requirements.txt python3 ${KE_DIR}/tools/archive_builtin_recipes.py -q rm -f ${KE_DIR}/application/recipes/*.recipe > /dev/null 2>&1