str-csv.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import csv
  2. import os
  3. import sys
  4. try:
  5. path = sys.argv[1]
  6. except:
  7. print("Please input the path of the csv file.")
  8. strs = []
  9. with open(path, mode="r", newline="", encoding="utf-8") as f:
  10. reader = csv.reader(f)
  11. for row in reader:
  12. strs.append(row)
  13. if not os.path.exists("lang/"):
  14. os.makedirs("lang/")
  15. with open("lang/english.lng", "w", encoding="utf-8") as f:
  16. f.write("##grflangid 0x01" + "\n")
  17. for i in range(len(strs)):
  18. if strs[i][1] == "":
  19. f.write(strs[i][0] + "\n")
  20. else:
  21. f.write(f"{strs[i][0]:48} {':' + strs[i][1]:<10}\n")
  22. def other_lang_generate(lang_name, lang_row, lang_code):
  23. with open("lang/" + lang_name + ".lng", "w", encoding="utf-8") as f:
  24. f.write("##grflangid " + lang_code + "\n")
  25. for i in range(len(strs)):
  26. if strs[i][lang_row] == "":
  27. if strs[i][1] == "":
  28. f.write(strs[i][0] + "\n")
  29. else:
  30. pass
  31. else:
  32. f.write(f"{strs[i][0]:48} {':' + strs[i][2]:<10}\n")
  33. other_lang_generate("simplified_chinese", 2, "0x56")