import argostranslate.translate import argostranslate.package import sys def install_language(): from_lang = sys.argv[1] to_lang = sys.argv[2] try: argostranslate.package.update_package_index() available_packages = argostranslate.package.get_available_packages() # Convert the filter result into a list filtered_packages = list( filter( lambda x: x.from_code == from_lang and x.to_code == to_lang, available_packages ) ) # Check if the filtered list is empty if not filtered_packages: return 1 # If we have at least one package, proceed to download and install available_package = filtered_packages[0] download_path = available_package.download() argostranslate.package.install_from_path(download_path) # After successful installation, append package details to the CSV file print(f"Finished Download, now you can translate from {from_lang} to {to_lang}") except Exception as e: return e if __name__ == "__main__": install_language()