(self, text)
| 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 | |
| 197 | class BingTranslator(BaseTranslator): |
nothing calls this directly
no test coverage detected