googletransfork


Namegoogletransfork JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/Suro4ek/py-googletrans
SummaryFree Google Translate API for Python. Translates totally free of charge.
upload_time2024-09-22 03:04:00
maintainerNone
docs_urlNone
authorSuHun Han, Suro
requires_python>=3.6
licenseMIT
keywords google translate translator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Googletrans
===========

|GitHub license| |travis status| |Documentation Status| |PyPI version|
|Coverage Status| |Code Climate|

ANNOUNCEMENT: `v1.0 is planned <https://github.com/ssut/py-googletrans/issues/411>`_.

Googletrans is a **free** and **unlimited** python library that
implemented Google Translate API. This uses the `Google Translate Ajax
API <https://translate.google.com>`__ to make calls to such methods as
detect and translate.

Compatible with Python 3.6+.

For details refer to the `API
Documentation <https://py-googletrans.readthedocs.io/en/latest>`__.

Features
--------

-  Fast and reliable - it uses the same servers that
   translate.google.com uses
-  Auto language detection
-  Bulk translations
-  Customizable service URL
-  HTTP/2 support

TODO
~~~~

more features are coming soon.

-  Proxy support
-  Internal session management (for better bulk translations)

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:

.. code:: python

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

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 <https://translate.google.com/translate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>`__,
and implemented on the top of Python. However, this could be blocked at
any time.

--------------

Installation
------------

To install, either use things like pip with the package "googletransfork"
or download the package and put the "googletransfork" directory into your
python path.

.. code:: bash

    $ pip install googletransfork

Basic Usage
-----------

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

.. code:: python

    >>> from googletrans import Translator
    >>> translator = Translator()
    >>> translator.translate('안녕하세요.')
    # <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>
    >>> translator.translate('안녕하세요.', dest='ja')
    # <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>
    >>> 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, it then randomly chooses a domain.

.. code:: python

    >>> from googletrans import Translator
    >>> translator = Translator(service_urls=[
          'translate.google.com',
          'translate.google.co.kr',
        ])

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 works
for arrays as well.

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

Language detection
~~~~~~~~~~~~~~~~~~

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

.. code:: python

    >>> from googletrans import Translator
    >>> translator = Translator()
    >>> translator.detect('이 문장은 한글로 쓰여졌습니다.')
    # <Detected lang=ko confidence=0.27041003>
    >>> translator.detect('この文章は日本語で書かれました。')
    # <Detected lang=ja confidence=0.64889508>
    >>> translator.detect('This sentence is written in English.')
    # <Detected lang=en confidence=0.22348526>
    >>> translator.detect('Tiu frazo estas skribita en Esperanto.')
    # <Detected lang=eo confidence=0.10538048>

GoogleTrans as a command line application
-----------------------------------------

.. code:: 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 15k.**

-  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, I highly recommend you to use
   `Google's official translate
   API <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.

--------------

Versioning
----------

This library follows `Semantic Versioning <http://semver.org/>`__ from
v2.0.0. Any release versioned 0.x.y is subject to backwards incompatible
changes at any time.

Contributing
-------------------------

Contributions are more than welcomed. See
`CONTRIBUTING.md <CONTRIBUTING.md>`__

-----------------------------------------

License
-------

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

.. |GitHub license| image:: https://img.shields.io/github/license/mashape/apistatus.svg
   :target: http://opensource.org/licenses/MIT
.. |travis status| image:: https://travis-ci.org/ssut/py-googletrans.svg?branch=master
   :target: https://travis-ci.org/ssut/py-googletrans
.. |Documentation Status| image:: https://readthedocs.org/projects/py-googletrans/badge/?version=latest
   :target: https://readthedocs.org/projects/py-googletrans/?badge=latest
.. |PyPI version| image:: https://badge.fury.io/py/googletrans.svg
   :target: http://badge.fury.io/py/googletrans
.. |Coverage Status| image:: https://coveralls.io/repos/github/ssut/py-googletrans/badge.svg
   :target: https://coveralls.io/github/ssut/py-googletrans
.. |Code Climate| image:: https://codeclimate.com/github/ssut/py-googletrans/badges/gpa.svg
   :target: https://codeclimate.com/github/ssut/py-googletrans

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Suro4ek/py-googletrans",
    "name": "googletransfork",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "google translate translator",
    "author": "SuHun Han, Suro",
    "author_email": "ssut@ssut.me",
    "download_url": "https://files.pythonhosted.org/packages/01/d3/36e2e2b21df8746822b77701510dfacce45159e8601b504773e346c00c81/googletransfork-1.0.1.tar.gz",
    "platform": null,
    "description": "Googletrans\n===========\n\n|GitHub license| |travis status| |Documentation Status| |PyPI version|\n|Coverage Status| |Code Climate|\n\nANNOUNCEMENT: `v1.0 is planned <https://github.com/ssut/py-googletrans/issues/411>`_.\n\nGoogletrans is a **free** and **unlimited** python library that\nimplemented Google Translate API. This uses the `Google Translate Ajax\nAPI <https://translate.google.com>`__ to make calls to such methods as\ndetect and translate.\n\nCompatible with Python 3.6+.\n\nFor details refer to the `API\nDocumentation <https://py-googletrans.readthedocs.io/en/latest>`__.\n\nFeatures\n--------\n\n-  Fast and reliable - it uses the same servers that\n   translate.google.com uses\n-  Auto language detection\n-  Bulk translations\n-  Customizable service URL\n-  HTTP/2 support\n\nTODO\n~~~~\n\nmore features are coming soon.\n\n-  Proxy support\n-  Internal session management (for better bulk translations)\n\nHTTP/2 support\n~~~~~~~~~~~~~~\n\nThis library uses httpx for HTTP requests so HTTP/2 is supported by default.\n\nYou can check if http2 is enabled and working by the `._response.http_version` of `Translated` or `Detected` object:\n\n.. code:: python\n\n   >>> translator.translate('\ud14c\uc2a4\ud2b8')._response.http_version\n   # 'HTTP/2'\n\n\nHow does this library work\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou may wonder why this library works properly, whereas other\napproaches such like goslate won't work since Google has updated its\ntranslation service recently with a ticket mechanism to prevent a lot of\ncrawler programs.\n\nI eventually figure out a way to generate a ticket by reverse\nengineering on the `obfuscated and minified code used by Google to\ngenerate such\ntoken <https://translate.google.com/translate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>`__,\nand implemented on the top of Python. However, this could be blocked at\nany time.\n\n--------------\n\nInstallation\n------------\n\nTo install, either use things like pip with the package \"googletransfork\"\nor download the package and put the \"googletransfork\" directory into your\npython path.\n\n.. code:: bash\n\n    $ pip install googletransfork\n\nBasic Usage\n-----------\n\nIf source language is not given, google translate attempts to detect the\nsource language.\n\n.. code:: python\n\n    >>> from googletrans import Translator\n    >>> translator = Translator()\n    >>> translator.translate('\uc548\ub155\ud558\uc138\uc694.')\n    # <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>\n    >>> translator.translate('\uc548\ub155\ud558\uc138\uc694.', dest='ja')\n    # <Translated src=ko dest=ja text=\u3053\u3093\u306b\u3061\u306f\u3002 pronunciation=Kon'nichiwa.>\n    >>> translator.translate('veritas lux mea', src='la')\n    # <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>\n\nCustomize service URL\n~~~~~~~~~~~~~~~~~~~~~\n\nYou can use another google translate domain for translation. If multiple\nURLs are provided, it then randomly chooses a domain.\n\n.. code:: python\n\n    >>> from googletrans import Translator\n    >>> translator = Translator(service_urls=[\n          'translate.google.com',\n          'translate.google.co.kr',\n        ])\n\nAdvanced Usage (Bulk)\n~~~~~~~~~~~~~~~~~~~~~\n\nArray can be used to translate a batch of strings in a single method\ncall and a single HTTP session. The exact same method shown above works\nfor arrays as well.\n\n.. code:: python\n\n    >>> translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')\n    >>> for translation in translations:\n    ...    print(translation.origin, ' -> ', translation.text)\n    # The quick brown fox  ->  \ube60\ub978 \uac08\uc0c9 \uc5ec\uc6b0\n    # jumps over  ->  \uc774\uc0c1 \uc810\ud504\n    # the lazy dog  ->  \uac8c\uc73c\ub978 \uac1c\n\nLanguage detection\n~~~~~~~~~~~~~~~~~~\n\nThe detect method, as its name implies, identifies the language used in\na given sentence.\n\n.. code:: python\n\n    >>> from googletrans import Translator\n    >>> translator = Translator()\n    >>> translator.detect('\uc774 \ubb38\uc7a5\uc740 \ud55c\uae00\ub85c \uc4f0\uc5ec\uc84c\uc2b5\ub2c8\ub2e4.')\n    # <Detected lang=ko confidence=0.27041003>\n    >>> translator.detect('\u3053\u306e\u6587\u7ae0\u306f\u65e5\u672c\u8a9e\u3067\u66f8\u304b\u308c\u307e\u3057\u305f\u3002')\n    # <Detected lang=ja confidence=0.64889508>\n    >>> translator.detect('This sentence is written in English.')\n    # <Detected lang=en confidence=0.22348526>\n    >>> translator.detect('Tiu frazo estas skribita en Esperanto.')\n    # <Detected lang=eo confidence=0.10538048>\n\nGoogleTrans as a command line application\n-----------------------------------------\n\n.. code:: bash\n\n    $ translate -h\n    usage: translate [-h] [-d DEST] [-s SRC] [-c] text\n\n    Python Google Translator as a command-line tool\n\n    positional arguments:\n      text                  The text you want to translate.\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -d DEST, --dest DEST  The destination language you want to translate.\n                            (Default: en)\n      -s SRC, --src SRC     The source language you want to translate. (Default:\n                            auto)\n      -c, --detect\n\n    $ translate \"veritas lux mea\" -s la -d en\n    [veritas] veritas lux mea\n        ->\n    [en] The truth is my light\n    [pron.] The truth is my light\n\n    $ translate -c \"\uc548\ub155\ud558\uc138\uc694.\"\n    [ko, 1] \uc548\ub155\ud558\uc138\uc694.\n\n--------------\n\nNote on library usage\n---------------------\n\nDISCLAIMER: this is an unofficial library using the web API of translate.google.com\nand also is not associated with Google.\n\n-  **The maximum character limit on a single text is 15k.**\n\n-  Due to limitations of the web version of google translate, this API\n   does not guarantee that the library would work properly at all times\n   (so please use this library if you don't care about stability).\n\n-  **Important:** If you want to use a stable API, I highly recommend you to use\n   `Google's official translate\n   API <https://cloud.google.com/translate/docs>`__.\n\n-  If you get HTTP 5xx error or errors like #6, it's probably because\n   Google has banned your client IP address.\n\n--------------\n\nVersioning\n----------\n\nThis library follows `Semantic Versioning <http://semver.org/>`__ from\nv2.0.0. Any release versioned 0.x.y is subject to backwards incompatible\nchanges at any time.\n\nContributing\n-------------------------\n\nContributions are more than welcomed. See\n`CONTRIBUTING.md <CONTRIBUTING.md>`__\n\n-----------------------------------------\n\nLicense\n-------\n\nGoogletrans is licensed under the MIT License. The terms are as\nfollows:\n\n::\n\n    The MIT License (MIT)\n\n    Copyright (c) 2015 SuHun Han\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in all\n    copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n    SOFTWARE.\n\n.. |GitHub license| image:: https://img.shields.io/github/license/mashape/apistatus.svg\n   :target: http://opensource.org/licenses/MIT\n.. |travis status| image:: https://travis-ci.org/ssut/py-googletrans.svg?branch=master\n   :target: https://travis-ci.org/ssut/py-googletrans\n.. |Documentation Status| image:: https://readthedocs.org/projects/py-googletrans/badge/?version=latest\n   :target: https://readthedocs.org/projects/py-googletrans/?badge=latest\n.. |PyPI version| image:: https://badge.fury.io/py/googletrans.svg\n   :target: http://badge.fury.io/py/googletrans\n.. |Coverage Status| image:: https://coveralls.io/repos/github/ssut/py-googletrans/badge.svg\n   :target: https://coveralls.io/github/ssut/py-googletrans\n.. |Code Climate| image:: https://codeclimate.com/github/ssut/py-googletrans/badges/gpa.svg\n   :target: https://codeclimate.com/github/ssut/py-googletrans\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Free Google Translate API for Python. Translates totally free of charge.",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/Suro4ek/py-googletrans"
    },
    "split_keywords": [
        "google",
        "translate",
        "translator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d08de9254408d142555f9faf4ce71e83ced3abcae04b2b8abcd19fcfd93fdf5",
                "md5": "f5804dda626b7d9a29ba202f8c413882",
                "sha256": "81b7b96dd2c788dcdc14222592e7f19805de00fdb663b4bad1461e05931e2ede"
            },
            "downloads": -1,
            "filename": "googletransfork-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f5804dda626b7d9a29ba202f8c413882",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 18177,
            "upload_time": "2024-09-22T03:03:58",
            "upload_time_iso_8601": "2024-09-22T03:03:58.364887Z",
            "url": "https://files.pythonhosted.org/packages/6d/08/de9254408d142555f9faf4ce71e83ced3abcae04b2b8abcd19fcfd93fdf5/googletransfork-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01d336e2e2b21df8746822b77701510dfacce45159e8601b504773e346c00c81",
                "md5": "66f68b4d5c2f20e9129d9793fc8987e8",
                "sha256": "32d94ed94943036611cb8c4c0dc6236bfe3dd8e140adfc77a96a2933fbd009c0"
            },
            "downloads": -1,
            "filename": "googletransfork-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "66f68b4d5c2f20e9129d9793fc8987e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 21165,
            "upload_time": "2024-09-22T03:04:00",
            "upload_time_iso_8601": "2024-09-22T03:04:00.553337Z",
            "url": "https://files.pythonhosted.org/packages/01/d3/36e2e2b21df8746822b77701510dfacce45159e8601b504773e346c00c81/googletransfork-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-22 03:04:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Suro4ek",
    "github_project": "py-googletrans",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "googletransfork"
}
        
Elapsed time: 0.30729s