File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 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" ))
Original file line number Diff line number Diff line change 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+ )
You can’t perform that action at this time.
0 commit comments