createplugincontext.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Copyright 2014 Burkhard Lück <lueck@hube-lueck.de>
  5. Permission to use, copy, modify, and distribute this software
  6. and its documentation for any purpose and without fee is hereby
  7. granted, provided that the above copyright notice appear in all
  8. copies and that both that the copyright notice and this
  9. permission notice and warranty disclaimer appear in supporting
  10. documentation, and that the name of the author not be used in
  11. advertising or publicity pertaining to distribution of the
  12. software without specific, written prior permission.
  13. The author disclaim all warranties with regard to this
  14. software, including all implied warranties of merchantability
  15. and fitness. In no event shall the author be liable for any
  16. special, indirect or consequential damages or any damages
  17. whatsoever resulting from loss of use, data or profits, whether
  18. in an action of contract, negligence or other tortious action,
  19. arising out of or in connection with the use or performance of
  20. this software.
  21. """
  22. # This script generates a POT file from a JSON settings file. It
  23. # has been adapted from createjsoncontext.py of KDE's translation
  24. # scripts. It extracts the "label" and "description" values of
  25. # the JSON file using the structure as used by Uranium settings files.
  26. import sys
  27. import os.path
  28. import collections
  29. import json
  30. debugoutput = False #set True to print debug output in scripty's logs
  31. basedir = sys.argv[-1]
  32. pottxt = ""
  33. def appendMessage(file, field, value):
  34. global pottxt
  35. pottxt += "#: {0}\nmsgctxt \"{1}\"\nmsgid \"{2}\"\nmsgstr \"\"\n\n".format(file, field, value.replace("\n", "\\n").replace("\"", "\\\""))
  36. if len(sys.argv) < 3:
  37. print("wrong number of args: %s" % sys.argv)
  38. print("\nUsage: python %s jsonfilenamelist basedir" % os.path.basename(sys.argv[0]))
  39. else:
  40. json_filename = sys.argv[1]
  41. basedir = sys.argv[2]
  42. output_filename = sys.argv[3]
  43. with open(json_filename, "r", encoding = "utf-8") as data_file:
  44. error = False
  45. jsondatadict = json.load(data_file, object_pairs_hook=collections.OrderedDict)
  46. if "name" not in jsondatadict or ("api" not in jsondatadict and "supported_sdk_versions" not in jsondatadict) or "version" not in jsondatadict:
  47. print("The plugin.json file found on %s is invalid, ignoring it" % json_filename)
  48. exit(1)
  49. file = json_filename.replace(basedir, "")
  50. if "description" in jsondatadict:
  51. appendMessage(file, "description", jsondatadict["description"])
  52. if "name" in jsondatadict:
  53. appendMessage(file, "name", jsondatadict["name"])
  54. if pottxt != "":
  55. with open(output_filename, "a", encoding = "utf-8") as output_file:
  56. output_file.write(pottxt)