str-csv.py 1.0 KB

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