lionbridge_import.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import argparse #To get the source directory from command line arguments.
  4. import os #To find files from the source.
  5. import os.path #To find files from the source and the destination path.
  6. ## Imports translation files from Lionbridge.
  7. #
  8. # Lionbridge has a bit of a weird export feature. It exports it to the same
  9. # file type as what we imported, so that's a .pot file. However this .pot file
  10. # only contains the translations, so the header is completely empty. We need
  11. # to merge those translations into our existing files so that the header is
  12. # preserved.
  13. def lionbridge_import(source: str) -> None:
  14. print("Importing from:", source)
  15. print("Importing to Cura:", destination_cura())
  16. print("Importing to Uranium:", destination_uranium())
  17. ## Gets the destination path to copy the translations for Cura to.
  18. def destination_cura() -> str:
  19. return os.path.abspath(os.path.join(__file__, "..", "..", "resources", "i18n"))
  20. ## Gets the destination path to copy the translations for Uranium to.
  21. def destination_uranium() -> str:
  22. try:
  23. import UM
  24. except ImportError:
  25. relative_path = os.path.join(__file__, "..", "..", "..", "Uranium", "resources", "i18n", "uranium.pot")
  26. print(os.path.abspath(relative_path))
  27. if os.path.exists(relative_path):
  28. return os.path.abspath(relative_path)
  29. else:
  30. raise Exception("Can't find Uranium. Please put UM on the PYTHONPATH or put the Uranium folder next to the Cura folder.")
  31. return os.path.abspath(os.path.join(UM.__file__, "..", "..", "resources", "i18n"))
  32. if __name__ == "__main__":
  33. argparser = argparse.ArgumentParser(description = "Import translation files from Lionbridge.")
  34. argparser.add_argument("source")
  35. args = argparser.parse_args()
  36. lionbridge_import(args.source)