import argostranslate.translate import argostranslate.package from package_mangement.note_all_packages import write_installed_packages_to_csv def install_language(from_code, to_code): 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_code and x.to_code == to_code, available_packages ) ) # Check if the filtered list is empty if not filtered_packages: print(f"No available package for translating from {from_code} to {to_code}") 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 write_installed_packages_to_csv() return 0 except Exception as e: print(f"An error occurred: {e}") return e