Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: lazy-import Tencent TMT and pin compatible SDK
Stop loading TextTranslateRequest at translator module import so
incompatible tencentcloud-sdk-python-tmt 3.1.129 no longer breaks
other engines. Pin the dependency to 3.0.1257-3.1.121, the last
releases that still ship the text-translate models.

Co-authored-by: Yuzhong Zhang <BetterAndBetterII@users.noreply.github.com>
  • Loading branch information
cursoragent and BetterAndBetterII committed Aug 18, 2026
commit e77e29942ff52f0ebd9059096c2ea64639e3bde8
19 changes: 12 additions & 7 deletions pdf2zh/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
import xinference_client
from azure.ai.translation.text import TextTranslationClient
from azure.core.credentials import AzureKeyCredential
from tencentcloud.common import credential
from tencentcloud.tmt.v20180321.models import (
TextTranslateRequest,
TextTranslateResponse,
)
from tencentcloud.tmt.v20180321.tmt_client import TmtClient

from pdf2zh.cache import TranslationCache
from pdf2zh.config import ConfigManager
Expand Down Expand Up @@ -763,6 +757,17 @@ class TencentTranslator(BaseTranslator):
def __init__(
self, lang_in, lang_out, model, envs=None, ignore_cache=False, **kwargs
):
try:
from tencentcloud.common import credential
from tencentcloud.tmt.v20180321.models import TextTranslateRequest
from tencentcloud.tmt.v20180321.tmt_client import TmtClient
except ImportError as e:
raise ImportError(
"Tencent translator requires tencentcloud-sdk-python-tmt "
"providing TextTranslateRequest. "
"Pin a compatible version, e.g. "
"pip install 'tencentcloud-sdk-python-tmt>=3.0.1257,<=3.1.121'"
) from e
self.set_envs(envs)
super().__init__(lang_in, lang_out, model)
try:
Expand All @@ -783,7 +788,7 @@ def __init__(

def _translate_chunk(self, text):
self.req.SourceText = text
resp: TextTranslateResponse = self.client.TextTranslate(self.req)
resp = self.client.TextTranslate(self.req)
return resp.TargetText

def do_translate(self, text):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ dependencies = [
"onnx",
"onnxruntime",
"opencv-python-headless",
"tencentcloud-sdk-python-tmt",
# 3.1.129+ dropped TextTranslateRequest used by TencentTranslator
"tencentcloud-sdk-python-tmt>=3.0.1257,<=3.1.121",
"pdfminer-six==20250416",
"gradio_pdf>=0.0.21",
"pikepdf",
Expand Down