MCPcopy
hub / github.com/PDFMathTranslate/PDFMathTranslate / do_translate

Method do_translate

pdf2zh/translator.py:179–194  ·  view source on GitHub ↗
(self, text)

Source from the content-addressed store, hash-verified

177 }
178
179 def do_translate(self, text):
180 text = text[:5000] # google translate max length
181 response = self.session.get(
182 self.endpoint,
183 params={"tl": self.lang_out, "sl": self.lang_in, "q": text},
184 headers=self.headers,
185 )
186 re_result = re.findall(
187 r'(?s)class="(?:t0|result-container)">(.*?)<', response.text
188 )
189 if response.status_code == 400:
190 result = "IRREPARABLE TRANSLATION ERROR"
191 else:
192 response.raise_for_status()
193 result = html.unescape(re_result[0])
194 return remove_control_characters(result)
195
196
197class BingTranslator(BaseTranslator):

Callers

nothing calls this directly

Calls 2

getMethod · 0.45

Tested by

no test coverage detected