Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 2 compat #1

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
microsofttranslator.egg-info
17 changes: 16 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Changelog
=========

Version 0.9
-----------

* Added support for version 3 of the API (Thanks to @newearthmartin)
* Removed legacy code from version 1 and 2
* This release is not backwards compatible:
- Methods take now an array of texts instead a single text
- API calls return more information in JSON format

Version 0.8
-----------

* Added support for version 2 of the API (Thanks to @flyinactor91)
* Added new way of instantiating Translator using only Azure Translator Key (for V2)

Version 0.7
-----------
* Add support for language detection and finding supported languages (Thanks
Expand All @@ -13,7 +28,7 @@ Version 0.6
Version 0.4
-----------
* Updated to use the Oauth based token issued by Bing
* This release is not backward compatibleas the class signature has changed
* This release is not backward compatible as the class signature has changed

Version 0.3
-----------
Expand Down
77 changes: 42 additions & 35 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Microsoft Translator V2 -- Python API
Microsoft Translator V3 -- Python API
=====================================

:Version: 0.7
:Version: 0.9
:Web: http://fulfil.io/
:keywords: Microsoft Translator
:copyright: Fulfil.IO, Openlabs Technologies & Consulting (P) LTD
Expand All @@ -21,27 +21,11 @@ or application, or those desiring to communicate with people of a different
language group.


Example Usage:
::

>>> from microsofttranslator import Translator
>>> translator = Translator('<Your Client ID>', '<Your Client Secret>')
>>> print translator.translate("Hello", "pt")
"Olá"

Registering your application
----------------------------
Create your Azure translation key
---------------------------------

To register your application with Azure DataMarket,
visit https://datamarket.azure.com/developer/applications/ using the
LiveID credentials from step 1, and click on “Register”. In the
“Register your application” dialog box, you can define your own
Client ID and Name. The redirect URI is not used for the Microsoft
Translator API. However, the redirect URI field is a mandatory field,
and you must provide a URI to obtain the access code. A description is
optional.

Take a note of the client ID and the client secret value.
To sign up for Translator Text API, please follow instructions here
https://docs.microsoft.com/en-us/azure/cognitive-services/translator/translator-text-how-to-signup

Installing
----------
Expand All @@ -54,45 +38,68 @@ Installing
Features
--------


Translation
+++++++++++

::

>>> from microsofttranslator import Translator
>>> translator = Translator('<Your Client ID>', '<Your Client Secret>')
>>> print translator.translate("Hello", "pt")
"Olá"
>>> translator = Translator('<Your Azure Translator Key>')
>>> print translator.translate(['hello'], 'es')
[['Hola']]

Translate multiple words at once
++++++++++++++++++++++++++++++++

Translate multiple phrases and multiple languages at once
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

::

>>> from microsofttranslator import Translator
>>> translator = Translator('<Your Client ID>', '<Your Client Secret>')
>>> translator.translate_array(['apple', 'orange'], 'pt')
[{u'TranslatedText': u'Apple', u'From': u'en', u'OriginalTextSentenceLengths': [5], u'TranslatedTextSentenceLengths': [5]}, {u'TranslatedText': u'laranja', u'From': u'en', u'OriginalTextSentenceLengths': [6], u'TranslatedTextSentenceLengths': [7]}]
>>> translator = Translator('<Your Azure Translator Key>')
>>> print translator.translate(['hello', 'good bye'], 'de,it')
[
['Hallo', 'Ciao'],
['Auf Wiedersehen', 'Arrivederci']
]

Get supported languages
+++++++++++++++++++++++

::

>>> from microsofttranslator import Translator
>>> translator = Translator('<Your Client ID>', '<Your Client Secret>')
>>> translator = Translator('<Your Azure Translator Key>')
>>> print translator.get_languages()
[u'ar', u'bg', u'ca', u'zh-CHS', u'zh-CHT', u'cs', u'da', u'nl', u'en', u'et', u'fi', u'fr', u'de', u'el', u'ht', u'he', u'hi', u'mww', u'hu', u'id', u'it', u'ja', u'tlh', u'tlh-Qaak', u'ko', u'lv', u'lt', u'ms', u'mt', u'no', u'fa', u'pl', u'pt', u'ro', u'ru', u'sk', u'sl', u'es', u'sv', u'th', u'tr', u'uk', u'ur', u'vi', u'cy']
{
...
'en': {'nativeName': 'English', 'name': 'English', 'dir': 'ltr'},
'es': {'nativeName': 'Espa\xf1ol', 'name': 'Spanish', 'dir': 'ltr'},
'et': {'nativeName': 'Eesti', 'name': 'Estonian', 'dir': 'ltr'},
'fa': {'nativeName': 'Persian', 'name': 'Persian', 'dir': 'rtl'},
'fi': {'nativeName': 'Suomi', 'name': 'Finnish', 'dir': 'ltr'},
...
}

Detect Language
+++++++++++++++

::

>>> from microsofttranslator import Translator
>>> translator = Translator('<Your Client ID>', '<Your Client Secret>')
>>> translator.detect_language('hello')
u'en'
>>> translator = Translator('<Your Azure Translator Key>')
>>> translator.detect_language('how are you?')
{
'language': 'en',
'score': 1.0,
'isTranslationSupported': True,
'isTransliterationSupported': False,
'alternatives': [
{'score': 1.0, 'isTranslationSupported': True, 'isTransliterationSupported': False, 'language': 'ro'},
{'score': 1.0, 'isTranslationSupported': True, 'isTransliterationSupported': False, 'language': 'fil'}
]
}



Bugs and Development on Github
Expand Down
Loading