Skip to content

Commit a248601

Browse files
Merge pull request #28 from DavideGalilei/dev
πŸ‘¨β€πŸ’» Update 2.0.0
2 parents c0f59a3 + ea14253 commit a248601

31 files changed

+887
-640
lines changed

β€Ž.github/workflows/test-suite.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
17+
version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
1818

1919
steps:
2020
- uses: "actions/checkout@v2"

β€Ž.gitignoreβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/.idea/
33
/gpytranslate.egg-info/
44
**/__pycache__
5+
.aider*
6+
.env

β€ŽLICENSEβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Davide Galilei
3+
Copyright (c) 2024 Davide Galilei
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

β€ŽREADME.mdβ€Ž

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# gpytranslate
2-
A Python3 library for translating text using Google Translate API.
32

4-
----
3+
[![PyPI version](https://badge.fury.io/py/gpytranslate.svg)](https://badge.fury.io/py/gpytranslate)
4+
[![Python Versions](https://img.shields.io/pypi/pyversions/gpytranslate.svg)](https://pypi.org/project/gpytranslate/)
5+
[![License](https://img.shields.io/github/license/DavideGalilei/gpytranslate.svg)](https://github.com/DavideGalilei/gpytranslate/blob/master/LICENSE)
6+
7+
A Python3 library for translating text using Google Translate API.
58
## Features
69
- **Both Synchronous and Asynchronous**
710
- **Dot accessible values**
@@ -14,12 +17,21 @@ A Python3 library for translating text using Google Translate API.
1417
## Quick Start
1518

1619
### Installation
20+
1721
Requirements:
18-
- Python 3.7 or higher.
22+
- Python 3.9 or higher
23+
- httpx[socks] >= 0.28.0
24+
- aiofiles >= 24.1.0
25+
- typing-extensions >= 4.12.2
1926

27+
Install using pip:
28+
```bash
29+
python3 -m pip install -U gpytranslate
30+
```
2031

32+
Or install with poetry:
2133
```bash
22-
$ python3 -m pip install -U gpytranslate
34+
poetry add gpytranslate
2335
```
2436
----
2537
### Usage
@@ -89,11 +101,47 @@ https://danpetrov.xyz/programming/2021/12/30/telegram-google-translate.html
89101
https://vielhuber.de/en/blog/google-translation-api-hacking/
90102
https://github.com/OwlGramDev/OwlGram/blob/b9bb8a247758adbf7be7aaf3eb150f680bec1269/TMessagesProj/src/main/java/it/owlgram/android/translator/GoogleAppTranslator.java
91103

92-
----
104+
### Language Codes
105+
106+
The library uses ISO 639-1 two-letter language codes. Some common examples:
107+
108+
- English: 'en'
109+
- Spanish: 'es'
110+
- French: 'fr'
111+
- German: 'de'
112+
- Italian: 'it'
113+
- Japanese: 'ja'
114+
- Chinese (Simplified): 'zh'
115+
116+
### Error Handling
117+
118+
The library raises `TranslationError` when translation fails:
119+
120+
```python
121+
from gpytranslate import Translator, TranslationError
122+
123+
translator = Translator()
124+
try:
125+
result = await translator.translate("Hello", targetlang="invalid")
126+
except TranslationError as e:
127+
print(f"Translation failed: {e}")
128+
```
129+
93130
## Development
94-
Want to contribute? Pull requests are accepted!
95131

96-
----
132+
### Contributing
133+
134+
Contributions are welcome! Here's how you can help:
135+
136+
1. Fork the repository
137+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
138+
3. Make your changes
139+
4. Run the tests (`pytest`)
140+
5. Commit your changes (`git commit -m 'Add amazing feature'`)
141+
6. Push to the branch (`git push origin feature/amazing-feature`)
142+
7. Open a Pull Request
143+
144+
Please make sure to update tests as appropriate and follow the existing code style.
97145
## License
98146
Licensed under the MIT License.
99147

β€Žexamples/async/__init__.pyβ€Ž

Whitespace-only changes.

β€Žexamples/async/example.pyβ€Ž

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
1-
"""
2-
gpytranslate - A Python3 library for translating text using Google Translate API.
3-
MIT License
4-
5-
Copyright (c) 2023 Davide Galilei
6-
7-
Permission is hereby granted, free of charge, to any person obtaining a copy
8-
of this software and associated documentation files (the "Software"), to deal
9-
in the Software without restriction, including without limitation the rights
10-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
copies of the Software, and to permit persons to whom the Software is
12-
furnished to do so, subject to the following conditions:
13-
14-
The above copyright notice and this permission notice shall be included in all
15-
copies or substantial portions of the Software.
16-
17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
SOFTWARE.
24-
"""
25-
261
import asyncio
272

283
from gpytranslate import Translator
294

5+
"""Example showing basic translation and language detection."""
6+
307

31-
async def main():
8+
async def main() -> None:
9+
"""Demonstrate translation from Italian to English and language detection."""
3210
t = Translator()
3311
# Note: you can use proxies by passing proxies parameter to Translator
3412
translation = await t.translate("Ciao come stai? Io bene ahah.", targetlang="en")

β€Žexamples/async/https_proxy.pyβ€Ž

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
1-
"""
2-
gpytranslate - A Python3 library for translating text using Google Translate API.
3-
MIT License
4-
5-
Copyright (c) 2023 Davide Galilei
6-
7-
Permission is hereby granted, free of charge, to any person obtaining a copy
8-
of this software and associated documentation files (the "Software"), to deal
9-
in the Software without restriction, including without limitation the rights
10-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
copies of the Software, and to permit persons to whom the Software is
12-
furnished to do so, subject to the following conditions:
13-
14-
The above copyright notice and this permission notice shall be included in all
15-
copies or substantial portions of the Software.
16-
17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
SOFTWARE.
24-
"""
25-
261
import asyncio
272

283
from gpytranslate import Translator
294

5+
"""Example showing how to use HTTPS proxy with the translator."""
6+
307

31-
async def main():
8+
async def main() -> None:
9+
"""Demonstrate translation using an HTTPS proxy."""
3210
t = Translator(proxies={"https://": "https://{proxy_ip_here}"})
3311
# Check out https://www.python-httpx.org/compatibility/#proxy-keys
3412
translation = await t.translate("Ciao Mondo!", targetlang="en")

β€Žexamples/async/socks5_proxy.pyβ€Ž

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
1-
"""
2-
gpytranslate - A Python3 library for translating text using Google Translate API.
3-
MIT License
4-
5-
Copyright (c) 2023 Davide Galilei
6-
7-
Permission is hereby granted, free of charge, to any person obtaining a copy
8-
of this software and associated documentation files (the "Software"), to deal
9-
in the Software without restriction, including without limitation the rights
10-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
copies of the Software, and to permit persons to whom the Software is
12-
furnished to do so, subject to the following conditions:
13-
14-
The above copyright notice and this permission notice shall be included in all
15-
copies or substantial portions of the Software.
16-
17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
SOFTWARE.
24-
"""
25-
261
import asyncio
272

28-
from httpx_socks import AsyncProxyTransport
29-
303
from gpytranslate import Translator
314

5+
"""Example showing how to use SOCKS5 proxy with the translator."""
6+
327

33-
async def main():
34-
t = Translator(
35-
transport=AsyncProxyTransport.from_url("socks5://user:password@127.0.0.1:1080")
36-
)
8+
async def main() -> None:
9+
"""Demonstrate translation using a SOCKS5 proxy."""
10+
t = Translator(proxies={"socks5": "socks5://user:password@127.0.0.1:1080"})
3711
# Check out https://pypi.org/project/httpx-socks/
3812
translation = await t.translate("Ciao Mondo!", targetlang="en")
3913
# Hello World!

β€Žexamples/async/tts.pyβ€Ž

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,14 @@
1-
"""
2-
gpytranslate - A Python3 library for translating text using Google Translate API.
3-
MIT License
4-
5-
Copyright (c) 2023 Davide Galilei
6-
7-
Permission is hereby granted, free of charge, to any person obtaining a copy
8-
of this software and associated documentation files (the "Software"), to deal
9-
in the Software without restriction, including without limitation the rights
10-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
copies of the Software, and to permit persons to whom the Software is
12-
furnished to do so, subject to the following conditions:
13-
14-
The above copyright notice and this permission notice shall be included in all
15-
copies or substantial portions of the Software.
16-
17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
SOFTWARE.
24-
"""
25-
261
import asyncio
272

283
import aiofiles
294

305
from gpytranslate import Translator
316

7+
"""Example showing how to use text-to-speech functionality."""
8+
329

33-
async def main():
10+
async def main() -> None:
11+
"""Demonstrate text-to-speech generation."""
3412
translator = Translator()
3513

3614
async with aiofiles.open("test.mp3", "wb") as file:

β€Žexamples/sync/__init__.pyβ€Ž

Whitespace-only changes.

0 commit comments

Comments
Β (0)