Bighnesh Sahoo
commited on
Commit
·
b96c7cf
1
Parent(s):
bda0d63
addded cli functionality to return the languages supported by the chosen translator service
Browse files- deep_translator/cli.py +30 -5
deep_translator/cli.py
CHANGED
@@ -30,6 +30,27 @@ def translate(args):
|
|
30 |
print(" | Translation from {} to {} |".format(args.source, args.target))
|
31 |
print("Translated text: \n {}".format(res))
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def main():
|
35 |
"""
|
@@ -38,13 +59,17 @@ def main():
|
|
38 |
"""
|
39 |
parser = argparse.ArgumentParser()
|
40 |
parser.add_argument('--translator', '-trans',
|
41 |
-
default='google', type=str, help="name of the translator you want to use")
|
42 |
-
parser.add_argument('--source', '-src', type=str, help="source language to translate from"
|
43 |
-
parser.add_argument('--target', '-tg', type=str, help="target language to translate to"
|
44 |
-
parser.add_argument('--text', '-txt', type=str, help="text you want to translate"
|
|
|
45 |
|
46 |
args = parser.parse_args()
|
47 |
-
|
|
|
|
|
|
|
48 |
# sys.exit()
|
49 |
|
50 |
|
|
|
30 |
print(" | Translation from {} to {} |".format(args.source, args.target))
|
31 |
print("Translated text: \n {}".format(res))
|
32 |
|
33 |
+
def return_supported_languages(args):
|
34 |
+
"""
|
35 |
+
function used to return the languages supported by the translator service from the parsed terminal arguments
|
36 |
+
@param args: parsed terminal arguments
|
37 |
+
@return: None
|
38 |
+
"""
|
39 |
+
if args.translator == 'google':
|
40 |
+
translator = GoogleTranslator
|
41 |
+
elif args.translator == 'pons':
|
42 |
+
translator = PonsTranslator
|
43 |
+
elif args.translator == 'linguee':
|
44 |
+
translator = LingueeTranslator
|
45 |
+
elif args.translator == 'mymemory':
|
46 |
+
translator = MyMemoryTranslator
|
47 |
+
else:
|
48 |
+
print("given translator is not supported. Please use a supported translator from the deep_translator tool")
|
49 |
+
|
50 |
+
translator_supported_languages = translator.get_supported_languages(as_dict=True)
|
51 |
+
print(f'Languages supported by \'{args.translator}\' are :\n')
|
52 |
+
print(translator_supported_languages)
|
53 |
+
|
54 |
|
55 |
def main():
|
56 |
"""
|
|
|
59 |
"""
|
60 |
parser = argparse.ArgumentParser()
|
61 |
parser.add_argument('--translator', '-trans',
|
62 |
+
default='google', type=str, help="name of the translator you want to use", required=True)
|
63 |
+
parser.add_argument('--source', '-src', type=str, help="source language to translate from")
|
64 |
+
parser.add_argument('--target', '-tg', type=str, help="target language to translate to")
|
65 |
+
parser.add_argument('--text', '-txt', type=str, help="text you want to translate")
|
66 |
+
parser.add_argument('--languages', '-lang',action='store_true', help="all the languages available with the translator. Run the command deep_translator -trans <translator service> -lang")
|
67 |
|
68 |
args = parser.parse_args()
|
69 |
+
if args.languages:
|
70 |
+
return_supported_languages(args)
|
71 |
+
else:
|
72 |
+
translate(args)
|
73 |
# sys.exit()
|
74 |
|
75 |
|