33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import sys
|
|
from translate import translate
|
|
from package_mangement.downlaod_languages import install_language
|
|
from package_mangement.check_packages import check_languages_installed
|
|
from create_response import create_respone
|
|
|
|
def main():
|
|
message = sys.argv[1]
|
|
from_lang = sys.argv[2]
|
|
to_lang = sys.argv[3]
|
|
|
|
# Check if languages are installed
|
|
is_installed = check_languages_installed(from_lang, to_lang)
|
|
|
|
if not is_installed:
|
|
# Attempt to install the languages
|
|
installed = install_language(from_lang, to_lang)
|
|
if installed != 0:
|
|
# Installation failed
|
|
error = "Error: Installation failed"
|
|
create_respone("None", from_lang, to_lang, error)
|
|
return # Exit the function early
|
|
|
|
# Languages are installed or installation succeeded
|
|
translated = translate(message, from_lang, to_lang)
|
|
if translated:
|
|
create_respone(translated, from_lang, to_lang, error = "None")
|
|
else:
|
|
create_respone("None", from_lang, to_lang, error = "Could not translate it.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|