nidhal baccouri commited on
Commit
0f08209
·
1 Parent(s): e4473fe

added invalid source-target exception

Browse files
deep_translator/exceptions.py CHANGED
@@ -36,6 +36,18 @@ class NotValidPayload(BaseError):
36
  super(NotValidPayload, self).__init__(val, message)
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  class TranslationNotFound(BaseError):
40
  """
41
  exception thrown if no translation was found for the text provided by the user
 
36
  super(NotValidPayload, self).__init__(val, message)
37
 
38
 
39
+ class InvalidSourceOrTargetLanguage(BaseError):
40
+ """
41
+ exception thrown if the user enters an invalid payload
42
+ """
43
+
44
+ def __init__(self,
45
+ val,
46
+ message="source and target language can't be the same"):
47
+ super(InvalidSourceOrTargetLanguage, self).__init__(val, message)
48
+
49
+
50
+
51
  class TranslationNotFound(BaseError):
52
  """
53
  exception thrown if no translation was found for the text provided by the user
deep_translator/google_trans.py CHANGED
@@ -173,3 +173,6 @@ class GoogleTranslator(BaseTranslator):
173
  return arr
174
 
175
 
 
 
 
 
173
  return arr
174
 
175
 
176
+ # if __name__ == '__main__':
177
+ # text = GoogleTranslator(source="en", target="en").translate("how are you")
178
+ # print(text)
deep_translator/parent.py CHANGED
@@ -1,6 +1,6 @@
1
  """parent translator class"""
2
 
3
- from deep_translator.exceptions import NotValidPayload, NotValidLength
4
  from abc import ABC, abstractmethod
5
  import string
6
 
@@ -21,6 +21,9 @@ class BaseTranslator(ABC):
21
  @param source: source language to translate from
22
  @param target: target language to translate to
23
  """
 
 
 
24
  self.__base_url = base_url
25
  self._source = source
26
  self._target = target
 
1
  """parent translator class"""
2
 
3
+ from deep_translator.exceptions import NotValidPayload, NotValidLength, InvalidSourceOrTargetLanguage
4
  from abc import ABC, abstractmethod
5
  import string
6
 
 
21
  @param source: source language to translate from
22
  @param target: target language to translate to
23
  """
24
+ if source == target:
25
+ raise InvalidSourceOrTargetLanguage(source)
26
+
27
  self.__base_url = base_url
28
  self._source = source
29
  self._target = target