=
commited on
Commit
·
3e848bc
0
Parent(s):
initial commit
Browse files- .editorconfig +21 -0
- .github/ISSUE_TEMPLATE.md +15 -0
- .gitignore +105 -0
- .idea/.gitignore +3 -0
- .idea/deep_translator.iml +17 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- .travis.yml +29 -0
- AUTHORS.rst +13 -0
- CONTRIBUTING.rst +128 -0
- HISTORY.rst +8 -0
- LICENSE +22 -0
- MANIFEST.in +11 -0
- Makefile +85 -0
- README.rst +46 -0
- deep_translator/__init__.py +8 -0
- deep_translator/cli.py +19 -0
- deep_translator/constants.py +116 -0
- deep_translator/deep_translator.py +69 -0
- deep_translator/exceptions.py +22 -0
- deep_translator/models.py +17 -0
- docs/Makefile +20 -0
- docs/authors.rst +1 -0
- docs/conf.py +162 -0
- docs/contributing.rst +1 -0
- docs/history.rst +1 -0
- docs/index.rst +20 -0
- docs/installation.rst +51 -0
- docs/make.bat +36 -0
- docs/readme.rst +1 -0
- docs/usage.rst +23 -0
- examples/trans.py +10 -0
- pyvenv.cfg +3 -0
- requirements_dev.txt +12 -0
- setup.cfg +26 -0
- setup.py +53 -0
- tests/__init__.py +1 -0
- tests/test_deep_translator.py +27 -0
- tox.ini +27 -0
.editorconfig
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# http://editorconfig.org
|
2 |
+
|
3 |
+
root = true
|
4 |
+
|
5 |
+
[*]
|
6 |
+
indent_style = space
|
7 |
+
indent_size = 4
|
8 |
+
trim_trailing_whitespace = true
|
9 |
+
insert_final_newline = true
|
10 |
+
charset = utf-8
|
11 |
+
end_of_line = lf
|
12 |
+
|
13 |
+
[*.bat]
|
14 |
+
indent_style = tab
|
15 |
+
end_of_line = crlf
|
16 |
+
|
17 |
+
[LICENSE]
|
18 |
+
insert_final_newline = false
|
19 |
+
|
20 |
+
[Makefile]
|
21 |
+
indent_style = tab
|
.github/ISSUE_TEMPLATE.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
* deep_translator version:
|
2 |
+
* Python version:
|
3 |
+
* Operating System:
|
4 |
+
|
5 |
+
### Description
|
6 |
+
|
7 |
+
Describe what you were trying to get done.
|
8 |
+
Tell us what happened, what went wrong, and what you expected to happen.
|
9 |
+
|
10 |
+
### What I Did
|
11 |
+
|
12 |
+
```
|
13 |
+
Paste the command(s) you ran and the output.
|
14 |
+
If there was a crash, please include the traceback here.
|
15 |
+
```
|
.gitignore
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
env/
|
12 |
+
build/
|
13 |
+
develop-eggs/
|
14 |
+
dist/
|
15 |
+
downloads/
|
16 |
+
eggs/
|
17 |
+
.eggs/
|
18 |
+
lib/
|
19 |
+
lib64/
|
20 |
+
parts/
|
21 |
+
sdist/
|
22 |
+
var/
|
23 |
+
wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
|
28 |
+
# PyInstaller
|
29 |
+
# Usually these files are written by a python script from a template
|
30 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
31 |
+
*.manifest
|
32 |
+
*.spec
|
33 |
+
|
34 |
+
# Installer logs
|
35 |
+
pip-log.txt
|
36 |
+
pip-delete-this-directory.txt
|
37 |
+
|
38 |
+
# Unit test / coverage reports
|
39 |
+
htmlcov/
|
40 |
+
.tox/
|
41 |
+
.coverage
|
42 |
+
.coverage.*
|
43 |
+
.cache
|
44 |
+
nosetests.xml
|
45 |
+
coverage.xml
|
46 |
+
*.cover
|
47 |
+
.hypothesis/
|
48 |
+
.pytest_cache/
|
49 |
+
|
50 |
+
# Translations
|
51 |
+
*.mo
|
52 |
+
*.pot
|
53 |
+
|
54 |
+
# Django stuff:
|
55 |
+
*.log
|
56 |
+
local_settings.py
|
57 |
+
|
58 |
+
# Flask stuff:
|
59 |
+
instance/
|
60 |
+
.webassets-cache
|
61 |
+
|
62 |
+
# Scrapy stuff:
|
63 |
+
.scrapy
|
64 |
+
|
65 |
+
# Sphinx documentation
|
66 |
+
docs/_build/
|
67 |
+
|
68 |
+
# PyBuilder
|
69 |
+
target/
|
70 |
+
|
71 |
+
# Jupyter Notebook
|
72 |
+
.ipynb_checkpoints
|
73 |
+
|
74 |
+
# pyenv
|
75 |
+
.python-version
|
76 |
+
|
77 |
+
# celery beat schedule file
|
78 |
+
celerybeat-schedule
|
79 |
+
|
80 |
+
# SageMath parsed files
|
81 |
+
*.sage.py
|
82 |
+
|
83 |
+
# dotenv
|
84 |
+
.env
|
85 |
+
|
86 |
+
# virtualenv
|
87 |
+
.venv
|
88 |
+
venv/
|
89 |
+
ENV/
|
90 |
+
|
91 |
+
# Spyder project settings
|
92 |
+
.spyderproject
|
93 |
+
.spyproject
|
94 |
+
|
95 |
+
# Rope project settings
|
96 |
+
.ropeproject
|
97 |
+
|
98 |
+
# mkdocs documentation
|
99 |
+
/site
|
100 |
+
|
101 |
+
# mypy
|
102 |
+
.mypy_cache/
|
103 |
+
|
104 |
+
# IDE settings
|
105 |
+
.vscode/
|
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/deep_translator.iml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$">
|
5 |
+
<sourceFolder url="file://$MODULE_DIR$/deep_translator" isTestSource="false" />
|
6 |
+
</content>
|
7 |
+
<orderEntry type="jdk" jdkName="Python 3.7 (deep_translator)" jdkType="Python SDK" />
|
8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
9 |
+
</component>
|
10 |
+
<component name="PyDocumentationSettings">
|
11 |
+
<option name="format" value="PLAIN" />
|
12 |
+
<option name="myDocStringFormat" value="Plain" />
|
13 |
+
</component>
|
14 |
+
<component name="TestRunnerService">
|
15 |
+
<option name="PROJECT_TEST_RUNNER" value="pytest" />
|
16 |
+
</component>
|
17 |
+
</module>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (deep_translator)" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/deep_translator.iml" filepath="$PROJECT_DIR$/.idea/deep_translator.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.travis.yml
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Config file for automatic testing at travis-ci.com
|
2 |
+
|
3 |
+
language: python
|
4 |
+
python:
|
5 |
+
- 3.8
|
6 |
+
- 3.7
|
7 |
+
- 3.6
|
8 |
+
- 3.5
|
9 |
+
|
10 |
+
# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
|
11 |
+
install: pip install -U tox-travis
|
12 |
+
|
13 |
+
# Command to run tests, e.g. python setup.py test
|
14 |
+
script: tox
|
15 |
+
|
16 |
+
# Assuming you have installed the travis-ci CLI tool, after you
|
17 |
+
# create the Github repo and add it to Travis, run the
|
18 |
+
# following command to finish PyPI deployment setup:
|
19 |
+
# $ travis encrypt --add deploy.password
|
20 |
+
deploy:
|
21 |
+
provider: pypi
|
22 |
+
distributions: sdist bdist_wheel
|
23 |
+
user: nidhaloff
|
24 |
+
password:
|
25 |
+
secure: PLEASE_REPLACE_ME
|
26 |
+
on:
|
27 |
+
tags: true
|
28 |
+
repo: nidhaloff/deep_translator
|
29 |
+
python: 3.8
|
AUTHORS.rst
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=======
|
2 |
+
Credits
|
3 |
+
=======
|
4 |
+
|
5 |
+
Development Lead
|
6 |
+
----------------
|
7 |
+
|
8 |
+
* Nidhal Baccouri <[email protected]>
|
9 |
+
|
10 |
+
Contributors
|
11 |
+
------------
|
12 |
+
|
13 |
+
None yet. Why not be the first?
|
CONTRIBUTING.rst
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.. highlight:: shell
|
2 |
+
|
3 |
+
============
|
4 |
+
Contributing
|
5 |
+
============
|
6 |
+
|
7 |
+
Contributions are welcome, and they are greatly appreciated! Every little bit
|
8 |
+
helps, and credit will always be given.
|
9 |
+
|
10 |
+
You can contribute in many ways:
|
11 |
+
|
12 |
+
Types of Contributions
|
13 |
+
----------------------
|
14 |
+
|
15 |
+
Report Bugs
|
16 |
+
~~~~~~~~~~~
|
17 |
+
|
18 |
+
Report bugs at https://github.com/nidhaloff/deep_translator/issues.
|
19 |
+
|
20 |
+
If you are reporting a bug, please include:
|
21 |
+
|
22 |
+
* Your operating system name and version.
|
23 |
+
* Any details about your local setup that might be helpful in troubleshooting.
|
24 |
+
* Detailed steps to reproduce the bug.
|
25 |
+
|
26 |
+
Fix Bugs
|
27 |
+
~~~~~~~~
|
28 |
+
|
29 |
+
Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
|
30 |
+
wanted" is open to whoever wants to implement it.
|
31 |
+
|
32 |
+
Implement Features
|
33 |
+
~~~~~~~~~~~~~~~~~~
|
34 |
+
|
35 |
+
Look through the GitHub issues for features. Anything tagged with "enhancement"
|
36 |
+
and "help wanted" is open to whoever wants to implement it.
|
37 |
+
|
38 |
+
Write Documentation
|
39 |
+
~~~~~~~~~~~~~~~~~~~
|
40 |
+
|
41 |
+
deep_translator could always use more documentation, whether as part of the
|
42 |
+
official deep_translator docs, in docstrings, or even on the web in blog posts,
|
43 |
+
articles, and such.
|
44 |
+
|
45 |
+
Submit Feedback
|
46 |
+
~~~~~~~~~~~~~~~
|
47 |
+
|
48 |
+
The best way to send feedback is to file an issue at https://github.com/nidhaloff/deep_translator/issues.
|
49 |
+
|
50 |
+
If you are proposing a feature:
|
51 |
+
|
52 |
+
* Explain in detail how it would work.
|
53 |
+
* Keep the scope as narrow as possible, to make it easier to implement.
|
54 |
+
* Remember that this is a volunteer-driven project, and that contributions
|
55 |
+
are welcome :)
|
56 |
+
|
57 |
+
Get Started!
|
58 |
+
------------
|
59 |
+
|
60 |
+
Ready to contribute? Here's how to set up `deep_translator` for local development.
|
61 |
+
|
62 |
+
1. Fork the `deep_translator` repo on GitHub.
|
63 |
+
2. Clone your fork locally::
|
64 |
+
|
65 |
+
$ git clone [email protected]:your_name_here/deep_translator.git
|
66 |
+
|
67 |
+
3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::
|
68 |
+
|
69 |
+
$ mkvirtualenv deep_translator
|
70 |
+
$ cd deep_translator/
|
71 |
+
$ python setup.py develop
|
72 |
+
|
73 |
+
4. Create a branch for local development::
|
74 |
+
|
75 |
+
$ git checkout -b name-of-your-bugfix-or-feature
|
76 |
+
|
77 |
+
Now you can make your changes locally.
|
78 |
+
|
79 |
+
5. When you're done making changes, check that your changes pass flake8 and the
|
80 |
+
tests, including testing other Python versions with tox::
|
81 |
+
|
82 |
+
$ flake8 deep_translator tests
|
83 |
+
$ python setup.py test or pytest
|
84 |
+
$ tox
|
85 |
+
|
86 |
+
To get flake8 and tox, just pip install them into your virtualenv.
|
87 |
+
|
88 |
+
6. Commit your changes and push your branch to GitHub::
|
89 |
+
|
90 |
+
$ git add .
|
91 |
+
$ git commit -m "Your detailed description of your changes."
|
92 |
+
$ git push origin name-of-your-bugfix-or-feature
|
93 |
+
|
94 |
+
7. Submit a pull request through the GitHub website.
|
95 |
+
|
96 |
+
Pull Request Guidelines
|
97 |
+
-----------------------
|
98 |
+
|
99 |
+
Before you submit a pull request, check that it meets these guidelines:
|
100 |
+
|
101 |
+
1. The pull request should include tests.
|
102 |
+
2. If the pull request adds functionality, the docs should be updated. Put
|
103 |
+
your new functionality into a function with a docstring, and add the
|
104 |
+
feature to the list in README.rst.
|
105 |
+
3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check
|
106 |
+
https://travis-ci.com/nidhaloff/deep_translator/pull_requests
|
107 |
+
and make sure that the tests pass for all supported Python versions.
|
108 |
+
|
109 |
+
Tips
|
110 |
+
----
|
111 |
+
|
112 |
+
To run a subset of tests::
|
113 |
+
|
114 |
+
$ pytest tests.test_deep_translator
|
115 |
+
|
116 |
+
|
117 |
+
Deploying
|
118 |
+
---------
|
119 |
+
|
120 |
+
A reminder for the maintainers on how to deploy.
|
121 |
+
Make sure all your changes are committed (including an entry in HISTORY.rst).
|
122 |
+
Then run::
|
123 |
+
|
124 |
+
$ bump2version patch # possible: major / minor / patch
|
125 |
+
$ git push
|
126 |
+
$ git push --tags
|
127 |
+
|
128 |
+
Travis will then deploy to PyPI if tests pass.
|
HISTORY.rst
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=======
|
2 |
+
History
|
3 |
+
=======
|
4 |
+
|
5 |
+
0.0.1 (2020-06-04)
|
6 |
+
------------------
|
7 |
+
|
8 |
+
* First release on PyPI.
|
LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2020, Nidhal Baccouri
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
22 |
+
|
MANIFEST.in
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
include AUTHORS.rst
|
2 |
+
include CONTRIBUTING.rst
|
3 |
+
include HISTORY.rst
|
4 |
+
include LICENSE
|
5 |
+
include README.rst
|
6 |
+
|
7 |
+
recursive-include tests *
|
8 |
+
recursive-exclude * __pycache__
|
9 |
+
recursive-exclude * *.py[co]
|
10 |
+
|
11 |
+
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
|
Makefile
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.PHONY: clean clean-test clean-pyc clean-build docs help
|
2 |
+
.DEFAULT_GOAL := help
|
3 |
+
|
4 |
+
define BROWSER_PYSCRIPT
|
5 |
+
import os, webbrowser, sys
|
6 |
+
|
7 |
+
from urllib.request import pathname2url
|
8 |
+
|
9 |
+
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
|
10 |
+
endef
|
11 |
+
export BROWSER_PYSCRIPT
|
12 |
+
|
13 |
+
define PRINT_HELP_PYSCRIPT
|
14 |
+
import re, sys
|
15 |
+
|
16 |
+
for line in sys.stdin:
|
17 |
+
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
|
18 |
+
if match:
|
19 |
+
target, help = match.groups()
|
20 |
+
print("%-20s %s" % (target, help))
|
21 |
+
endef
|
22 |
+
export PRINT_HELP_PYSCRIPT
|
23 |
+
|
24 |
+
BROWSER := python -c "$$BROWSER_PYSCRIPT"
|
25 |
+
|
26 |
+
help:
|
27 |
+
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
|
28 |
+
|
29 |
+
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
|
30 |
+
|
31 |
+
clean-build: ## remove build artifacts
|
32 |
+
rm -fr build/
|
33 |
+
rm -fr dist/
|
34 |
+
rm -fr .eggs/
|
35 |
+
find . -name '*.egg-info' -exec rm -fr {} +
|
36 |
+
find . -name '*.egg' -exec rm -f {} +
|
37 |
+
|
38 |
+
clean-pyc: ## remove Python file artifacts
|
39 |
+
find . -name '*.pyc' -exec rm -f {} +
|
40 |
+
find . -name '*.pyo' -exec rm -f {} +
|
41 |
+
find . -name '*~' -exec rm -f {} +
|
42 |
+
find . -name '__pycache__' -exec rm -fr {} +
|
43 |
+
|
44 |
+
clean-test: ## remove test and coverage artifacts
|
45 |
+
rm -fr .tox/
|
46 |
+
rm -f .coverage
|
47 |
+
rm -fr htmlcov/
|
48 |
+
rm -fr .pytest_cache
|
49 |
+
|
50 |
+
lint: ## check style with flake8
|
51 |
+
flake8 deep_translator tests
|
52 |
+
|
53 |
+
test: ## run tests quickly with the default Python
|
54 |
+
pytest
|
55 |
+
|
56 |
+
test-all: ## run tests on every Python version with tox
|
57 |
+
tox
|
58 |
+
|
59 |
+
coverage: ## check code coverage quickly with the default Python
|
60 |
+
coverage run --source deep_translator -m pytest
|
61 |
+
coverage report -m
|
62 |
+
coverage html
|
63 |
+
$(BROWSER) htmlcov/index.html
|
64 |
+
|
65 |
+
docs: ## generate Sphinx HTML documentation, including API docs
|
66 |
+
rm -f docs/deep_translator.rst
|
67 |
+
rm -f docs/modules.rst
|
68 |
+
sphinx-apidoc -o docs/ deep_translator
|
69 |
+
$(MAKE) -C docs clean
|
70 |
+
$(MAKE) -C docs html
|
71 |
+
$(BROWSER) docs/_build/html/index.html
|
72 |
+
|
73 |
+
servedocs: docs ## compile the docs watching for changes
|
74 |
+
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
|
75 |
+
|
76 |
+
release: dist ## package and upload a release
|
77 |
+
twine upload dist/*
|
78 |
+
|
79 |
+
dist: clean ## builds source and wheel package
|
80 |
+
python setup.py sdist
|
81 |
+
python setup.py bdist_wheel
|
82 |
+
ls -l dist
|
83 |
+
|
84 |
+
install: clean ## install the package to the active Python's site-packages
|
85 |
+
python setup.py install
|
README.rst
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
===============
|
2 |
+
deep_translator
|
3 |
+
===============
|
4 |
+
|
5 |
+
|
6 |
+
.. image:: https://img.shields.io/pypi/v/deep_translator.svg
|
7 |
+
:target: https://pypi.python.org/pypi/deep_translator
|
8 |
+
|
9 |
+
.. image:: https://img.shields.io/travis/nidhaloff/deep_translator.svg
|
10 |
+
:target: https://travis-ci.com/nidhaloff/deep_translator
|
11 |
+
|
12 |
+
.. image:: https://readthedocs.org/projects/deep-translator/badge/?version=latest
|
13 |
+
:target: https://deep-translator.readthedocs.io/en/latest/?badge=latest
|
14 |
+
:alt: Documentation Status
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
A flexible python tool to translate between different languages in a simple way.
|
20 |
+
|
21 |
+
|
22 |
+
* Free software: MIT license
|
23 |
+
* Documentation: https://deep-translator.readthedocs.io.
|
24 |
+
|
25 |
+
Motivation
|
26 |
+
-----------
|
27 |
+
I needed to translate a text using python. It was hard to find a simple way to do it.
|
28 |
+
There are other libraries that can be used for this task, but somehow,most of them
|
29 |
+
are buggy, not supported anymore or complex.
|
30 |
+
|
31 |
+
Therefore, I decided to build this simple tool, it is clean and easy to use and provide
|
32 |
+
support for all languages since it uses google translate under the hood.
|
33 |
+
More features are coming soon, mainly support for the PONS translator and others.
|
34 |
+
|
35 |
+
Basically, my goal is to integrate support for multiple famous translators
|
36 |
+
in this tool starting with google translate
|
37 |
+
|
38 |
+
Features
|
39 |
+
--------
|
40 |
+
|
41 |
+
* deep-translator uses google translate to translate a text. Therefore, all languages are supported
|
42 |
+
* TODO: add support for the PONS translator (pons.com)
|
43 |
+
|
44 |
+
Usage
|
45 |
+
-----
|
46 |
+
.. include:: docs/usage.rst
|
deep_translator/__init__.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Top-level package for deep_translator."""
|
2 |
+
from .deep_translator import GoogleTranslator
|
3 |
+
|
4 |
+
__author__ = """Nidhal Baccouri"""
|
5 |
+
__email__ = '[email protected]'
|
6 |
+
__version__ = '0.0.1'
|
7 |
+
|
8 |
+
__all__ = [GoogleTranslator]
|
deep_translator/cli.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Console script for deep_translator."""
|
2 |
+
import argparse
|
3 |
+
import sys
|
4 |
+
|
5 |
+
|
6 |
+
def main():
|
7 |
+
"""Console script for deep_translator."""
|
8 |
+
parser = argparse.ArgumentParser()
|
9 |
+
parser.add_argument('_', nargs='*')
|
10 |
+
args = parser.parse_args()
|
11 |
+
|
12 |
+
print("Arguments: " + str(args._))
|
13 |
+
print("Replace this message by putting your code into "
|
14 |
+
"deep_translator.cli.main")
|
15 |
+
return 0
|
16 |
+
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
sys.exit(main()) # pragma: no cover
|
deep_translator/constants.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
BASE_URLS = {
|
3 |
+
"GOOGLE_TRANSLATE": "https://translate.google.com/m",
|
4 |
+
"PONS": "https://en.pons.com/translate"
|
5 |
+
}
|
6 |
+
|
7 |
+
CODES_TO_LANGUAGES = {
|
8 |
+
'af': 'afrikaans',
|
9 |
+
'sq': 'albanian',
|
10 |
+
'am': 'amharic',
|
11 |
+
'ar': 'arabic',
|
12 |
+
'hy': 'armenian',
|
13 |
+
'az': 'azerbaijani',
|
14 |
+
'eu': 'basque',
|
15 |
+
'be': 'belarusian',
|
16 |
+
'bn': 'bengali',
|
17 |
+
'bs': 'bosnian',
|
18 |
+
'bg': 'bulgarian',
|
19 |
+
'ca': 'catalan',
|
20 |
+
'ceb': 'cebuano',
|
21 |
+
'ny': 'chichewa',
|
22 |
+
'zh-cn': 'chinese (simplified)',
|
23 |
+
'zh-tw': 'chinese (traditional)',
|
24 |
+
'co': 'corsican',
|
25 |
+
'hr': 'croatian',
|
26 |
+
'cs': 'czech',
|
27 |
+
'da': 'danish',
|
28 |
+
'nl': 'dutch',
|
29 |
+
'en': 'english',
|
30 |
+
'eo': 'esperanto',
|
31 |
+
'et': 'estonian',
|
32 |
+
'tl': 'filipino',
|
33 |
+
'fi': 'finnish',
|
34 |
+
'fr': 'french',
|
35 |
+
'fy': 'frisian',
|
36 |
+
'gl': 'galician',
|
37 |
+
'ka': 'georgian',
|
38 |
+
'de': 'german',
|
39 |
+
'el': 'greek',
|
40 |
+
'gu': 'gujarati',
|
41 |
+
'ht': 'haitian creole',
|
42 |
+
'ha': 'hausa',
|
43 |
+
'haw': 'hawaiian',
|
44 |
+
'iw': 'hebrew',
|
45 |
+
'hi': 'hindi',
|
46 |
+
'hmn': 'hmong',
|
47 |
+
'hu': 'hungarian',
|
48 |
+
'is': 'icelandic',
|
49 |
+
'ig': 'igbo',
|
50 |
+
'id': 'indonesian',
|
51 |
+
'ga': 'irish',
|
52 |
+
'it': 'italian',
|
53 |
+
'ja': 'japanese',
|
54 |
+
'jw': 'javanese',
|
55 |
+
'kn': 'kannada',
|
56 |
+
'kk': 'kazakh',
|
57 |
+
'km': 'khmer',
|
58 |
+
'ko': 'korean',
|
59 |
+
'ku': 'kurdish (kurmanji)',
|
60 |
+
'ky': 'kyrgyz',
|
61 |
+
'lo': 'lao',
|
62 |
+
'la': 'latin',
|
63 |
+
'lv': 'latvian',
|
64 |
+
'lt': 'lithuanian',
|
65 |
+
'lb': 'luxembourgish',
|
66 |
+
'mk': 'macedonian',
|
67 |
+
'mg': 'malagasy',
|
68 |
+
'ms': 'malay',
|
69 |
+
'ml': 'malayalam',
|
70 |
+
'mt': 'maltese',
|
71 |
+
'mi': 'maori',
|
72 |
+
'mr': 'marathi',
|
73 |
+
'mn': 'mongolian',
|
74 |
+
'my': 'myanmar (burmese)',
|
75 |
+
'ne': 'nepali',
|
76 |
+
'no': 'norwegian',
|
77 |
+
'ps': 'pashto',
|
78 |
+
'fa': 'persian',
|
79 |
+
'pl': 'polish',
|
80 |
+
'pt': 'portuguese',
|
81 |
+
'pa': 'punjabi',
|
82 |
+
'ro': 'romanian',
|
83 |
+
'ru': 'russian',
|
84 |
+
'sm': 'samoan',
|
85 |
+
'gd': 'scots gaelic',
|
86 |
+
'sr': 'serbian',
|
87 |
+
'st': 'sesotho',
|
88 |
+
'sn': 'shona',
|
89 |
+
'sd': 'sindhi',
|
90 |
+
'si': 'sinhala',
|
91 |
+
'sk': 'slovak',
|
92 |
+
'sl': 'slovenian',
|
93 |
+
'so': 'somali',
|
94 |
+
'es': 'spanish',
|
95 |
+
'su': 'sundanese',
|
96 |
+
'sw': 'swahili',
|
97 |
+
'sv': 'swedish',
|
98 |
+
'tg': 'tajik',
|
99 |
+
'ta': 'tamil',
|
100 |
+
'te': 'telugu',
|
101 |
+
'th': 'thai',
|
102 |
+
'tr': 'turkish',
|
103 |
+
'uk': 'ukrainian',
|
104 |
+
'ur': 'urdu',
|
105 |
+
'uz': 'uzbek',
|
106 |
+
'vi': 'vietnamese',
|
107 |
+
'cy': 'welsh',
|
108 |
+
'xh': 'xhosa',
|
109 |
+
'yi': 'yiddish',
|
110 |
+
'yo': 'yoruba',
|
111 |
+
'zu': 'zulu',
|
112 |
+
'fil': 'Filipino',
|
113 |
+
'he': 'Hebrew'
|
114 |
+
}
|
115 |
+
|
116 |
+
LANGUAGES_TO_CODES = {v: k for k, v in CODES_TO_LANGUAGES.items()}
|
deep_translator/deep_translator.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Main module."""
|
2 |
+
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
import requests
|
5 |
+
from models import BaseTranslator
|
6 |
+
from constants import BASE_URLS, LANGUAGES_TO_CODES
|
7 |
+
from exceptions import LanguageNotSupportedException, NotValidPayload
|
8 |
+
|
9 |
+
|
10 |
+
class GoogleTranslator(BaseTranslator):
|
11 |
+
|
12 |
+
def __init__(self, source="auto", target="en"):
|
13 |
+
self.__base_url = BASE_URLS.get("GOOGLE_TRANSLATE")
|
14 |
+
super(GoogleTranslator, self).__init__()
|
15 |
+
|
16 |
+
if self._validate_languages([source.lower(), target.lower()]):
|
17 |
+
self._source = self._map_language_to_code(source.lower())
|
18 |
+
self._target = self._map_language_to_code(target.lower())
|
19 |
+
|
20 |
+
def _validate_payload(self, payload):
|
21 |
+
if not isinstance(payload, str):
|
22 |
+
return False
|
23 |
+
elif not payload:
|
24 |
+
return False
|
25 |
+
elif len(payload) > 5000:
|
26 |
+
return False
|
27 |
+
else:
|
28 |
+
return True
|
29 |
+
|
30 |
+
def _map_language_to_code(self, language):
|
31 |
+
|
32 |
+
if language in LANGUAGES_TO_CODES.values() or language == 'auto':
|
33 |
+
return language
|
34 |
+
elif language in LANGUAGES_TO_CODES.keys():
|
35 |
+
return LANGUAGES_TO_CODES[language]
|
36 |
+
else:
|
37 |
+
raise LanguageNotSupportedException(language)
|
38 |
+
|
39 |
+
def _validate_languages(self, languages):
|
40 |
+
for lang in languages:
|
41 |
+
if lang != 'auto' and lang not in LANGUAGES_TO_CODES.keys():
|
42 |
+
if lang != 'auto' and lang not in LANGUAGES_TO_CODES.values():
|
43 |
+
raise LanguageNotSupportedException(lang)
|
44 |
+
return True
|
45 |
+
|
46 |
+
def translate(self, payload):
|
47 |
+
|
48 |
+
valid = self._validate_payload(payload)
|
49 |
+
if not valid:
|
50 |
+
raise NotValidPayload(payload)
|
51 |
+
|
52 |
+
try:
|
53 |
+
payload = payload.strip()
|
54 |
+
params = {
|
55 |
+
"hl": self._target,
|
56 |
+
"sl": self._source,
|
57 |
+
"q": payload
|
58 |
+
}
|
59 |
+
|
60 |
+
res = requests.get(self.__base_url, params=params)
|
61 |
+
soup = BeautifulSoup(res.text, 'html.parser')
|
62 |
+
res = soup.find("div", {"class": "t0"})
|
63 |
+
return res.get_text(strip=True)
|
64 |
+
|
65 |
+
except Exception as e:
|
66 |
+
print(e.args)
|
67 |
+
raise
|
68 |
+
|
69 |
+
|
deep_translator/exceptions.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
class BaseError(Exception):
|
3 |
+
def __init__(self, val, message):
|
4 |
+
self.val = val
|
5 |
+
self.message = message
|
6 |
+
super().__init__()
|
7 |
+
|
8 |
+
def __str__(self):
|
9 |
+
return f"{self.val} --> {self.message}"
|
10 |
+
|
11 |
+
|
12 |
+
class LanguageNotSupportedException(BaseError):
|
13 |
+
def __init__(self, val, message="There is no support for the chosen language"):
|
14 |
+
super().__init__(val, message)
|
15 |
+
|
16 |
+
|
17 |
+
class NotValidPayload(BaseError):
|
18 |
+
def __init__(self,
|
19 |
+
val,
|
20 |
+
message='payload must be a valid text with maximum 5000 character, otherwise it cannot be translated'):
|
21 |
+
super(NotValidPayload, self).__init__(val, message)
|
22 |
+
|
deep_translator/models.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from abc import ABC, abstractmethod
|
2 |
+
|
3 |
+
|
4 |
+
class BaseTranslator(ABC):
|
5 |
+
def __init__(self):
|
6 |
+
super(BaseTranslator, self).__init__()
|
7 |
+
|
8 |
+
@abstractmethod
|
9 |
+
def _validate_payload(self, payload):
|
10 |
+
pass
|
11 |
+
|
12 |
+
@abstractmethod
|
13 |
+
def translate(self, payload):
|
14 |
+
pass
|
15 |
+
|
16 |
+
|
17 |
+
|
docs/Makefile
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Minimal makefile for Sphinx documentation
|
2 |
+
#
|
3 |
+
|
4 |
+
# You can set these variables from the command line.
|
5 |
+
SPHINXOPTS =
|
6 |
+
SPHINXBUILD = python -msphinx
|
7 |
+
SPHINXPROJ = deep_translator
|
8 |
+
SOURCEDIR = .
|
9 |
+
BUILDDIR = _build
|
10 |
+
|
11 |
+
# Put it first so that "make" without argument is like "make help".
|
12 |
+
help:
|
13 |
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
14 |
+
|
15 |
+
.PHONY: help Makefile
|
16 |
+
|
17 |
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
18 |
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
19 |
+
%: Makefile
|
20 |
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
docs/authors.rst
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.. include:: ../AUTHORS.rst
|
docs/conf.py
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# deep_translator documentation build configuration file, created by
|
4 |
+
# sphinx-quickstart on Fri Jun 9 13:47:02 2017.
|
5 |
+
#
|
6 |
+
# This file is execfile()d with the current directory set to its
|
7 |
+
# containing dir.
|
8 |
+
#
|
9 |
+
# Note that not all possible configuration values are present in this
|
10 |
+
# autogenerated file.
|
11 |
+
#
|
12 |
+
# All configuration values have a default; values that are commented out
|
13 |
+
# serve to show the default.
|
14 |
+
|
15 |
+
# If extensions (or modules to document with autodoc) are in another
|
16 |
+
# directory, add these directories to sys.path here. If the directory is
|
17 |
+
# relative to the documentation root, use os.path.abspath to make it
|
18 |
+
# absolute, like shown here.
|
19 |
+
#
|
20 |
+
import os
|
21 |
+
import sys
|
22 |
+
sys.path.insert(0, os.path.abspath('..'))
|
23 |
+
|
24 |
+
import deep_translator
|
25 |
+
|
26 |
+
# -- General configuration ---------------------------------------------
|
27 |
+
|
28 |
+
# If your documentation needs a minimal Sphinx version, state it here.
|
29 |
+
#
|
30 |
+
# needs_sphinx = '1.0'
|
31 |
+
|
32 |
+
# Add any Sphinx extension module names here, as strings. They can be
|
33 |
+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
34 |
+
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
|
35 |
+
|
36 |
+
# Add any paths that contain templates here, relative to this directory.
|
37 |
+
templates_path = ['_templates']
|
38 |
+
|
39 |
+
# The suffix(es) of source filenames.
|
40 |
+
# You can specify multiple suffix as a list of string:
|
41 |
+
#
|
42 |
+
# source_suffix = ['.rst', '.md']
|
43 |
+
source_suffix = '.rst'
|
44 |
+
|
45 |
+
# The master toctree document.
|
46 |
+
master_doc = 'index'
|
47 |
+
|
48 |
+
# General information about the project.
|
49 |
+
project = 'deep_translator'
|
50 |
+
copyright = "2020, Nidhal Baccouri"
|
51 |
+
author = "Nidhal Baccouri"
|
52 |
+
|
53 |
+
# The version info for the project you're documenting, acts as replacement
|
54 |
+
# for |version| and |release|, also used in various other places throughout
|
55 |
+
# the built documents.
|
56 |
+
#
|
57 |
+
# The short X.Y version.
|
58 |
+
version = deep_translator.__version__
|
59 |
+
# The full version, including alpha/beta/rc tags.
|
60 |
+
release = deep_translator.__version__
|
61 |
+
|
62 |
+
# The language for content autogenerated by Sphinx. Refer to documentation
|
63 |
+
# for a list of supported languages.
|
64 |
+
#
|
65 |
+
# This is also used if you do content translation via gettext catalogs.
|
66 |
+
# Usually you set "language" from the command line for these cases.
|
67 |
+
language = None
|
68 |
+
|
69 |
+
# List of patterns, relative to source directory, that match files and
|
70 |
+
# directories to ignore when looking for source files.
|
71 |
+
# This patterns also effect to html_static_path and html_extra_path
|
72 |
+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
73 |
+
|
74 |
+
# The name of the Pygments (syntax highlighting) style to use.
|
75 |
+
pygments_style = 'sphinx'
|
76 |
+
|
77 |
+
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
78 |
+
todo_include_todos = False
|
79 |
+
|
80 |
+
|
81 |
+
# -- Options for HTML output -------------------------------------------
|
82 |
+
|
83 |
+
# The theme to use for HTML and HTML Help pages. See the documentation for
|
84 |
+
# a list of builtin themes.
|
85 |
+
#
|
86 |
+
html_theme = 'alabaster'
|
87 |
+
|
88 |
+
# Theme options are theme-specific and customize the look and feel of a
|
89 |
+
# theme further. For a list of options available for each theme, see the
|
90 |
+
# documentation.
|
91 |
+
#
|
92 |
+
# html_theme_options = {}
|
93 |
+
|
94 |
+
# Add any paths that contain custom static files (such as style sheets) here,
|
95 |
+
# relative to this directory. They are copied after the builtin static files,
|
96 |
+
# so a file named "default.css" will overwrite the builtin "default.css".
|
97 |
+
html_static_path = ['_static']
|
98 |
+
|
99 |
+
|
100 |
+
# -- Options for HTMLHelp output ---------------------------------------
|
101 |
+
|
102 |
+
# Output file base name for HTML help builder.
|
103 |
+
htmlhelp_basename = 'deep_translatordoc'
|
104 |
+
|
105 |
+
|
106 |
+
# -- Options for LaTeX output ------------------------------------------
|
107 |
+
|
108 |
+
latex_elements = {
|
109 |
+
# The paper size ('letterpaper' or 'a4paper').
|
110 |
+
#
|
111 |
+
# 'papersize': 'letterpaper',
|
112 |
+
|
113 |
+
# The font size ('10pt', '11pt' or '12pt').
|
114 |
+
#
|
115 |
+
# 'pointsize': '10pt',
|
116 |
+
|
117 |
+
# Additional stuff for the LaTeX preamble.
|
118 |
+
#
|
119 |
+
# 'preamble': '',
|
120 |
+
|
121 |
+
# Latex figure (float) alignment
|
122 |
+
#
|
123 |
+
# 'figure_align': 'htbp',
|
124 |
+
}
|
125 |
+
|
126 |
+
# Grouping the document tree into LaTeX files. List of tuples
|
127 |
+
# (source start file, target name, title, author, documentclass
|
128 |
+
# [howto, manual, or own class]).
|
129 |
+
latex_documents = [
|
130 |
+
(master_doc, 'deep_translator.tex',
|
131 |
+
'deep_translator Documentation',
|
132 |
+
'Nidhal Baccouri', 'manual'),
|
133 |
+
]
|
134 |
+
|
135 |
+
|
136 |
+
# -- Options for manual page output ------------------------------------
|
137 |
+
|
138 |
+
# One entry per manual page. List of tuples
|
139 |
+
# (source start file, name, description, authors, manual section).
|
140 |
+
man_pages = [
|
141 |
+
(master_doc, 'deep_translator',
|
142 |
+
'deep_translator Documentation',
|
143 |
+
[author], 1)
|
144 |
+
]
|
145 |
+
|
146 |
+
|
147 |
+
# -- Options for Texinfo output ----------------------------------------
|
148 |
+
|
149 |
+
# Grouping the document tree into Texinfo files. List of tuples
|
150 |
+
# (source start file, target name, title, author,
|
151 |
+
# dir menu entry, description, category)
|
152 |
+
texinfo_documents = [
|
153 |
+
(master_doc, 'deep_translator',
|
154 |
+
'deep_translator Documentation',
|
155 |
+
author,
|
156 |
+
'deep_translator',
|
157 |
+
'One line description of project.',
|
158 |
+
'Miscellaneous'),
|
159 |
+
]
|
160 |
+
|
161 |
+
|
162 |
+
|
docs/contributing.rst
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.. include:: ../CONTRIBUTING.rst
|
docs/history.rst
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.. include:: ../HISTORY.rst
|
docs/index.rst
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Welcome to deep_translator's documentation!
|
2 |
+
======================================
|
3 |
+
|
4 |
+
.. toctree::
|
5 |
+
:maxdepth: 2
|
6 |
+
:caption: Contents:
|
7 |
+
|
8 |
+
readme
|
9 |
+
installation
|
10 |
+
usage
|
11 |
+
modules
|
12 |
+
contributing
|
13 |
+
authors
|
14 |
+
history
|
15 |
+
|
16 |
+
Indices and tables
|
17 |
+
==================
|
18 |
+
* :ref:`genindex`
|
19 |
+
* :ref:`modindex`
|
20 |
+
* :ref:`search`
|
docs/installation.rst
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.. highlight:: shell
|
2 |
+
|
3 |
+
============
|
4 |
+
Installation
|
5 |
+
============
|
6 |
+
|
7 |
+
|
8 |
+
Stable release
|
9 |
+
--------------
|
10 |
+
|
11 |
+
To install deep_translator, run this command in your terminal:
|
12 |
+
|
13 |
+
.. code-block:: console
|
14 |
+
|
15 |
+
$ pip install deep_translator
|
16 |
+
|
17 |
+
This is the preferred method to install deep_translator, as it will always install the most recent stable release.
|
18 |
+
|
19 |
+
If you don't have `pip`_ installed, this `Python installation guide`_ can guide
|
20 |
+
you through the process.
|
21 |
+
|
22 |
+
.. _pip: https://pip.pypa.io
|
23 |
+
.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
|
24 |
+
|
25 |
+
|
26 |
+
From sources
|
27 |
+
------------
|
28 |
+
|
29 |
+
The sources for deep_translator can be downloaded from the `Github repo`_.
|
30 |
+
|
31 |
+
You can either clone the public repository:
|
32 |
+
|
33 |
+
.. code-block:: console
|
34 |
+
|
35 |
+
$ git clone git://github.com/nidhaloff/deep_translator
|
36 |
+
|
37 |
+
Or download the `tarball`_:
|
38 |
+
|
39 |
+
.. code-block:: console
|
40 |
+
|
41 |
+
$ curl -OJL https://github.com/nidhaloff/deep_translator/tarball/master
|
42 |
+
|
43 |
+
Once you have a copy of the source, you can install it with:
|
44 |
+
|
45 |
+
.. code-block:: console
|
46 |
+
|
47 |
+
$ python setup.py install
|
48 |
+
|
49 |
+
|
50 |
+
.. _Github repo: https://github.com/nidhaloff/deep_translator
|
51 |
+
.. _tarball: https://github.com/nidhaloff/deep_translator/tarball/master
|
docs/make.bat
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@ECHO OFF
|
2 |
+
|
3 |
+
pushd %~dp0
|
4 |
+
|
5 |
+
REM Command file for Sphinx documentation
|
6 |
+
|
7 |
+
if "%SPHINXBUILD%" == "" (
|
8 |
+
set SPHINXBUILD=python -msphinx
|
9 |
+
)
|
10 |
+
set SOURCEDIR=.
|
11 |
+
set BUILDDIR=_build
|
12 |
+
set SPHINXPROJ=deep_translator
|
13 |
+
|
14 |
+
if "%1" == "" goto help
|
15 |
+
|
16 |
+
%SPHINXBUILD% >NUL 2>NUL
|
17 |
+
if errorlevel 9009 (
|
18 |
+
echo.
|
19 |
+
echo.The Sphinx module was not found. Make sure you have Sphinx installed,
|
20 |
+
echo.then set the SPHINXBUILD environment variable to point to the full
|
21 |
+
echo.path of the 'sphinx-build' executable. Alternatively you may add the
|
22 |
+
echo.Sphinx directory to PATH.
|
23 |
+
echo.
|
24 |
+
echo.If you don't have Sphinx installed, grab it from
|
25 |
+
echo.http://sphinx-doc.org/
|
26 |
+
exit /b 1
|
27 |
+
)
|
28 |
+
|
29 |
+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
30 |
+
goto end
|
31 |
+
|
32 |
+
:help
|
33 |
+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
34 |
+
|
35 |
+
:end
|
36 |
+
popd
|
docs/readme.rst
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.. include:: ../README.rst
|
docs/usage.rst
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=====
|
2 |
+
Usage
|
3 |
+
=====
|
4 |
+
|
5 |
+
To use deep_translator in a project::
|
6 |
+
|
7 |
+
from deep_translator import GoogleTranslator
|
8 |
+
|
9 |
+
english_text = 'happy coding'
|
10 |
+
chinese_text = '這很好'
|
11 |
+
|
12 |
+
# first create a GoogleTranslator object with source and target language
|
13 |
+
# then use the translate function to translate a text.
|
14 |
+
# All language are supported. Basic example:
|
15 |
+
result_german = GoogleTranslator(source='auto', target='de').translate(payload=english_text)
|
16 |
+
result_french = GoogleTranslator(source='auto', target='fr').translate(payload=chinese_text)
|
17 |
+
|
18 |
+
# Alternatively, you can pass languages by their name:
|
19 |
+
result_german = GoogleTranslator(source='english', target='german').translate(payload=english_text)
|
20 |
+
result_french = GoogleTranslator(source='auto', target='french').translate(payload=chinese_text)
|
21 |
+
|
22 |
+
# soon also support for the PONS translator.
|
23 |
+
|
examples/trans.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from deep_translator import GoogleTranslator
|
2 |
+
|
3 |
+
english_text = 'happy coding'
|
4 |
+
chinese_text = '這很好'
|
5 |
+
result_german = GoogleTranslator(source='english', target='german').translate(payload=english_text)
|
6 |
+
result_french = GoogleTranslator(source='auto', target='french').translate(payload=chinese_text)
|
7 |
+
|
8 |
+
print(f"original english text: {english_text} | translated text: {result_german}") # result: fröhliche Codierung
|
9 |
+
print(f"original chinese text: {chinese_text} | translated text: {result_french}") # result: C' est bon
|
10 |
+
|
pyvenv.cfg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
home = /usr/bin
|
2 |
+
include-system-site-packages = false
|
3 |
+
version = 3.7.7
|
requirements_dev.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip==19.2.3
|
2 |
+
bump2version==0.5.11
|
3 |
+
wheel==0.33.6
|
4 |
+
watchdog==0.9.0
|
5 |
+
flake8==3.7.8
|
6 |
+
tox==3.14.0
|
7 |
+
coverage==4.5.4
|
8 |
+
Sphinx==1.8.5
|
9 |
+
twine==1.14.0
|
10 |
+
|
11 |
+
pytest==4.6.5
|
12 |
+
pytest-runner==5.1
|
setup.cfg
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[bumpversion]
|
2 |
+
current_version = 0.0.1
|
3 |
+
commit = True
|
4 |
+
tag = True
|
5 |
+
|
6 |
+
[bumpversion:file:setup.py]
|
7 |
+
search = version='{current_version}'
|
8 |
+
replace = version='{new_version}'
|
9 |
+
|
10 |
+
[bumpversion:file:deep_translator/__init__.py]
|
11 |
+
search = __version__ = '{current_version}'
|
12 |
+
replace = __version__ = '{new_version}'
|
13 |
+
|
14 |
+
[bdist_wheel]
|
15 |
+
universal = 1
|
16 |
+
|
17 |
+
[flake8]
|
18 |
+
exclude = docs
|
19 |
+
|
20 |
+
[aliases]
|
21 |
+
# Define setup.py command aliases here
|
22 |
+
test = pytest
|
23 |
+
|
24 |
+
[tool:pytest]
|
25 |
+
collect_ignore = ['setup.py']
|
26 |
+
|
setup.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
"""The setup script."""
|
4 |
+
|
5 |
+
from setuptools import setup, find_packages
|
6 |
+
|
7 |
+
with open('README.rst') as readme_file:
|
8 |
+
readme = readme_file.read()
|
9 |
+
|
10 |
+
with open('HISTORY.rst') as history_file:
|
11 |
+
history = history_file.read()
|
12 |
+
|
13 |
+
requirements = [ ]
|
14 |
+
|
15 |
+
setup_requirements = ['pytest-runner', ]
|
16 |
+
|
17 |
+
test_requirements = ['pytest>=3', ]
|
18 |
+
|
19 |
+
setup(
|
20 |
+
author="Nidhal Baccouri",
|
21 |
+
author_email='[email protected]',
|
22 |
+
python_requires='>=3.5',
|
23 |
+
classifiers=[
|
24 |
+
'Development Status :: 2 - Pre-Alpha',
|
25 |
+
'Intended Audience :: Developers',
|
26 |
+
'License :: OSI Approved :: MIT License',
|
27 |
+
'Natural Language :: English',
|
28 |
+
'Programming Language :: Python :: 3',
|
29 |
+
'Programming Language :: Python :: 3.5',
|
30 |
+
'Programming Language :: Python :: 3.6',
|
31 |
+
'Programming Language :: Python :: 3.7',
|
32 |
+
'Programming Language :: Python :: 3.8',
|
33 |
+
],
|
34 |
+
description="A flexible python tool to translate between different languages in a simple way.",
|
35 |
+
entry_points={
|
36 |
+
'console_scripts': [
|
37 |
+
'deep_translator=deep_translator.cli:main',
|
38 |
+
],
|
39 |
+
},
|
40 |
+
install_requires=requirements,
|
41 |
+
license="MIT license",
|
42 |
+
long_description=readme + '\n\n' + history,
|
43 |
+
include_package_data=True,
|
44 |
+
keywords='deep_translator',
|
45 |
+
name='deep_translator',
|
46 |
+
packages=find_packages(include=['deep_translator', 'deep_translator.*']),
|
47 |
+
setup_requires=setup_requirements,
|
48 |
+
test_suite='tests',
|
49 |
+
tests_require=test_requirements,
|
50 |
+
url='https://github.com/nidhaloff/deep_translator',
|
51 |
+
version='0.0.1',
|
52 |
+
zip_safe=False,
|
53 |
+
)
|
tests/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
"""Unit test package for deep_translator."""
|
tests/test_deep_translator.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
"""Tests for `deep_translator` package."""
|
4 |
+
|
5 |
+
import pytest
|
6 |
+
|
7 |
+
from deep_translator import GoogleTranslator
|
8 |
+
from exceptions import LanguageNotSupportedException, NotValidPayload
|
9 |
+
|
10 |
+
|
11 |
+
@pytest.fixture
|
12 |
+
def response():
|
13 |
+
"""Sample pytest fixture.
|
14 |
+
|
15 |
+
See more at: http://doc.pytest.org/en/latest/fixture.html
|
16 |
+
"""
|
17 |
+
with pytest.raises(LanguageNotSupportedException):
|
18 |
+
GoogleTranslator(source="", target="")
|
19 |
+
|
20 |
+
with pytest.raises(LanguageNotSupportedException):
|
21 |
+
GoogleTranslator(source="auto", target="nothing")
|
22 |
+
|
23 |
+
|
24 |
+
def test_content(response):
|
25 |
+
"""Sample pytest test function with the pytest fixture as an argument."""
|
26 |
+
# from bs4 import BeautifulSoup
|
27 |
+
# assert 'GitHub' in BeautifulSoup(response.content).title.string
|
tox.ini
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tox]
|
2 |
+
envlist = py35, py36, py37, py38, flake8
|
3 |
+
|
4 |
+
[travis]
|
5 |
+
python =
|
6 |
+
3.8: py38
|
7 |
+
3.7: py37
|
8 |
+
3.6: py36
|
9 |
+
3.5: py35
|
10 |
+
|
11 |
+
[testenv:flake8]
|
12 |
+
basepython = python
|
13 |
+
deps = flake8
|
14 |
+
commands = flake8 deep_translator tests
|
15 |
+
|
16 |
+
[testenv]
|
17 |
+
setenv =
|
18 |
+
PYTHONPATH = {toxinidir}
|
19 |
+
deps =
|
20 |
+
-r{toxinidir}/requirements_dev.txt
|
21 |
+
; If you want to make tox run the tests with the same versions, create a
|
22 |
+
; requirements.txt with the pinned versions and uncomment the following line:
|
23 |
+
; -r{toxinidir}/requirements.txt
|
24 |
+
commands =
|
25 |
+
pip install -U pip
|
26 |
+
pytest --basetemp={envtmpdir}
|
27 |
+
|