plugins_tr.py 763 B

123456789101112131415161718192021222324252627282930313233
  1. import re
  2. import csv
  3. import sys
  4. inFile = sys.argv[1]
  5. outFile = "待翻译.csv"
  6. def extract_strings_from_file(file_path):
  7. pattern = r'tr\(["\']([^"\']*)["\']\)' # 正则表达式模式
  8. strings = []
  9. with open(file_path, "r", encoding="utf-8") as file:
  10. content = file.read()
  11. matches = re.findall(pattern, content) # 使用正则表达式查找匹配项
  12. for match in matches:
  13. strings.append(match)
  14. return strings
  15. tr_strs = extract_strings_from_file(inFile)
  16. lines = [["key", "en_US"]]
  17. for i in tr_strs:
  18. lines.append([i, ""])
  19. with open(outFile, "w", encoding="utf-8", newline="") as f:
  20. writer = csv.writer(f)
  21. for i in lines:
  22. writer.writerow(i)
  23. print("插件翻译完成:\n", inFile)