aiogtrans


Nameaiogtrans JSON
Version 1.1.10 PyPI version JSON
download
home_pagehttps://github.com/Leg3ndary/aiogtrans
SummaryAn async and updated version of the googletrans package.
upload_time2024-05-12 15:05:39
maintainerNone
docs_urlNone
authorBen Z
requires_python>=3.9
licenseMIT
keywords google translate translator async
VCS
bugtrack_url
requirements httpx setuptools
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiogtrans



aiogtrans is a **free** and **unlimited** python library that implements the Google Translate API asynchronously. This uses the [Google Translate Ajax API](https://translate.google.com>) and [httpx](https://www.python-httpx.org) to make api calls.



Compatible with Python 3.6+.



For details refer to the [API Documentation](https://aiogtrans.readthedocs.io/en/latest>).



## Features



-  Fast and semi-reliable

	- Uses the same api that google translate uses

	- Reverse Engineered

-  Auto language detection

-  Bulk translations

-  Customizable service URL

-  HTTP/2 support



## HTTP/2 support



This library uses httpx for HTTP requests so HTTP/2 is supported by default.



You can check if http2 is enabled and working by the `._response.http_version` of `Translated` or `Detected` object:



```py

>>> (await translator.translate('테스트'))._response.http_version

# 'HTTP/2'

```



### How does this library work?



You 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.



The original fork author [Suhun Han](https://github.com/ssut) eventually figured out a way to generate a ticket by reverse engineering the obfuscated and minified code used by Google to generate tokens [https://translate.google.com/translate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>](https://translate.google.comtranslate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>), and implemented this in Python. However, this could be blocked at any time.



### Why not use googletrans?



It seems [Suhun Han](https://github.com/ssut) has abandoned the project, at the time of this writing it's been nearly a year and a half since the last commit.



I have decided to move on and update this project.



## Installation



```bash

$ pip install aiogtrans

```



## Basic Usage



If a source language is not given, google translate attempts to detect the source language.



```python

>>> from aiogtrans import Translator

>>> translator = Translator()

>>> await translator.translate('안녕하세요.')

# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>

>>> await translator.translate('안녕하세요.', dest='ja')

# <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>

>>> await translator.translate('veritas lux mea', src='la')

# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>

```



### Customize service URL



You can use another google translate domain for translation. If multiple URLs are provided, the program will randomly choose a domain.



```python

>>> from aiogtrans import Translator

>>> translator = Translator(service_urls=[

        'translate.google.com',

        'translate.google.co.kr',

    ])

```



### Advanced Usage (Bulk Translations)



You can provide a list of strings to be used to translated in a single method and HTTP session. 



```python

>>> 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  ->  게으른 개

```



### Language Detection



The detect method, as its name implies, identifies the language used in a given sentence.



```python

>>> from googletrans import Translator

>>> translator = Translator()

>>> await translator.detect('이 문장은 한글로 쓰여졌습니다.')

# <Detected lang=ko confidence=0.27041003>

>>> await translator.detect('この文章は日本語で書かれました。')

# <Detected lang=ja confidence=0.64889508>

>>> await translator.detect('This sentence is written in English.')

# <Detected lang=en confidence=0.22348526>

>>> await translator.detect('Tiu frazo estas skribita en Esperanto.')

# <Detected lang=eo confidence=0.10538048>

```



## aiogtrans as a command line application



```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



$ translate "veritas lux mea" -s la -d en

[veritas] veritas lux mea

    ->

[en] The truth is my light

[pron.] The truth is my light



$ translate -c "안녕하세요."

[ko, 1] 안녕하세요.

```



## Note on Library Usage



**DISCLAIMER**: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.



-  **The maximum character limit on a single text is 15,000.**



-  Due to limitations of the web version of google translate, this API does not guarantee that the library would work properly at all times (so please use this library if you don't care about stability).



-  **Important:** If you want to use a stable API, it is highly recommended that you use Google's official translate API [https://cloud.google.com/translate/docs](https://cloud.google.com/translate/docs).



-  If you get HTTP 5xx error or errors like #6, it's probably because Google has banned your client IP address.



## Contributing



Contributions are currently discouraged, I am writing this fork as a personal project and if I ever do decide to open up to contributions I will change this.



Of course you're more then welcome to fork this and make your own changes



## License



**aiogtrans** is licensed under the MIT License. The terms are as follows:



The MIT License (MIT)



Copyright (c) 2022 Ben Zhou 



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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Leg3ndary/aiogtrans",
    "name": "aiogtrans",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "google translate translator async",
    "author": "Ben Z",
    "author_email": "bleg3ndary@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fb/27/51f8226c82d0981b067c10310fa07ca0cfa3e320274f39390e50b4584742/aiogtrans-1.1.10.tar.gz",
    "platform": null,
    "description": "# aiogtrans\r\r\n\r\r\naiogtrans is a **free** and **unlimited** python library that implements the Google Translate API asynchronously. This uses the [Google Translate Ajax API](https://translate.google.com>) and [httpx](https://www.python-httpx.org) to make api calls.\r\r\n\r\r\nCompatible with Python 3.6+.\r\r\n\r\r\nFor details refer to the [API Documentation](https://aiogtrans.readthedocs.io/en/latest>).\r\r\n\r\r\n## Features\r\r\n\r\r\n-  Fast and semi-reliable\r\r\n\t- Uses the same api that google translate uses\r\r\n\t- Reverse Engineered\r\r\n-  Auto language detection\r\r\n-  Bulk translations\r\r\n-  Customizable service URL\r\r\n-  HTTP/2 support\r\r\n\r\r\n## HTTP/2 support\r\r\n\r\r\nThis library uses httpx for HTTP requests so HTTP/2 is supported by default.\r\r\n\r\r\nYou can check if http2 is enabled and working by the `._response.http_version` of `Translated` or `Detected` object:\r\r\n\r\r\n```py\r\r\n>>> (await translator.translate('\ud14c\uc2a4\ud2b8'))._response.http_version\r\r\n# 'HTTP/2'\r\r\n```\r\r\n\r\r\n### How does this library work?\r\r\n\r\r\nYou 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.\r\r\n\r\r\nThe original fork author [Suhun Han](https://github.com/ssut) eventually figured out a way to generate a ticket by reverse engineering the obfuscated and minified code used by Google to generate tokens [https://translate.google.com/translate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>](https://translate.google.comtranslate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>), and implemented this in Python. However, this could be blocked at any time.\r\r\n\r\r\n### Why not use googletrans?\r\r\n\r\r\nIt seems [Suhun Han](https://github.com/ssut) has abandoned the project, at the time of this writing it's been nearly a year and a half since the last commit.\r\r\n\r\r\nI have decided to move on and update this project.\r\r\n\r\r\n## Installation\r\r\n\r\r\n```bash\r\r\n$ pip install aiogtrans\r\r\n```\r\r\n\r\r\n## Basic Usage\r\r\n\r\r\nIf a source language is not given, google translate attempts to detect the source language.\r\r\n\r\r\n```python\r\r\n>>> from aiogtrans import Translator\r\r\n>>> translator = Translator()\r\r\n>>> await translator.translate('\uc548\ub155\ud558\uc138\uc694.')\r\r\n# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>\r\r\n>>> await translator.translate('\uc548\ub155\ud558\uc138\uc694.', dest='ja')\r\r\n# <Translated src=ko dest=ja text=\u3053\u3093\u306b\u3061\u306f\u3002 pronunciation=Kon'nichiwa.>\r\r\n>>> await translator.translate('veritas lux mea', src='la')\r\r\n# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>\r\r\n```\r\r\n\r\r\n### Customize service URL\r\r\n\r\r\nYou can use another google translate domain for translation. If multiple URLs are provided, the program will randomly choose a domain.\r\r\n\r\r\n```python\r\r\n>>> from aiogtrans import Translator\r\r\n>>> translator = Translator(service_urls=[\r\r\n        'translate.google.com',\r\r\n        'translate.google.co.kr',\r\r\n    ])\r\r\n```\r\r\n\r\r\n### Advanced Usage (Bulk Translations)\r\r\n\r\r\nYou can provide a list of strings to be used to translated in a single method and HTTP session. \r\r\n\r\r\n```python\r\r\n>>> translations = await translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')\r\r\n>>> for translation in translations:\r\r\n...    print(translation.origin, ' -> ', translation.text)\r\r\n# The quick brown fox  ->  \ube60\ub978 \uac08\uc0c9 \uc5ec\uc6b0\r\r\n# jumps over  ->  \uc774\uc0c1 \uc810\ud504\r\r\n# the lazy dog  ->  \uac8c\uc73c\ub978 \uac1c\r\r\n```\r\r\n\r\r\n### Language Detection\r\r\n\r\r\nThe detect method, as its name implies, identifies the language used in a given sentence.\r\r\n\r\r\n```python\r\r\n>>> from googletrans import Translator\r\r\n>>> translator = Translator()\r\r\n>>> await translator.detect('\uc774 \ubb38\uc7a5\uc740 \ud55c\uae00\ub85c \uc4f0\uc5ec\uc84c\uc2b5\ub2c8\ub2e4.')\r\r\n# <Detected lang=ko confidence=0.27041003>\r\r\n>>> await translator.detect('\u3053\u306e\u6587\u7ae0\u306f\u65e5\u672c\u8a9e\u3067\u66f8\u304b\u308c\u307e\u3057\u305f\u3002')\r\r\n# <Detected lang=ja confidence=0.64889508>\r\r\n>>> await translator.detect('This sentence is written in English.')\r\r\n# <Detected lang=en confidence=0.22348526>\r\r\n>>> await translator.detect('Tiu frazo estas skribita en Esperanto.')\r\r\n# <Detected lang=eo confidence=0.10538048>\r\r\n```\r\r\n\r\r\n## aiogtrans as a command line application\r\r\n\r\r\n```bash\r\r\n$ translate -h\r\r\nusage: translate [-h] [-d DEST] [-s SRC] [-c] text\r\r\n\r\r\nPython Google Translator as a command-line tool\r\r\n\r\r\npositional arguments:\r\r\n    text                  The text you want to translate.\r\r\n\r\r\noptional arguments:\r\r\n    -h, --help            show this help message and exit\r\r\n    -d DEST, --dest DEST  The destination language you want to translate.\r\r\n                        (Default: en)\r\r\n    -s SRC, --src SRC     The source language you want to translate. (Default:\r\r\n                        auto)\r\r\n    -c, --detect\r\r\n\r\r\n$ translate \"veritas lux mea\" -s la -d en\r\r\n[veritas] veritas lux mea\r\r\n    ->\r\r\n[en] The truth is my light\r\r\n[pron.] The truth is my light\r\r\n\r\r\n$ translate -c \"\uc548\ub155\ud558\uc138\uc694.\"\r\r\n[ko, 1] \uc548\ub155\ud558\uc138\uc694.\r\r\n```\r\r\n\r\r\n## Note on Library Usage\r\r\n\r\r\n**DISCLAIMER**: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.\r\r\n\r\r\n-  **The maximum character limit on a single text is 15,000.**\r\r\n\r\r\n-  Due to limitations of the web version of google translate, this API does not guarantee that the library would work properly at all times (so please use this library if you don't care about stability).\r\r\n\r\r\n-  **Important:** If you want to use a stable API, it is highly recommended that you use Google's official translate API [https://cloud.google.com/translate/docs](https://cloud.google.com/translate/docs).\r\r\n\r\r\n-  If you get HTTP 5xx error or errors like #6, it's probably because Google has banned your client IP address.\r\r\n\r\r\n## Contributing\r\r\n\r\r\nContributions are currently discouraged, I am writing this fork as a personal project and if I ever do decide to open up to contributions I will change this.\r\r\n\r\r\nOf course you're more then welcome to fork this and make your own changes\r\r\n\r\r\n## License\r\r\n\r\r\n**aiogtrans** is licensed under the MIT License. The terms are as follows:\r\r\n\r\r\nThe MIT License (MIT)\r\r\n\r\r\nCopyright (c) 2022 Ben Zhou \r\r\n\r\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\r\nof this software and associated documentation files (the \"Software\"), to deal\r\r\nin the Software without restriction, including without limitation the rights\r\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\r\ncopies of the Software, and to permit persons to whom the Software is\r\r\nfurnished to do so, subject to the following conditions:\r\r\n\r\r\nThe above copyright notice and this permission notice shall be included in all\r\r\ncopies or substantial portions of the Software.\r\r\n\r\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\r\nSOFTWARE.\r\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An async and updated version of the googletrans package.",
    "version": "1.1.10",
    "project_urls": {
        "Homepage": "https://github.com/Leg3ndary/aiogtrans"
    },
    "split_keywords": [
        "google",
        "translate",
        "translator",
        "async"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb2751f8226c82d0981b067c10310fa07ca0cfa3e320274f39390e50b4584742",
                "md5": "51efce05e0c30c8bb5332365bbc60005",
                "sha256": "786457765aa334fd3f58ba4266932a8709e314f1f7f8c47247ab5268daf6cd4a"
            },
            "downloads": -1,
            "filename": "aiogtrans-1.1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "51efce05e0c30c8bb5332365bbc60005",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 14879,
            "upload_time": "2024-05-12T15:05:39",
            "upload_time_iso_8601": "2024-05-12T15:05:39.701467Z",
            "url": "https://files.pythonhosted.org/packages/fb/27/51f8226c82d0981b067c10310fa07ca0cfa3e320274f39390e50b4584742/aiogtrans-1.1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-12 15:05:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Leg3ndary",
    "github_project": "aiogtrans",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "httpx",
            "specs": [
                [
                    "<=",
                    "0.27.0"
                ]
            ]
        },
        {
            "name": "setuptools",
            "specs": [
                [
                    "==",
                    "58.1.0"
                ]
            ]
        }
    ],
    "lcname": "aiogtrans"
}
        
Elapsed time: 0.28664s