=
commited on
Commit
·
790d8de
1
Parent(s):
531ed25
update readme and fixed the pons no translation bug
Browse files- README.rst +94 -19
- deep_translator/__init__.py +1 -1
- setup.cfg +1 -1
- setup.py +1 -1
README.rst
CHANGED
@@ -42,8 +42,9 @@ A flexible **FREE** and **UNLIMITED** tool to translate between different langua
|
|
42 |
* Free software: MIT license
|
43 |
* Documentation: https://deep-translator.readthedocs.io.
|
44 |
|
|
|
45 |
Motivation
|
46 |
-
|
47 |
|
48 |
I needed to translate a text using python. It was hard to find a simple way to do it.
|
49 |
There are other libraries that can be used for this task, but most of them
|
@@ -55,8 +56,10 @@ support for all languages.
|
|
55 |
Basically, my goal was to integrate support for multiple famous translators
|
56 |
in this tool.
|
57 |
|
|
|
58 |
When you should use it
|
59 |
-
|
|
|
60 |
- If you want to translate text using python
|
61 |
- If you want to translate from a file
|
62 |
- If you want to get translations from many sources and not only one
|
@@ -64,8 +67,10 @@ When you should use it
|
|
64 |
- If you want to compare different translations
|
65 |
- If you want to detect language automatically
|
66 |
|
|
|
67 |
Why you should use it
|
68 |
-
|
|
|
69 |
- High level of abstraction
|
70 |
- Automatic language detection
|
71 |
- Easy to use and extend
|
@@ -73,8 +78,9 @@ Why you should use it
|
|
73 |
- Stable
|
74 |
- Support for most famous universal translators
|
75 |
|
|
|
76 |
Features
|
77 |
-
|
78 |
|
79 |
* Support for google translate
|
80 |
* Support for Pons translator (pons.com)
|
@@ -86,6 +92,7 @@ Features
|
|
86 |
* Automate the translation of different paragraphs in different languages
|
87 |
* Translate directly from terminal (version >= 1.1.0)
|
88 |
|
|
|
89 |
Installation
|
90 |
=============
|
91 |
|
@@ -97,9 +104,16 @@ Install the stable release:
|
|
97 |
|
98 |
take a look at the docs if you want to install from source.
|
99 |
|
|
|
100 |
Usage
|
101 |
=====
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
.. code-block:: python
|
105 |
|
@@ -110,14 +124,14 @@ Usage
|
|
110 |
detect_language)
|
111 |
|
112 |
|
|
|
|
|
113 |
|
114 |
.. note::
|
115 |
|
116 |
You can check the supported languages of each translator by calling the
|
117 |
get_supported_languages function as a static method.
|
118 |
|
119 |
-
- Example of checking the supported languages for the google translator:
|
120 |
-
|
121 |
.. code-block:: python
|
122 |
|
123 |
# default return type is a list
|
@@ -126,74 +140,129 @@ Usage
|
|
126 |
# alternatively, you can the dictionary containing languages mapped to their abbreviation
|
127 |
langs_dict = GoogleTranslator.get_supported_languages(as_dict=True) # output: {arabic: ar, french: fr, english:en etc...}
|
128 |
|
|
|
|
|
|
|
129 |
.. note::
|
130 |
|
131 |
You can also detect language automatically. Notice that this package is free and my goal is to keep it free.
|
132 |
Therefore, you will need to get your own api_key if you want to use the language detection function.
|
133 |
I figured out you can get one for free here: https://detectlanguage.com/documentation
|
134 |
|
135 |
-
- Language detection:
|
136 |
-
|
137 |
.. code-block:: python
|
138 |
|
139 |
lang = detect_language('bonjour la vie', api_key='your_api_key')
|
140 |
print(lang) # output: fr
|
141 |
|
142 |
|
143 |
-
|
|
|
144 |
|
145 |
.. code-block:: python
|
146 |
|
147 |
text = 'happy coding'
|
148 |
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
-
# Alternatively, you can pass languages by their name:
|
152 |
translated = GoogleTranslator(source='english', target='german').translate(text=text)
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
- Translate from a file:
|
155 |
|
156 |
.. code-block:: python
|
157 |
|
158 |
translated = GoogleTranslator(source='auto', target='german').translate_file('path/to/file')
|
159 |
|
160 |
-
- Automate translation by detecting the source language
|
161 |
|
162 |
.. code-block:: python
|
163 |
|
164 |
# or maybe you have many sentences in different languages and want to automate the translation process
|
165 |
-
translated = GoogleTranslator(source='auto', target='de').translate_sentences(your_list_of_sentences)
|
|
|
166 |
|
167 |
|
168 |
-
|
|
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
.. code-block:: python
|
172 |
|
173 |
-
word = 'good'
|
174 |
translated_word = PonsTranslator(source='english', target='french').translate(word)
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
# set the argument return_all to True if you want to get all synonyms of the word to translate
|
177 |
translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
|
178 |
|
179 |
|
180 |
-
|
|
|
|
|
181 |
|
182 |
|
183 |
.. code-block:: python
|
184 |
|
185 |
word = 'good'
|
|
|
|
|
|
|
|
|
|
|
186 |
translated_word = LingueeTranslator(source='english', target='french').translate(word)
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
# set the argument return_all to True if you want to get all synonyms of the word to translate
|
189 |
translated_word = LingueeTranslator(source='english', target='french').translate(word, return_all=True)
|
190 |
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
.. code-block:: python
|
194 |
|
195 |
-
|
196 |
-
|
|
|
197 |
|
198 |
Usage from Terminal
|
199 |
====================
|
@@ -222,6 +291,12 @@ If you want, you can also pass the source and target language by their abbreviat
|
|
222 |
|
223 |
$ deep_translator -trans "google" -src "en" -tg "de" -txt "happy coding"
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
========
|
226 |
Links
|
227 |
========
|
|
|
42 |
* Free software: MIT license
|
43 |
* Documentation: https://deep-translator.readthedocs.io.
|
44 |
|
45 |
+
==========
|
46 |
Motivation
|
47 |
+
==========
|
48 |
|
49 |
I needed to translate a text using python. It was hard to find a simple way to do it.
|
50 |
There are other libraries that can be used for this task, but most of them
|
|
|
56 |
Basically, my goal was to integrate support for multiple famous translators
|
57 |
in this tool.
|
58 |
|
59 |
+
======================
|
60 |
When you should use it
|
61 |
+
======================
|
62 |
+
|
63 |
- If you want to translate text using python
|
64 |
- If you want to translate from a file
|
65 |
- If you want to get translations from many sources and not only one
|
|
|
67 |
- If you want to compare different translations
|
68 |
- If you want to detect language automatically
|
69 |
|
70 |
+
======================
|
71 |
Why you should use it
|
72 |
+
======================
|
73 |
+
|
74 |
- High level of abstraction
|
75 |
- Automatic language detection
|
76 |
- Easy to use and extend
|
|
|
78 |
- Stable
|
79 |
- Support for most famous universal translators
|
80 |
|
81 |
+
========
|
82 |
Features
|
83 |
+
========
|
84 |
|
85 |
* Support for google translate
|
86 |
* Support for Pons translator (pons.com)
|
|
|
92 |
* Automate the translation of different paragraphs in different languages
|
93 |
* Translate directly from terminal (version >= 1.1.0)
|
94 |
|
95 |
+
=============
|
96 |
Installation
|
97 |
=============
|
98 |
|
|
|
104 |
|
105 |
take a look at the docs if you want to install from source.
|
106 |
|
107 |
+
=====
|
108 |
Usage
|
109 |
=====
|
110 |
|
111 |
+
In this section, demos on how to use all different integrated translators in this tool are provided.
|
112 |
+
This includes the google, pons, linguee and mymemory translator (at least for now). Perhaps more
|
113 |
+
translators will be integrated in the future.
|
114 |
+
|
115 |
+
Imports
|
116 |
+
========
|
117 |
|
118 |
.. code-block:: python
|
119 |
|
|
|
124 |
detect_language)
|
125 |
|
126 |
|
127 |
+
Check Supported Languages
|
128 |
+
==========================
|
129 |
|
130 |
.. note::
|
131 |
|
132 |
You can check the supported languages of each translator by calling the
|
133 |
get_supported_languages function as a static method.
|
134 |
|
|
|
|
|
135 |
.. code-block:: python
|
136 |
|
137 |
# default return type is a list
|
|
|
140 |
# alternatively, you can the dictionary containing languages mapped to their abbreviation
|
141 |
langs_dict = GoogleTranslator.get_supported_languages(as_dict=True) # output: {arabic: ar, french: fr, english:en etc...}
|
142 |
|
143 |
+
Language Detection
|
144 |
+
===================
|
145 |
+
|
146 |
.. note::
|
147 |
|
148 |
You can also detect language automatically. Notice that this package is free and my goal is to keep it free.
|
149 |
Therefore, you will need to get your own api_key if you want to use the language detection function.
|
150 |
I figured out you can get one for free here: https://detectlanguage.com/documentation
|
151 |
|
|
|
|
|
152 |
.. code-block:: python
|
153 |
|
154 |
lang = detect_language('bonjour la vie', api_key='your_api_key')
|
155 |
print(lang) # output: fr
|
156 |
|
157 |
|
158 |
+
Google Translate
|
159 |
+
=================
|
160 |
|
161 |
.. code-block:: python
|
162 |
|
163 |
text = 'happy coding'
|
164 |
|
165 |
+
- You can use automatic language detection to detect the source language:
|
166 |
+
|
167 |
+
.. code-block:: python
|
168 |
+
|
169 |
+
translated = GoogleTranslator(source='auto', target='german').translate(text=text)
|
170 |
+
|
171 |
+
- You can pass languages by name:
|
172 |
+
|
173 |
+
.. code-block:: python
|
174 |
|
|
|
175 |
translated = GoogleTranslator(source='english', target='german').translate(text=text)
|
176 |
|
177 |
+
- Alternatively, you can pass languages by their abbreviation:
|
178 |
+
|
179 |
+
.. code-block:: python
|
180 |
+
|
181 |
+
translated = GoogleTranslator(source='en', target='de').translate(text=text)
|
182 |
+
|
183 |
- Translate from a file:
|
184 |
|
185 |
.. code-block:: python
|
186 |
|
187 |
translated = GoogleTranslator(source='auto', target='german').translate_file('path/to/file')
|
188 |
|
189 |
+
- Automate translation by detecting the source language and translate it automatically to the desired language
|
190 |
|
191 |
.. code-block:: python
|
192 |
|
193 |
# or maybe you have many sentences in different languages and want to automate the translation process
|
194 |
+
translated = GoogleTranslator(source='auto', target='de').translate_sentences([your_list_of_sentences])
|
195 |
+
|
196 |
|
197 |
|
198 |
+
PONS Translator
|
199 |
+
===============
|
200 |
|
201 |
+
.. note::
|
202 |
+
|
203 |
+
You can pass the languages by the name or by abbreviation just like
|
204 |
+
previous examples using GoogleTranslate
|
205 |
+
|
206 |
+
.. code-block:: python
|
207 |
+
|
208 |
+
word = 'awesome'
|
209 |
+
|
210 |
+
- Simple Translation
|
211 |
|
212 |
.. code-block:: python
|
213 |
|
|
|
214 |
translated_word = PonsTranslator(source='english', target='french').translate(word)
|
215 |
|
216 |
+
# pass language by their abbreviation
|
217 |
+
translated_word = PonsTranslator(source='en', target='fr').translate(word)
|
218 |
+
|
219 |
+
- Return all synonyms or words that matches
|
220 |
+
|
221 |
+
.. code-block:: python
|
222 |
+
|
223 |
# set the argument return_all to True if you want to get all synonyms of the word to translate
|
224 |
translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
|
225 |
|
226 |
|
227 |
+
|
228 |
+
Linguee Translator
|
229 |
+
===================
|
230 |
|
231 |
|
232 |
.. code-block:: python
|
233 |
|
234 |
word = 'good'
|
235 |
+
|
236 |
+
- Simple Translation
|
237 |
+
|
238 |
+
.. code-block:: python
|
239 |
+
|
240 |
translated_word = LingueeTranslator(source='english', target='french').translate(word)
|
241 |
|
242 |
+
# pass language by their abbreviation
|
243 |
+
translated_word = LingueeTranslator(source='en', target='fr').translate(word)
|
244 |
+
|
245 |
+
- Return all synonyms or words that matches
|
246 |
+
|
247 |
+
.. code-block:: python
|
248 |
+
|
249 |
# set the argument return_all to True if you want to get all synonyms of the word to translate
|
250 |
translated_word = LingueeTranslator(source='english', target='french').translate(word, return_all=True)
|
251 |
|
252 |
+
|
253 |
+
Mymemory Translator
|
254 |
+
====================
|
255 |
+
|
256 |
+
.. note::
|
257 |
+
|
258 |
+
You can use the automatic language detection with mymemory by passing
|
259 |
+
"auto" as a value for the source language
|
260 |
|
261 |
.. code-block:: python
|
262 |
|
263 |
+
text = 'Keep it up. You are awesome'
|
264 |
+
|
265 |
+
translated = MyMemoryTranslator(source='auto', target='french').translate(text)
|
266 |
|
267 |
Usage from Terminal
|
268 |
====================
|
|
|
291 |
|
292 |
$ deep_translator -trans "google" -src "en" -tg "de" -txt "happy coding"
|
293 |
|
294 |
+
Side Hint
|
295 |
+
==========
|
296 |
+
|
297 |
+
Generally, I find the google and mymemory translators suitable for translating sentences, whereas
|
298 |
+
the pons and linguee translators are good choices if you want to translate words.
|
299 |
+
|
300 |
========
|
301 |
Links
|
302 |
========
|
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.
|
13 |
|
14 |
__all__ = [GoogleTranslator,
|
15 |
PonsTranslator,
|
|
|
9 |
|
10 |
__author__ = """Nidhal Baccouri"""
|
11 |
__email__ = '[email protected]'
|
12 |
+
__version__ = '1.1.6'
|
13 |
|
14 |
__all__ = [GoogleTranslator,
|
15 |
PonsTranslator,
|
setup.cfg
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
[bumpversion]
|
2 |
-
current_version = 1.1.
|
3 |
commit = True
|
4 |
tag = True
|
5 |
|
|
|
1 |
[bumpversion]
|
2 |
+
current_version = 1.1.6
|
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.
|
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.6',
|
55 |
zip_safe=False,
|
56 |
)
|