musfiqdehan commited on
Commit
c313f4e
1 Parent(s): 47622e8

Refactor translation functions to accept target language code

Browse files
Files changed (1) hide show
  1. helper/translators.py +5 -7
helper/translators.py CHANGED
@@ -36,21 +36,19 @@ def get_translated_digit(sentence):
36
 
37
  return "".join(each for each in translated_sentence)
38
 
39
- def google_translation(sentence: str, source="auto", target="") -> str:
40
  """
41
  Translate a sentence from one language to another using Google Translator.\n
42
  At first install dependencies \n
43
  `!pip install -U deep-translator`
44
  """
45
- translator = GoogleTranslator()
46
- translated_sentence = translator.translate(
47
- sentence, source=source, target=target)
48
- return translated_sentence
49
 
50
 
51
- def get_better_translation(src=""):
52
  src_mod = get_translated_digit(src)
53
- tgt = google_translation(src_mod)
54
  tgt = decontracting_words(tgt)
55
  tgt = tgt.replace('rupees', 'takas').replace('Rs', 'takas')
56
  return tgt
 
36
 
37
  return "".join(each for each in translated_sentence)
38
 
39
+ def google_translation(sentence, tgt_lang_code):
40
  """
41
  Translate a sentence from one language to another using Google Translator.\n
42
  At first install dependencies \n
43
  `!pip install -U deep-translator`
44
  """
45
+ translated = GoogleTranslator(source='auto', target=tgt_lang_code).translate(sentence)
46
+ return translated
 
 
47
 
48
 
49
+ def get_better_translation(src, tgt_lang_code):
50
  src_mod = get_translated_digit(src)
51
+ tgt = google_translation(src_mod, tgt_lang_code)
52
  tgt = decontracting_words(tgt)
53
  tgt = tgt.replace('rupees', 'takas').replace('Rs', 'takas')
54
  return tgt