= commited on
Commit
8ab0bea
·
1 Parent(s): f36740b

updated readme

Browse files
Files changed (2) hide show
  1. README.rst +54 -29
  2. deep_translator/mymemory.py +6 -1
README.rst CHANGED
@@ -71,21 +71,21 @@ When you should use it
71
  Why you should use it
72
  ======================
73
 
 
74
  - High level of abstraction
75
  - Automatic language detection
76
  - Easy to use and extend
77
- - It's the only python tool that integrates many translators
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)
87
- * Support for the Linguee translator
88
- * Support for the Mymemory translator
89
  * Automatic single language detection
90
  * Batch language detection
91
  * Translate directly from a text file
@@ -113,6 +113,12 @@ In this section, demos on how to use all different integrated translators in thi
113
  This includes the google, pons, linguee and mymemory translator (at least for now). Perhaps more
114
  translators will be integrated in the future.
115
 
 
 
 
 
 
 
116
  Imports
117
  --------
118
 
@@ -178,13 +184,13 @@ Google Translate
178
 
179
  .. code-block:: python
180
 
181
- translated = GoogleTranslator(source='auto', target='german').translate(text=text)
182
 
183
  - You can pass languages by name:
184
 
185
  .. code-block:: python
186
 
187
- translated = GoogleTranslator(source='english', target='german').translate(text=text)
188
 
189
  - Alternatively, you can pass languages by their abbreviation:
190
 
@@ -202,38 +208,41 @@ Google Translate
202
 
203
  .. code-block:: python
204
 
205
- # or maybe you have many sentences in different languages and want to automate the translation process
206
  translated = GoogleTranslator(source='auto', target='de').translate_sentences([your_list_of_sentences])
207
 
208
 
209
-
210
- PONS Translator
211
- ----------------
212
 
213
  .. note::
214
 
215
- You can pass the languages by the name or by abbreviation just like
216
- previous examples using GoogleTranslate
 
 
 
217
 
218
  .. code-block:: python
219
 
220
- word = 'awesome'
221
 
222
- - Simple Translation
223
 
224
- .. code-block:: python
225
 
226
- translated_word = PonsTranslator(source='english', target='french').translate(word)
227
 
228
- # pass language by their abbreviation
229
- translated_word = PonsTranslator(source='en', target='fr').translate(word)
230
 
231
- - Return all synonyms or words that matches
232
 
233
  .. code-block:: python
234
 
235
- # set the argument return_all to True if you want to get all synonyms of the word to translate
236
- translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
 
237
 
238
 
239
 
@@ -262,19 +271,35 @@ Linguee Translator
262
  translated_word = LingueeTranslator(source='english', target='french').translate(word, return_all=True)
263
 
264
 
265
- Mymemory Translator
266
- --------------------
267
 
268
  .. note::
269
 
270
- You can use the automatic language detection with mymemory by passing
271
- "auto" as a value for the source language
272
 
273
  .. code-block:: python
274
 
275
- text = 'Keep it up. You are awesome'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
 
277
- translated = MyMemoryTranslator(source='auto', target='french').translate(text)
278
 
279
  Usage from Terminal
280
  --------------------
@@ -306,7 +331,7 @@ If you want, you can also pass the source and target language by their abbreviat
306
  Side Hint
307
  ----------
308
 
309
- Generally, I find the google and mymemory translators suitable for translating sentences, whereas
310
  the pons and linguee translators are good choices if you want to translate words.
311
 
312
  ========
 
71
  Why you should use it
72
  ======================
73
 
74
+ - It's the only python tool that integrates many translators
75
  - High level of abstraction
76
  - Automatic language detection
77
  - Easy to use and extend
 
 
78
  - Support for most famous universal translators
79
+ - Stable and maintained regularly
80
 
81
  ========
82
  Features
83
  ========
84
 
85
  * Support for google translate
86
+ * Support for `Pons translator <https://de.pons.com//>`_
87
+ * Support for the `Linguee translator <https://www.linguee.com//>`_
88
+ * Support for the `Mymemory translator <https://mymemory.translated.net//>`_
89
  * Automatic single language detection
90
  * Batch language detection
91
  * Translate directly from a text file
 
113
  This includes the google, pons, linguee and mymemory translator (at least for now). Perhaps more
114
  translators will be integrated in the future.
115
 
116
+ .. note::
117
+
118
+ You can always pass the languages by the name or by abbreviation.
119
+
120
+ *Example*: If you want to use english as a source or target language, you can pass **english** or **en** as an argument
121
+
122
  Imports
123
  --------
124
 
 
184
 
185
  .. code-block:: python
186
 
187
+ translated = GoogleTranslator(source='auto', target='de').translate(text=text)
188
 
189
  - You can pass languages by name:
190
 
191
  .. code-block:: python
192
 
193
+ translated = GoogleTranslator(source='auto', target='german').translate(text=text)
194
 
195
  - Alternatively, you can pass languages by their abbreviation:
196
 
 
208
 
209
  .. code-block:: python
210
 
211
+ # this is useful if you have many sentences in different languages and want to automate the translation process
212
  translated = GoogleTranslator(source='auto', target='de').translate_sentences([your_list_of_sentences])
213
 
214
 
215
+ Mymemory Translator
216
+ --------------------
 
217
 
218
  .. note::
219
 
220
+ As in google translate, you can use the automatic language detection with mymemory by using "auto" as an
221
+ argument for the source language. However, this feature in the mymemory translator is not so powerful as
222
+ in google translate.
223
+
224
+ - Simple translation
225
 
226
  .. code-block:: python
227
 
228
+ text = 'Keep it up. You are awesome'
229
 
230
+ translated = MyMemoryTranslator(source='auto', target='french').translate(text)
231
 
232
+ - Translate a list of sentences or paragraphs
233
 
234
+ .. code-block:: python
235
 
236
+ texts = ["hallo welt", "guten morgen"]
237
+ translated = MyMemoryTranslator('de', 'english').translate_sentences(texts)
238
 
239
+ - Translate from file
240
 
241
  .. code-block:: python
242
 
243
+ path = "your_file.txt"
244
+
245
+ translated = MyMemoryTranslator(source='en', target='fr').translate_file(path)
246
 
247
 
248
 
 
271
  translated_word = LingueeTranslator(source='english', target='french').translate(word, return_all=True)
272
 
273
 
274
+ PONS Translator
275
+ ----------------
276
 
277
  .. note::
278
 
279
+ You can pass the languages by the name or by abbreviation just like
280
+ previous examples using GoogleTranslate
281
 
282
  .. code-block:: python
283
 
284
+ word = 'awesome'
285
+
286
+ - Simple Translation
287
+
288
+ .. code-block:: python
289
+
290
+ translated_word = PonsTranslator(source='english', target='french').translate(word)
291
+
292
+ # pass language by their abbreviation
293
+ translated_word = PonsTranslator(source='en', target='fr').translate(word)
294
+
295
+ - Return all synonyms or words that matches
296
+
297
+ .. code-block:: python
298
+
299
+ # set the argument return_all to True if you want to get all synonyms of the word to translate
300
+ translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
301
+
302
 
 
303
 
304
  Usage from Terminal
305
  --------------------
 
331
  Side Hint
332
  ----------
333
 
334
+ Generally, I find the google and mymemory translators suitable for translating texts/paragraphs, whereas
335
  the pons and linguee translators are good choices if you want to translate words.
336
 
337
  ========
deep_translator/mymemory.py CHANGED
@@ -24,7 +24,6 @@ class MyMemoryTranslator(BaseTranslator):
24
  self._source, self._target = self._map_language_to_code(source.lower(), target.lower())
25
  self._source = self._source if self._source != 'auto' else 'Lao'
26
 
27
- print(self._source, self._target)
28
  self.email = kwargs.get('email', None)
29
  super(MyMemoryTranslator, self).__init__(base_url=self.__base_url,
30
  source=self._source,
@@ -143,3 +142,9 @@ class MyMemoryTranslator(BaseTranslator):
143
  return self.translate(text=text)
144
  except Exception as e:
145
  raise e
 
 
 
 
 
 
 
24
  self._source, self._target = self._map_language_to_code(source.lower(), target.lower())
25
  self._source = self._source if self._source != 'auto' else 'Lao'
26
 
 
27
  self.email = kwargs.get('email', None)
28
  super(MyMemoryTranslator, self).__init__(base_url=self.__base_url,
29
  source=self._source,
 
142
  return self.translate(text=text)
143
  except Exception as e:
144
  raise e
145
+
146
+
147
+ if __name__ == '__main__':
148
+
149
+ res = MyMemoryTranslator('de', 'english').translate_sentences(["hallo welt", "guten morgen"])
150
+ print(res)