You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5 KiB

  1. #!/usr/bin/env python
  2. """
  3. Author: Sotiris Papadopoulos <ytubedlg@gmail.com>
  4. Last-Revision: 2017-01-30
  5. Script to add support for a new language
  6. Usage : ./new-locale.py <language_code>
  7. Example : ./new-locale.py en_US
  8. """
  9. import os
  10. import sys
  11. import shutil
  12. PACKAGE = "youtube_dl_gui"
  13. LOCALE_PATH_TMPL = os.path.join(PACKAGE, "locale", "{lang}", "LC_MESSAGES")
  14. PO_FILE_TMPL = os.path.join("{parent_dir}", "youtube_dl_gui.po")
  15. def error(msg):
  16. print("[-]{0}".format(msg))
  17. sys.exit(1)
  18. def output(msg):
  19. print("[*]{0}".format(msg))
  20. def manage_directory():
  21. """Allow script calls outside the 'locale_build' dir."""
  22. if os.path.basename(os.getcwd()) == "locale_build":
  23. os.chdir("..")
  24. def main(lang_code):
  25. manage_directory()
  26. target_dir = LOCALE_PATH_TMPL.format(lang=lang_code)
  27. default_dir = LOCALE_PATH_TMPL.format(lang="en_US")
  28. target_po = PO_FILE_TMPL.format(parent_dir=target_dir)
  29. source_po = PO_FILE_TMPL.format(parent_dir=default_dir)
  30. if os.path.exists(target_dir):
  31. error("Locale '{0}' already exists, exiting...".format(lang_code))
  32. output("Creating directory: '{0}'".format(target_dir))
  33. os.makedirs(target_dir)
  34. output("Creating PO file: '{0}'".format(target_po))
  35. shutil.copy(source_po, target_po)
  36. output("Done")
  37. if __name__ == "__main__":
  38. if len(sys.argv) == 2:
  39. main(sys.argv[1])
  40. else:
  41. print("Usage : {0} <language_code>".format(sys.argv[0]))
  42. print("Example : {0} en_US".format(sys.argv[0]))