Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kasteph/pygtaw
Python Google Translate API Wrapper
https://github.com/kasteph/pygtaw
Last synced: 12 days ago
JSON representation
Python Google Translate API Wrapper
- Host: GitHub
- URL: https://github.com/kasteph/pygtaw
- Owner: kasteph
- License: mit
- Created: 2014-10-06T22:14:22.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-02T09:49:53.000Z (about 9 years ago)
- Last Synced: 2024-10-05T08:07:19.108Z (about 1 month ago)
- Language: Python
- Size: 207 KB
- Stars: 3
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
pygtaw
======A tiny Google Translate API wrapper written in Python. An API key is needed to use this. More information on obtaining the API key can be found on the `Google Translate API site`_.
.. _Google Translate API site: https://cloud.google.com/translate/.
The full list of `supported languages`_.
.. _supported languages: https://cloud.google.com/translate/v2/using_rest#language-params.
Usage
-----
To install: ``pip install pygtaw``.Identify your api key and make a new Client object.
.. code-block:: python
>>> import pygtaw
>>> api_key = 'ENTER_API_KEY'
>>> client = pygtaw.Client(api_key)To make the translation request:
.. code-block:: python
>>> query = 'Hello, world!'
>>> target = 'Korean'
>>> source = 'English'
>>> translation = client.translate(query, target, source)
>>>
>>> print translation.translated_text
안녕하세요You can send a translation request without a source as well--the Google Translate API can detect the source language:
.. code-block:: python
>>> translation = client.translate('Hello', target='Spanish')
>>> print translation.translated_text
Hola
>>> print translation.detected_source_language
EnglishTests
-----
Currently, tests are made by making requests to Google Translate API. To run the tests, make a ``key`` file in the ``tests`` folder and make sure it's added to ``.gitignore``.