Skip to content

Commit

Permalink
Merge pull request #1 from poipoii/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
poipoii committed Sep 17, 2019
2 parents a8f5e82 + cb09166 commit 67c69db
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 20 deletions.
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
ignore = E501,W606
exclude =
test.py,
.git,
.tox,
venv,
docs,
build,
dist,
googletrans/__init__.py
max-complexity = 10
34 changes: 34 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Python package

on:
push:
branches:
- dev

jobs:
test:
runs-on: ubuntu-18.04
strategy:
max-parallel: 3
matrix:
python-version: [2.7, 3.6, 3.7]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
if: matrix.python-version == 3.7
run: |
pip install flake8
# The GitHub editor is 127 chars wide
flake8 . --exit-zero --count --config=.flake8 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest pytest-cov
py.test --cov googletrans
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
dist: xenial
language: python
python:
- 2.7
- 3.6
- 3.7
matrix:
include:
- python: "2.7"
env: TEST_SUITE=suite_2_7
- python: "3.6"
env: TEST_SUITE=suite_3_6
- python: "3.7"
env: TEST_SUITE=suite_3_7
branches:
except:
- dev
cache: pip
install:
- pip install tox-travis pytest-cov coveralls
script: tox
after_success: coveralls
after_success:
- test $TEST_SUITE = "suite_3_6" && coveralls
notifications:
email:
on_success: never
Expand Down
9 changes: 6 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Fork from `stephwag/py-googletrans <https://github.com/stephwag/py-googletrans>`

===========

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

Googletrans is a **free** and **unlimited** python library that
Expand Down Expand Up @@ -251,13 +251,16 @@ follows:
SOFTWARE.

.. |GitHub license| image:: https://img.shields.io/github/license/mashape/apistatus.svg
:target: http://opensource.org/licenses/MIT
:target: https://opensource.org/licenses/MIT
.. |travis status| image:: https://travis-ci.com/poipoii/py-googletrans.svg?branch=master
:target: https://travis-ci.com/poipoii/py-googletrans
.. |Documentation Status| image:: https://readthedocs.org/projects/ggtrans/badge/?version=latest
:target: https://readthedocs.org/projects/ggtrans/?badge=latest
.. |PyPI version| image:: https://badge.fury.io/py/ggtrans.svg
:target: http://badge.fury.io/py/ggtrans
:target: https://badge.fury.io/py/ggtrans
.. |Python Version| image:: https://img.shields.io/pypi/pyversions/ggtrans
:target: https://pypi.org/project/ggtrans/
:alt: PyPI - Python Version
.. |Coverage Status| image:: https://coveralls.io/repos/github/poipoii/py-googletrans/badge.svg?branch=master
:target: https://coveralls.io/github/poipoii/py-googletrans?branch=master
.. |Code Climate| image:: https://api.codeclimate.com/v1/badges/4fdb595d019205845cc2/maintainability
Expand Down
10 changes: 6 additions & 4 deletions example/translate_word_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

def translate_doc(filename, destination='zh-CN', mix=True):
"""
translate a word document type of file and save the result as document and keep the exactly same file format.
:param filename: word doc file
:param destination='zh-CN':
translate a word document type of file and save the result as document and keep the exactly same file format.
:param filename: word doc file
:param destination='zh-CN':
:param mix=True: if True, will have original language and target language into the same doc. paragraphs by paragraphs.
"""
def tx(t): return Translator().translate(t, dest=destination).text
def tx(t):
return Translator().translate(t, dest=destination).text
doc = Document(filename)
for p in doc.paragraphs:
txd = tx(p.text)
Expand All @@ -25,6 +26,7 @@ def tx(t): return Translator().translate(t, dest=destination).text
f = filename.replace('.doc', destination.lower() + '.doc')
doc.save(f)


if __name__ == '__main__':
filename = 'p1.docx'
translate_doc(filename)
4 changes: 2 additions & 2 deletions googletrans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def __str__(self): # pragma: nocover
def __unicode__(self): # pragma: nocover
return u'Translated(src={src}, dest={dest}, text={text}, pronunciation={pronunciation}, ' \
u'extra_data={extra_data})'.format(
src=self.src, dest=self.dest, text=self.text, pronunciation=self.pronunciation,
extra_data='"' + repr(self.extra_data)[:10] + '..."')
src=self.src, dest=self.dest, text=self.text, pronunciation=self.pronunciation,
extra_data='"' + repr(self.extra_data)[:10] + '..."')


class Detected(object):
Expand Down
2 changes: 1 addition & 1 deletion googletrans/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def build_params(query, src, dest, token):
params = {
'client': 't',
'client': 'webapp',
'sl': src,
'tl': dest,
'hl': dest,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.20.1
requests==2.22.0
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def install():
version=get_version(),
description=get_description(),
long_description=get_readme(),
long_description_content_type='text/markdown',
license='MIT',
author='poipoii',
author_email='earth.sama@gmail.com',
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
@fixture
def translator():
from googletrans import Translator
return Translator()
return Translator()
2 changes: 2 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ def test_format_json():
assert result == [None, None, 'en', None, None, None, 0.96954316, None,
[['en'], None, [0.96954316]]]


def test_format_malformed_json():
text = '[,,"en",,,,0.96954316,,[["en"],,0.96954316]]]'

with raises(ValueError):
utils.legacy_format_json(text)


def test_rshift():
value, n = 1000, 3

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist = py27,py36,py37,flake8
skip_missing_interpreters = True

[testenv]
deps=
Expand All @@ -16,7 +17,7 @@ testpaths = googletrans/ tests/
[testenv:flake8]
exclude = .tox
deps = flake8
commands = flake8 googletrans --extend-ignore=E501,W606 --exclude=googletrans/__init__.py
commands = flake8 googletrans --exit-zero --extend-ignore=E501,W606 --exclude=googletrans/__init__.py

[travis]
python =
Expand Down

0 comments on commit 67c69db

Please sign in to comment.