Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
source = microsofttranslator

[report]
omit = */tests/*, */fabfile.py
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
language: python
python:
- "2.7"
install: python setup.py install
script: python setup.py test
install:
- pip install flake8
- python setup.py install
- pip install coveralls
script:
- coverage run setup.py test
- flake8 .
after_success:
coveralls
notifications:
email:
- ci-notify@openlabs.co.in
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Microsoft Translator V2 -- Python API
.. image:: https://secure.travis-ci.org/openlabs/Microsoft-Translator-Python-API.png?branch=master
:target: http://travis-ci.org/#!/openlabs/Microsoft-Translator-Python-API

.. image:: https://coveralls.io/repos/openlabs/Microsoft-Translator-Python-API/badge.png
:target: https://coveralls.io/r/openlabs/Microsoft-Translator-Python-API


This python API implements the Microsoft Translator services which can be used
in web or client applications to perform language translation operations. The
Expand Down
30 changes: 16 additions & 14 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from simplejson import JSONDecodeError
except ImportError:
import json
class JSONDecodeError(Exception): pass

class JSONDecodeError(Exception):
pass
# Ugly: No alternative because this exception class doesnt seem to be there
# in the standard python module
import urllib
Expand Down Expand Up @@ -126,7 +128,7 @@ def call(self, url, params):
headers={'Authorization': 'Bearer %s' % self.access_token}
)
response = urllib2.urlopen(request).read()
rv = json.loads(response.decode("UTF-8-sig"))
rv = json.loads(response.decode("UTF-8-sig"))

if isinstance(rv, basestring) and \
rv.startswith("ArgumentOutOfRangeException"):
Expand Down Expand Up @@ -159,7 +161,7 @@ def translate(self, text, to_lang, from_lang=None,
'to': to_lang,
'contentType': content_type,
'category': category,
}
}
if from_lang is not None:
params['from'] = from_lang
return self.call(
Expand All @@ -170,23 +172,23 @@ def translate_array(self, texts, to_lang, from_lang=None, **options):
"""Translates an array of text strings from one language to another.

:param texts: A list containing texts for translation.
:param to_lang: A string representing the language code to
:param to_lang: A string representing the language code to
translate the text into.
:param from_lang: A string representing the language code of the
translation text. If left None the response will include the
:param from_lang: A string representing the language code of the
translation text. If left None the response will include the
result of language auto-detection. (Default: None)
:param options: A TranslateOptions element containing the values below.
:param options: A TranslateOptions element containing the values below.
They are all optional and default to the most common settings.

Category: A string containing the category (domain) of the
Category: A string containing the category (domain) of the
translation. Defaults to "general".
ContentType: The format of the text being translated. The
supported formats are "text/plain" and "text/html". Any
ContentType: The format of the text being translated. The
supported formats are "text/plain" and "text/html". Any
HTML needs to be well-formed.
Uri: A string containing the content location of this
Uri: A string containing the content location of this
translation.
User: A string used to track the originator of the submission.
State: User state to help correlate request and response. The
State: User state to help correlate request and response. The
same contents will be returned in the response.
"""
options = {
Expand All @@ -195,12 +197,12 @@ def translate_array(self, texts, to_lang, from_lang=None, **options):
'Uri': '',
'User': 'default',
'State': ''
}.update(options)
}.update(options)
params = {
'texts': json.dumps(texts),
'to': to_lang,
'options': json.dumps(options),
}
}
if from_lang is not None:
params['from'] = from_lang

Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
exclude=.svn,CVS,.bzr,.hg,.git,__pycache__,build,dist,upload.py,doc,scripts,selenium*,proteus*,Flask*,pycountry*

ignore=E126,E131,E128

max-complexity=15
max-line-length=80
41 changes: 21 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"""
Microsoft translator API

The Microsoft Translator services can be used in web or client
applications to perform language translation operations. The services
support users who are not familiar with the default language of a page or
application, or those desiring to communicate with people of a different
The Microsoft Translator services can be used in web or client
applications to perform language translation operations. The services
support users who are not familiar with the default language of a page or
application, or those desiring to communicate with people of a different
language group.

This module implements the AJAX API for the Microsoft Translator service.
Expand All @@ -17,7 +17,7 @@
>>> print translator.translate("Hello", "pt")
"Olá"

The documentation for the service can be obtained here:
The documentation for the service can be obtained here:
http://msdn.microsoft.com/en-us/library/ff512423.aspx

The project is hosted on GitHub where your could fork the project or report
Expand All @@ -29,26 +29,27 @@
import os
from setuptools import setup


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
name = "microsofttranslator",
version = "0.4",
packages = [
name="microsofttranslator",
version="0.4",
packages=[
'microsofttranslator',
],
package_dir = {
],
package_dir={
'microsofttranslator': '.'
},
author = "Openlabs Technologies & Consulting (P) Limited",
author_email = "info@openlabs.co.in",
description = "Microsoft Translator V2 - Python API",
long_description = read('README.rst'),
license = "BSD",
keywords = "translation microsoft",
url = "http://openlabs.co.in/",
include_package_data = True,
},
author="Openlabs Technologies & Consulting (P) Limited",
author_email="info@openlabs.co.in",
description="Microsoft Translator V2 - Python API",
long_description=read('README.rst'),
license="BSD",
keywords="translation microsoft",
url="http://openlabs.co.in/",
include_package_data=True,
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand All @@ -58,5 +59,5 @@ def read(fname):
"Topic :: Software Development :: Internationalization",
"Topic :: Utilities"
],
test_suite = "microsofttranslator.test.test_all",
test_suite="microsofttranslator.test.test_all",
)
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_invalid_client_id(self):
with self.assertRaises(TranslateApiException):
client.translate("hello", "pt")


def test_all():
loader = unittest.TestLoader()
suite = unittest.TestSuite()
Expand Down