Skip to content

Commit 94d6194

Browse files
committed
update
1 parent 4ad9896 commit 94d6194

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

googletrans/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
googletrans-python
3+
"""
4+
import re
5+
import html
6+
import urllib.request
7+
import urllib.parse
8+
9+
__version__ = '0.1.0.0'
10+
11+
def translate(to_translate, to_language="auto", from_language="auto"):
12+
link = f"http://translate.google.com/m?tl={to_language}&sl={from_language}&q={urllib.parse.quote(to_translate)}"
13+
request = urllib.request.Request(link, headers={'User-Agent':"Mozilla/4.0 (compatible;MSIE 6.0;Windows NT 5.1;SV1;.NET CLR 1.1.4322;.NET CLR 2.0.50727;.NET CLR 3.0.04506.30)"})
14+
re_result = re.findall(r'(?s)class="(?:t0|result-container)">(.*?)<', urllib.request.urlopen(request).read().decode("utf-8"))
15+
return "" if len(re_result) == 0 else html.unescape(re_result[0])
16+
17+
if __name__ == "__main__":
18+
print(translate("Hello, My name is python.", "ko"))

setup.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from setuptools import setup, find_packages
2+
from googletrans import __version__ as VERSION
3+
4+
requirements = [
5+
]
6+
7+
test_requirements = [
8+
]
9+
10+
setup(
11+
name = 'googletrans-python',
12+
version = VERSION,
13+
description = 'googletrans-python package.',
14+
long_description = readme,
15+
author = "leeyunjai",
16+
author_email = '[email protected]',
17+
url = 'https://github.com/leeyunjai/googletrans-python',
18+
packages = find_packages(),
19+
install_requires = requirements,
20+
keywords = 'googletrans',
21+
classifiers = [
22+
'Natural Language :: English',
23+
'Programming Language :: Python :: 3.5',
24+
'Programming Language :: Python :: 3.6',
25+
'Programming Language :: Python :: 3.7',
26+
'Programming Language :: Python :: 3.8',
27+
'Programming Language :: Python :: 3.9',
28+
],
29+
test_suite = 'tests',
30+
tests_require = test_requirements
31+
)

0 commit comments

Comments
 (0)