Skip to content

Commit

Permalink
Merge pull request #7 from DavideGalilei/dev
Browse files Browse the repository at this point in the history
✨ Update 1.1.0
  • Loading branch information
DavideGalilei authored May 27, 2021
2 parents d1c1448 + 4b0961e commit b635c6d
Show file tree
Hide file tree
Showing 25 changed files with 597 additions and 169 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/venv/
/.idea/
/gpytranslate.egg-info/
55 changes: 1 addition & 54 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -618,57 +618,4 @@ an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
END OF TERMS AND CONDITIONS
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ A Python3 library for translating text using Google Translate API.

----
## Features

- **Dot accessible values**
- **Supports emoji**
- **Asynchronous**
- **Type hinted**
- **Free to use**
- **Easy**
- **Both Synchronous and Asynchronous**
- **Dot accessible values**
- **Supports emoji**
- **Type hinted**
- **Free to use**
- **Easy**

----
## Quick Start
Expand All @@ -19,29 +18,39 @@ Requirements:
- Python 3.6 or higher.


``` bash
$ python -m pip install gpytranslate
```bash
$ python3 -m pip install -U gpytranslate
```
----
### Usage

[Example:](https://github.com/DavideGalilei/gpytranslate/blob/master/examples/example.py)
``` python
[Async Example:](/examples/async/example.py)
```python
from gpytranslate import Translator
import asyncio


async def main():
t = Translator()
translation = await t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
language = await t.detect("Ciao come stai? Io bene ahah.")
language = await t.detect(translation.text)
print(f"Translation: {translation.text}\nDetected language: {language}")


if __name__ == "__main__":
asyncio.run(main())
```
**Note:** you could also check [tests](https://github.com/DavideGalilei/gpytranslate/blob/master/tests/) folder for extra examples

[Sync Example:](/examples/sync/example.py)
```python
from gpytranslate import SyncTranslator

t = SyncTranslator()
translation = t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
language = t.detect(translation.text)
print(f"Translation: {translation.text}\nDetected language: {language}")
```
**Note:** you could also check [tests](/tests) folder for extra examples.

Output:
```
Expand All @@ -50,9 +59,10 @@ Detected language: it
```
----
## Development

Want to contribute? Pull requests are accepted!

----
## License
GNU GPLv3
Licensed under the GNU GPLv3.

Click [here](/LICENSE) for futher information.
35 changes: 35 additions & 0 deletions examples/async/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
gpytranslate - A Python3 library for translating text using Google Translate API.
Copyright (C) 2020-2021 Davide Galilei
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

import asyncio

from gpytranslate import Translator


async def main():
t = Translator()
# Note: you can use proxies by passing proxies parameter to Translator
translation = await t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
# By default, sourcelang is "auto"
language = await t.detect(translation.text)
# Returns language code "it"
print(f"Translation: {translation.text}\nDetected language: {language}")


if __name__ == "__main__":
asyncio.run(main())
33 changes: 33 additions & 0 deletions examples/async/https_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
gpytranslate - A Python3 library for translating text using Google Translate API.
Copyright (C) 2020-2021 Davide Galilei
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

import asyncio

from gpytranslate import Translator


async def main():
t = Translator(proxies={"https://": "https://{proxy_ip_here}"})
# Check out https://www.python-httpx.org/compatibility/#proxy-keys
translation = await t.translate("Ciao Mondo!", targetlang="en")
# Hello World!
print(f"Translation: {translation.text}")


if __name__ == "__main__":
asyncio.run(main())
37 changes: 37 additions & 0 deletions examples/async/socks5_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
gpytranslate - A Python3 library for translating text using Google Translate API.
Copyright (C) 2020-2021 Davide Galilei
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

import asyncio

from httpx_socks import AsyncProxyTransport

from gpytranslate import Translator


async def main():
t = Translator(
transport=AsyncProxyTransport.from_url("socks5://user:[email protected]:1080")
)
# Check out https://pypi.org/project/httpx-socks/
translation = await t.translate("Ciao Mondo!", targetlang="en")
# Hello World!
print(f"Translation: {translation.text}")


if __name__ == "__main__":
asyncio.run(main())
17 changes: 0 additions & 17 deletions examples/example.py

This file was deleted.

15 changes: 0 additions & 15 deletions examples/https_proxy.py

This file was deleted.

19 changes: 0 additions & 19 deletions examples/socks5_proxy.py

This file was deleted.

24 changes: 24 additions & 0 deletions examples/sync/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
gpytranslate - A Python3 library for translating text using Google Translate API.
Copyright (C) 2020-2021 Davide Galilei
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from gpytranslate import SyncTranslator

t = SyncTranslator()
translation = t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
language = t.detect(translation.text)
print(f"Translation: {translation.text}\nDetected language: {language}")
25 changes: 25 additions & 0 deletions examples/sync/https_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
gpytranslate - A Python3 library for translating text using Google Translate API.
Copyright (C) 2020-2021 Davide Galilei
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from gpytranslate import SyncTranslator

t = SyncTranslator(proxies={"https://": "https://{proxy_ip_here}"})
# Check out https://www.python-httpx.org/compatibility/#proxy-keys
translation = t.translate("Ciao Mondo!", targetlang="en")
# Hello World!
print(f"Translation: {translation.text}")
29 changes: 29 additions & 0 deletions examples/sync/socks5_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
gpytranslate - A Python3 library for translating text using Google Translate API.
Copyright (C) 2020-2021 Davide Galilei
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from httpx_socks import SyncProxyTransport

from gpytranslate import SyncTranslator

t = SyncTranslator(
transport=SyncProxyTransport.from_url("socks5://user:[email protected]:1080")
)
# Check out https://pypi.org/project/httpx-socks/
translation = await t.translate("Ciao Mondo!", targetlang="en")
# Hello World!
print(f"Translation: {translation.text}")
4 changes: 3 additions & 1 deletion gpytranslate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .gpytranslate import Translator
from .sync import SyncTranslator
from .types import TranslatedObject

__all__ = ["Translator", "TranslatedObject"]
__version__ = "1.1.0"
__all__ = ["Translator", "SyncTranslator", "TranslatedObject"]
Loading

0 comments on commit b635c6d

Please sign in to comment.