35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
|
import argostranslate.translate
|
||
|
import argostranslate.package
|
||
|
from note_all_packages import write_installed_packages_to_csv
|
||
|
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
|
||
|
write_installed_packages_to_csv()
|
||
|
print("Finished Download")
|
||
|
|
||
|
except Exception as e:
|
||
|
return e
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
install_language()
|