= commited on
Commit
9cde6b7
·
1 Parent(s): 76349e5

merged language detection feature in master

Browse files
README.rst CHANGED
@@ -61,10 +61,12 @@ When you should use it
61
  - If you want to get translations from many sources and not only one
62
  - If you want to automate translations
63
  - If you want to compare different translations
 
64
 
65
  Why you should use it
66
  ----------------------
67
  - High level of abstraction
 
68
  - Easy to use and extend
69
  - It's the only python tool that integrates many translators
70
  - Stable
@@ -77,6 +79,7 @@ Features
77
  * Support for Pons translator (pons.com)
78
  * Support for the Linguee translator
79
  * Support for the Mymemory translator
 
80
  * Translate directly from a text file
81
  * Get multiple translation for a word
82
  * Automate the translation of different paragraphs in different languages
@@ -99,7 +102,7 @@ Usage
99
 
100
  .. code-block:: python
101
 
102
- from deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslator, MyMemoryTranslator
103
 
104
  text = 'happy coding'
105
 
@@ -119,6 +122,19 @@ Usage
119
  # alternatively, you can the dictionary containing languages mapped to their abbreviation
120
  langs_dict = GoogleTranslator.get_supported_languages(as_dict=True) # output: {arabic: ar, french: fr, english:en etc...}
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  - Simple translation:
124
 
 
61
  - If you want to get translations from many sources and not only one
62
  - If you want to automate translations
63
  - If you want to compare different translations
64
+ - If you want to detect language automatically
65
 
66
  Why you should use it
67
  ----------------------
68
  - High level of abstraction
69
+ - Automatic language detection
70
  - Easy to use and extend
71
  - It's the only python tool that integrates many translators
72
  - Stable
 
79
  * Support for Pons translator (pons.com)
80
  * Support for the Linguee translator
81
  * Support for the Mymemory translator
82
+ * Automatic language detection
83
  * Translate directly from a text file
84
  * Get multiple translation for a word
85
  * Automate the translation of different paragraphs in different languages
 
102
 
103
  .. code-block:: python
104
 
105
+ from deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslator, MyMemoryTranslator, detect_language
106
 
107
  text = 'happy coding'
108
 
 
122
  # alternatively, you can the dictionary containing languages mapped to their abbreviation
123
  langs_dict = GoogleTranslator.get_supported_languages(as_dict=True) # output: {arabic: ar, french: fr, english:en etc...}
124
 
125
+ .. note::
126
+
127
+ You can also detect language automatically. Notice that this package is free and my goal is to keep it free.
128
+ Therefore, you will need to get your own api_key if you want to use the language detection function.
129
+ I figured out you can get one for free here: https://detectlanguage.com/documentation
130
+
131
+ - Language detection:
132
+
133
+ .. code-block:: python
134
+
135
+ lang = detect_language('bonjour la vie', api_key='your_api_key')
136
+ print(lang) # output: fr
137
+
138
 
139
  - Simple translation:
140
 
deep_translator/__init__.py CHANGED
@@ -9,7 +9,7 @@ from .detection import detect_language
9
 
10
  __author__ = """Nidhal Baccouri"""
11
  __email__ = '[email protected]'
12
- __version__ = '1.1.2'
13
 
14
  __all__ = [GoogleTranslator,
15
  PonsTranslator,
 
9
 
10
  __author__ = """Nidhal Baccouri"""
11
  __email__ = '[email protected]'
12
+ __version__ = '1.1.3'
13
 
14
  __all__ = [GoogleTranslator,
15
  PonsTranslator,
deep_translator/detection.py CHANGED
@@ -28,5 +28,5 @@ def detect_language(text, api_key=None):
28
  return lang
29
 
30
  except Exception as e:
31
- print(e.args)
32
- raise
 
28
  return lang
29
 
30
  except Exception as e:
31
+ print("Error occured while requesting from server: ", e.args)
32
+ raise e
deep_translator/utils.py CHANGED
@@ -1,21 +1,3 @@
1
-
2
- import requests
3
- from bs4 import BeautifulSoup
4
-
5
-
6
- # res = requests.get('https://translate.google.com/?sl=auto&tl=en#view=home&op=translate&sl=auto&tl=de&text=cute')
7
- # soup = BeautifulSoup(res.text, 'html.parser')
8
- # print(soup)
9
- # a = soup.find('div', {'class': 'goog-inline-block jfk-button jfk-button-standard jfk-button-collapse-right jfk-button-checked'})
10
-
11
- # print(a)
12
- from bs4 import BeautifulSoup
13
- from requests_html import HTMLSession
14
-
15
- session = HTMLSession()
16
- r = session.get('https://translate.google.com/m?hl=en&sl=auto&tl=de&ie=UTF-8&prev=_m&q=here+is+a+sentence')
17
- r.html.render()
18
-
19
- print(r.html.html)
20
- #soup = BeautifulSoup(r.html.html, 'html.parser')
21
-
 
1
+ """
2
+ utilities
3
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
setup.cfg CHANGED
@@ -1,5 +1,5 @@
1
  [bumpversion]
2
- current_version = 1.1.2
3
  commit = True
4
  tag = True
5
 
 
1
  [bumpversion]
2
+ current_version = 1.1.3
3
  commit = True
4
  tag = True
5
 
setup.py CHANGED
@@ -51,6 +51,6 @@ setup(
51
  test_suite='tests',
52
  tests_require=test_requirements,
53
  url='https://github.com/nidhaloff/deep_translator',
54
- version='1.1.2',
55
  zip_safe=False,
56
  )
 
51
  test_suite='tests',
52
  tests_require=test_requirements,
53
  url='https://github.com/nidhaloff/deep_translator',
54
+ version='1.1.3',
55
  zip_safe=False,
56
  )