(self, request)
| 80 | await self.init() |
| 81 | |
| 82 | async def translate(self, request): |
| 83 | src, dest = self.denormalize_lang(request.src, request.dest) |
| 84 | # Format url query data |
| 85 | text = quote(request.text, safe="") |
| 86 | url = self.translate_url.format(text=text, src=src, dest=dest) |
| 87 | |
| 88 | # Do request |
| 89 | response = await self.get(url) |
| 90 | try: |
| 91 | detected = response.get("info", {}).get("detectedSource", None) |
| 92 | mistakes = response.get("info", {}).get("typo", None) |
| 93 | src_pronunciation = response.get("info", {}).get("pronunciation", {}).get("query", None) |
| 94 | dest_pronunciation = response.get("info", {}).get("pronunciation", {}).get("translation", None) |
| 95 | |
| 96 | return Translation( |
| 97 | response["translation"], |
| 98 | request, |
| 99 | detected, |
| 100 | TranslationMistake(mistakes, mistakes) if mistakes else None, |
| 101 | TranslationPronunciation(src_pronunciation, dest_pronunciation), |
| 102 | ) |
| 103 | |
| 104 | except Exception as exc: |
| 105 | raise UnexpectedError("Failed reading the translation data") from exc |
| 106 | |
| 107 | async def speech(self, text, language): |
| 108 | (language,) = self.denormalize_lang(language) |
nothing calls this directly
no test coverage detected