### Installing Googletrans Python Library Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This command shows the standard way to install the Googletrans library using pip, Python's package installer. Running `pip install googletrans` will download and set up the library, making it available for import in your Python projects. This is the recommended method for quick and easy setup. ```Bash pip install googletrans ``` -------------------------------- ### Installing Googletrans Library (Bash) Source: https://github.com/ssut/py-googletrans/blob/main/docs/index.rst This snippet demonstrates how to install the Googletrans library using pip, the Python package installer. It's the first step to using the library for translation tasks. ```bash $ pip install googletrans ``` -------------------------------- ### Installing Googletrans Library with pip Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This command installs the Googletrans Python library from the Python Package Index (PyPI) using pip. It's the standard method to add the library to your Python environment, enabling access to its translation and language detection functionalities. ```Python pip install googletrans ``` -------------------------------- ### Generating Google Translate API Token with TokenAcquirer Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This example demonstrates how to use the `TokenAcquirer` class, an internal utility for generating the necessary token to access the Google Translate API. It initializes an `Acquirer` object, provides a sample text, and then calls the `do()` method to obtain the token. ```python from googletrans.gtoken import TokenAcquirer acquirer = TokenAcquirer() text = 'test' tk = acquirer.do(text) # Expected output for tk: 950629.577246 (example value) ``` -------------------------------- ### Detecting Language with googletrans.Translator (Basic) Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet demonstrates the basic usage of the `Translator().detect()` method to identify the language of a given text string. It shows how to initialize the Translator and then call `detect()` with various language examples, returning a `Detected` object with the language code and confidence. ```python from googletrans import Translator translator = Translator() translator.detect('이 문장은 한글로 쓰여졌습니다.') # Expected output: translator.detect('この文章は日本語で書かれました。') # Expected output: translator.detect('This sentence is written in English.') # Expected output: translator.detect('Tiu frazo estas skribita in Esperanto.') # Expected output: ``` -------------------------------- ### Performing Basic Asynchronous Translation with Googletrans Python Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This example illustrates basic asynchronous text translation using the `googletrans.Translator`. It demonstrates translating text with automatic source language detection, specifying a destination language, and providing both source and destination languages. The `async with Translator()` context manager ensures proper resource handling, and `asyncio.run()` executes the asynchronous function. ```Python import asyncio from googletrans import Translator async def translate_text(): async with Translator() as translator: result = await translator.translate('안녕하세요.') print(result) # result = await translator.translate('안녕하세요.', dest='ja') print(result) # result = await translator.translate('veritas lux mea', src='la') print(result) # asyncio.run(translate_text()) ``` -------------------------------- ### Translating Text with Googletrans Basic Usage Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html These Python examples demonstrate basic text translation using the `googletrans.Translator` class. They show how to initialize the translator, translate text with automatic source language detection, and specify a target language. The output is a `Translated` object containing the source, destination, translated text, and pronunciation. ```Python from googletrans import Translator translator = Translator() translator.translate('안녕하세요.') # translator.translate('안녕하세요.', dest='ja') # translator.translate('veritas lux mea', src='la') # ``` -------------------------------- ### Detecting Languages Asynchronously with Googletrans (Python) Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This Python snippet demonstrates how to use the `googletrans` library's asynchronous `detect` method to identify the language of a given text. It shows examples for English and Esperanto, printing the detected language and confidence score. This operation requires an `asyncio` event loop. ```Python ... result = await translator.detect('This sentence is written in English.') ... print(result) # ... ... result = await translator.detect('Tiu frazo estas skribita in Esperanto.') ... print(result) # ... >>> asyncio.run(detect_languages()) ``` -------------------------------- ### Performing Asynchronous Bulk Translation with Googletrans Python Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This snippet illustrates how to perform bulk translations of multiple strings asynchronously. By passing a list of strings to the `translate` method, the library processes them in a single call, optimizing HTTP sessions. The example then iterates through the returned `Translated` objects, printing the original text and its Korean translation. ```Python import asyncio from googletrans import Translator async def translate_bulk(): async with Translator() as translator: translations = await translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko') for translation in translations: print(translation.origin, ' -> ', translation.text) # The quick brown fox -> 빠른 갈색 여우 # jumps over -> 이상 점프 # the lazy dog -> 게으른 개 asyncio.run(translate_bulk()) ``` -------------------------------- ### Detecting Languages Asynchronously with Googletrans Python Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This example demonstrates using the `detect` method to identify the language of a given text asynchronously. It shows how to pass a string to `translator.detect()` and then access the `lang` and `confidence` attributes of the returned `Detected` object. This is useful for applications requiring automatic language identification before translation. ```Python import asyncio from googletrans import Translator async def detect_languages(): async with Translator() as translator: result = await translator.detect('이 문장은 한글로 쓰여졌습니다.') print(result) # result = await translator.detect('この文章は日本語で書かれました。') print(result) # ``` -------------------------------- ### Configuring Googletrans for Standard API Endpoint in Python Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This example demonstrates configuring the `Translator` to use the standard Google Translate API endpoint (`translate.googleapis.com`). Unlike webapp-based URLs that might require a token, this direct API endpoint often provides more stable and reliable translation processing, addressing potential issues with token generation. It's recommended for robust applications. ```Python from googletrans import Translator translator = Translator(service_urls=[ 'translate.googleapis.com' ]) ``` -------------------------------- ### Displaying Help for Googletrans CLI (Bash) Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This Bash snippet illustrates how to access the help documentation for the `translate` command-line tool, part of the `py-googletrans` project. It outlines the available arguments for translation and language detection, including source/destination languages and the text input. ```Bash $ translate -h usage: translate [-h] [-d DEST] [-s SRC] [-c] text Python Google Translator as a command-line tool positional arguments: text The text you want to translate. optional arguments: -h, --help show this help message and exit -d DEST, --dest DEST The destination language you want to translate. (Default: en) -s SRC, --src SRC The source language you want to translate. (Default: auto) -c, --detect ``` -------------------------------- ### Initializing Googletrans Translator with Custom Service URLs (Python) Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet demonstrates how to initialize the `googletrans.Translator` class with a list of custom Google Translate service URLs. Providing multiple URLs allows the translator to randomly choose a domain for translation, which can be useful for load balancing or bypassing regional restrictions. The `service_urls` parameter accepts a list of strings, each representing a valid Google Translate domain. ```Python from googletrans import Translator translator = Translator(service_urls=[ 'translate.google.com', 'translate.google.co.kr' ]) ``` -------------------------------- ### Cloning py-googletrans Repository - Shell Source: https://github.com/ssut/py-googletrans/blob/main/CONTRIBUTING.md This command clones the `py-googletrans` source code repository from GitHub to your local machine. It's the initial step to obtain the project files for development or contribution. ```Shell $ git clone https://github.com/ssut/py-googletrans ``` -------------------------------- ### Performing Bulk Translations with Googletrans (Python) Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet illustrates how to translate a batch of strings simultaneously using the `googletrans` library. By passing a list of strings to the `translate` method, all translations are performed in a single method call and HTTP session, improving efficiency. The `dest` parameter specifies the target language for translation, in this case, Korean ('ko'). The snippet then iterates through the returned `translations` object to print the original and translated texts. ```Python translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko') for translation in translations: print(translation.origin, ' -> ', translation.text) ``` -------------------------------- ### Running Project Unit Tests with Pytest - Python Source: https://github.com/ssut/py-googletrans/blob/main/CONTRIBUTING.md This command executes the project's unit tests using the `pytest` framework. It's a crucial step to ensure that new changes or bug fixes do not introduce regressions and that all existing functionality remains intact. ```Python pytest ``` -------------------------------- ### Initializing Searchbox Display - JavaScript Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/py-modindex.html This JavaScript snippet uses jQuery to immediately show the searchbox element on the page. It's typically used to ensure a UI element is visible upon page load or after a certain condition is met. ```JavaScript $('#searchbox').show(0); ``` -------------------------------- ### Animating GitHub Corner Icon with CSS Source: https://github.com/ssut/py-googletrans/blob/main/docs/_themes/solar/layout.html This CSS snippet defines the animation for the GitHub corner icon, making the octocat arm wave on hover and providing a continuous wave animation on smaller screens. It uses keyframes to control the rotation of the arm. ```CSS .github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}} ``` -------------------------------- ### Animating GitHub Corner Octocat Arm with CSS Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This CSS snippet defines an animation for the 'octo-arm' element, typically part of a GitHub corner ribbon. The `octocat-wave` keyframe animation makes the arm wave on hover and on smaller screens. It ensures a dynamic visual effect for the GitHub link. ```CSS [](https://github.com/ssut/py-googletrans).github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}} ``` -------------------------------- ### Basic Text Translation with googletrans.Translator in Python Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet illustrates the basic usage of the `translate` method for single-text translation. It shows how to initialize the `Translator` and translate text from an automatically detected source language to a destination language (defaulting to English) or to a specified destination language like Japanese, or from a specified source language like Latin. ```Python from googletrans import Translator translator = Translator() translator.translate('안녕하세요.') translator.translate('안녕하세요.', dest='ja') translator.translate('veritas lux mea', src='la') ``` -------------------------------- ### Translating Text with Googletrans (Python) Source: https://github.com/ssut/py-googletrans/blob/main/docs/index.rst This snippet shows basic text translation using the googletrans.Translator class. It demonstrates translating text with automatic source language detection, specifying a destination language, and providing a source language explicitly. The output is a Translated object containing source, destination, translated text, and pronunciation. ```python >>> from googletrans import Translator >>> translator = Translator() >>> translator.translate('안녕하세요.') # >>> translator.translate('안녕하세요.', dest='ja') # >>> translator.translate('veritas lux mea', src='la') # ``` -------------------------------- ### MIT License for Googletrans Library Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This snippet provides the full text of the MIT License under which the Googletrans library is distributed. It grants broad permissions for use, modification, and distribution, provided the copyright and permission notices are included, and disclaims warranties. ```Text 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. ``` -------------------------------- ### Translating Text with Googletrans CLI (Bash) Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This Bash command demonstrates how to translate text using the `translate` command-line tool. It translates the Latin phrase 'veritas lux mea' to English, specifying source ('la') and destination ('en') languages, and displays the original, translated text, and pronunciation. ```Bash $ translate "veritas lux mea" -s la -d en [veritas] veritas lux mea -> [en] The truth is my light [pron.] The truth is my light ``` -------------------------------- ### Customizing Googletrans Service URLs in Python Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This snippet shows how to initialize the `Translator` with a list of custom Google Translate service URLs. Providing multiple URLs allows the library to randomly choose a domain for translation requests, which can be useful for load balancing or bypassing regional restrictions. This offers flexibility in how translation requests are routed. ```Python from googletrans import Translator translator = Translator(service_urls=[ 'translate.google.com', 'translate.google.co.kr', ]) ``` -------------------------------- ### Defining GitHub Corner Octocat Wave Animation - CSS Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/py-modindex.html This CSS snippet defines a keyframe animation named 'octocat-wave' for a GitHub corner element. It creates a waving effect on hover and ensures the animation also plays on smaller screens, providing visual feedback for the GitHub link. ```CSS .github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}} ``` -------------------------------- ### Batch Text Translation with googletrans.Translator in Python Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet demonstrates advanced usage of the `translate` method for batch translation. It shows how to pass a list of strings to the method for simultaneous translation and then iterate through the returned `Translated` objects to access the original and translated texts. ```Python translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko') for translation in translations: print(translation.origin, ' -> ', translation.text) ``` -------------------------------- ### Customizing Googletrans Service URLs (Python) Source: https://github.com/ssut/py-googletrans/blob/main/docs/index.rst This snippet illustrates how to initialize the Translator with custom service URLs. Providing multiple URLs allows the library to randomly choose a domain for translation, which can be useful for bypassing IP bans or regional restrictions. ```python >>> from googletrans import Translator >>> translator = Translator(service_urls=[ 'translate.google.com', 'translate.google.co.kr', ]) ``` -------------------------------- ### Detecting Multiple Languages with googletrans.Translator (Advanced) Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet illustrates advanced usage of `Translator().detect()` by passing a list of strings for batch language detection. It then iterates through the returned list of `Detected` objects, printing each detected language code and its confidence score. ```python langs = translator.detect(['한국어', '日本語', 'English', 'le français']) for lang in langs: print(lang.lang, lang.confidence) # Expected output: # ko 1 # ja 0.92929292 # en 0.96954316 # fr 0.043500196 ``` -------------------------------- ### Displaying Searchbox with jQuery Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This JavaScript snippet uses jQuery to immediately display an HTML element identified by the ID 'searchbox'. It's typically employed in web page initialization scripts to ensure a specific UI component, like a search input, is visible upon page load. ```JavaScript $('#searchbox').show(0); ``` -------------------------------- ### Performing Bulk Translations with Googletrans (Python) Source: https://github.com/ssut/py-googletrans/blob/main/docs/index.rst This snippet demonstrates how to translate a list of strings in a single method call using googletrans.Translator. It shows iterating through the returned Translated objects to access the original and translated text for each item in the batch. ```python >>> translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko') >>> for translation in translations: ... print(translation.origin, ' -> ', translation.text) # The quick brown fox -> 빠른 갈색 여우 # jumps over -> 이상 점프 # the lazy dog -> 게으른 개 ``` -------------------------------- ### Creating New Git Branch for Contributions - Shell Source: https://github.com/ssut/py-googletrans/blob/main/CONTRIBUTING.md This command creates and switches to a new Git branch named `BRANCH_NAME` based on the `origin/master` branch. It's used when preparing to contribute new features or fixes, ensuring changes are isolated from the main branch. ```Shell $ git checkout -b BRANCH_NAME origin/master ``` -------------------------------- ### Updating and Fetching Remote Git Branches - Shell Source: https://github.com/ssut/py-googletrans/blob/main/CONTRIBUTING.md This command sequence updates remote tracking branches and then fetches new objects from the remote repository. It's typically used to synchronize your local repository with the upstream `master` branch before creating a new feature branch, especially if `git checkout` fails. ```Shell $ git remote update && git fetch ``` -------------------------------- ### Detecting Language with Googletrans (Python) Source: https://github.com/ssut/py-googletrans/blob/main/docs/index.rst This snippet illustrates the use of the detect method to identify the language of a given text. It returns a Detected object containing the detected language code and a confidence score, useful for pre-processing text before translation. ```python >>> translator.detect('이 문장은 한글로 쓰여졌습니다.') # >>> translator.detect('この文章は日本語で書かれました。') # >>> translator.detect('This sentence is written in English.') # >>> translator.detect('Tiu frazo estas skribita en Esperanto.') # ``` -------------------------------- ### Checking HTTP/2 Support in Googletrans Python Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This snippet demonstrates how to verify if HTTP/2 is enabled and being used by the Googletrans library. After performing a translation using an initialized `Translator` instance, you can access the `_response.http_version` attribute of the returned `Translated` object to check the HTTP protocol version used for the request. This confirms the library's modern HTTP capabilities. ```Python translator.translate('테스트')._response.http_version ``` -------------------------------- ### Detecting Language with Googletrans CLI (Bash) Source: https://github.com/ssut/py-googletrans/blob/main/README.rst This Bash command illustrates how to detect the language of a given text using the `translate` command-line tool with the `-c` (detect) flag. It identifies '안녕하세요.' as Korean ('ko') with a confidence score of 1. ```Bash $ translate -c "안녕하세요." [ko, 1] 안녕하세요. ``` -------------------------------- ### Supported Language Codes in googletrans Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This Python dictionary, `LANGUAGES`, provides a mapping of ISO 639-1 language codes to their full language names, representing the languages supported for translation by the Google Translate API. It also includes `SPECIAL_CASES` for specific language code adjustments. ```python SPECIAL_CASES = { 'ee': 'et', } LANGUAGES = { 'af': 'afrikaans', 'sq': 'albanian', 'am': 'amharic', 'ar': 'arabic', 'hy': 'armenian', 'az': 'azerbaijani', 'eu': 'basque', 'be': 'belarusian', 'bn': 'bengali', 'bs': 'bosnian', 'bg': 'bulgarian', 'ca': 'catalan', 'ceb': 'cebuano', 'ny': 'chichewa', 'zh-cn': 'chinese (simplified)', 'zh-tw': 'chinese (traditional)', 'co': 'corsican', 'hr': 'croatian', 'cs': 'czech', 'da': 'danish', 'nl': 'dutch', 'en': 'english', 'eo': 'esperanto', 'et': 'estonian', 'tl': 'filipino', 'fi': 'finnish', 'fr': 'french', 'fy': 'frisian', 'gl': 'galician', 'ka': 'georgian', 'de': 'german', 'el': 'greek', 'gu': 'gujarati', 'ht': 'haitian creole', 'ha': 'hausa', 'haw': 'hawaiian', 'iw': 'hebrew', 'he': 'hebrew', 'hi': 'hindi', 'hmn': 'hmong', 'hu': 'hungarian', 'is': 'icelandic', 'ig': 'igbo', 'id': 'indonesian', 'ga': 'irish', 'it': 'italian', 'ja': 'japanese' } ``` -------------------------------- ### Defining Language Mappings in Python Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet defines a mapping of two-letter language codes to their full language names. It is typically used within the `py-googletrans` library to identify and process various languages supported by the Google Translate API. This mapping ensures consistent language identification across the application. ```Python 'jw': 'javanese', 'kn': 'kannada', 'kk': 'kazakh', 'km': 'khmer', 'ko': 'korean', 'ku': 'kurdish (kurmanji)', 'ky': 'kyrgyz', 'lo': 'lao', 'la': 'latin', 'lv': 'latvian', 'lt': 'lithuanian', 'lb': 'luxembourgish', 'mk': 'macedonian', 'mg': 'malagasy', 'ms': 'malay', 'ml': 'malayalam', 'mt': 'maltese', 'mi': 'maori', 'mr': 'marathi', 'mn': 'mongolian', 'my': 'myanmar (burmese)', 'ne': 'nepali', 'no': 'norwegian', 'or': 'odia', 'ps': 'pashto', 'fa': 'persian', 'pl': 'polish', 'pt': 'portuguese', 'pa': 'punjabi', 'ro': 'romanian', 'ru': 'russian', 'sm': 'samoan', 'gd': 'scots gaelic', 'sr': 'serbian', 'st': 'sesotho', 'sn': 'shona', 'sd': 'sindhi', 'si': 'sinhala', 'sk': 'slovak', 'sl': 'slovenian', 'so': 'somali', 'es': 'spanish', 'su': 'sundanese', 'sw': 'swahili', 'sv': 'swedish', 'tg': 'tajik', 'ta': 'tamil', 'te': 'telugu', 'th': 'thai', 'tr': 'turkish', 'uk': 'ukrainian', 'ur': 'urdu', 'ug': 'uyghur', 'uz': 'uzbek', 'vi': 'vietnamese', 'cy': 'welsh', 'xh': 'xhosa', 'yi': 'yiddish', 'yo': 'yoruba', 'zu': 'zulu' ``` -------------------------------- ### Detecting Language with googletrans.Translator in Python Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/index.html This snippet demonstrates how to use the `detect` method of the `googletrans.Translator` class to identify the language of a given text. The method returns a `Detected` object containing the detected language code (e.g., 'ko', 'ja', 'en', 'eo') and a confidence score. ```Python translator.detect('이 문장은 한글로 쓰여졌습니다.') translator.detect('この文章は日本語で書かれました。') translator.detect('This sentence is written in English.') translator.detect('Tiu frazo estas skribita en Esperanto.') ``` -------------------------------- ### Hiding Fallback Element with jQuery Source: https://github.com/ssut/py-googletrans/blob/main/docs/_build/html/search.html This JavaScript snippet uses the jQuery library to select an HTML element with the ID 'fallback' and immediately hides it. This is typically used to conceal a message or UI component that is only relevant when JavaScript is disabled, ensuring a cleaner user experience when JavaScript is active. ```JavaScript $('#fallback').hide(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.