Translator translate python not working
https://pypi.org/project/googletrans is an unofficial package (not created by Google). Also in the disclaimer, it has the following "...this API does not guarantee that the library would work properly at all times...". If you want stability, use official Google API https://cloud.google.com/translate/docs Show
Anyway below is a test to show the translator work:
Output:
I'm not sure what the issue you're experiencing. However I would suggest refactoring your code into methods and then you can test in isolation. The code below has not been tested, but should help debug:
Googletrans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make calls to such methods as detect and translate. Compatible with Python 3.6+. For details refer to the API Documentation. Features
TODOmore features are coming soon.
HTTP/2 supportThis library uses httpx for HTTP requests so HTTP/2 is supported by default. How does this library workYou may wonder why this library works properly, whereas other approaches such like goslate won’t work since Google has updated its translation service recently with a ticket mechanism to prevent a lot of crawler programs. I eventually figure out a way to generate a ticket by reverse engineering on the obfuscated and minified code used by Google to generate such token, and implemented on the top of Python. However, this could be blocked at any time. InstallationTo install, either use things like pip with the package “googletrans” or download the package and put the “googletrans” directory into your python path.
Basic UsageIf source language is not given, google translate attempts to detect the source language.
Customize service URLYou can use another google translate domain for translation. If multiple URLs are provided it then randomly chooses a domain.
Advanced Usage (Bulk)Array can be used to translate a batch of strings in a single method call and a single HTTP session. The exact same method shown above work for arrays as well.
Language detectionThe detect method, as its name implies, identifies the language used in a given sentence.
GoogleTrans as a command line application
Note on library usageDISCLAIMER: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.
VersioningThis library follows Semantic Versioning from v2.0.0. Any release versioned 0.x.y is subject to backwards incompatible changes at any time. Submitting a Pull RequestContributions to this library are always welcome and highly encouraged :)
LicenseGoogletrans is licensed under the MIT License. The terms are as follows: The MIT License (MIT) Copyright (c) 2015 SuHun Han Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Why is my translator not translating?The corrupted cached files can be the cause of the Translate app not working. You can clear them to fix the issue. You can go to Settings > App management > App list > translate > Storage usage. Then, you can click Clear data and Clear cache to delete them.
How do I enable TAP to translate?Turn Tap to Translate on or off. On your Android phone or tablet, open the Translate app .. At the top right, tap Menu Settings .. Tap Tap to Translate. Enable. For Android 10 and up: Tap Paste . For Pixel 6 and up: To get quick translations, you can turn on Show floating icon.. How do you translate text in Python?Introduction. from googletrans import Translator.. translator = Translator(). translated_text = translator. translate('안녕하세요. '). print(translated_text. text). translated_text = translator. translate('안녕하세요.', dest='ja'). How do you translate data in Python?Python String translate() Method. Replace any "S" characters with a "P" character: ... . Use a mapping table to replace "S" with "P": ... . Use a mapping table to replace many characters: ... . The third parameter in the mapping table describes characters that you want to remove from the string:. |