This repository was archived by the owner on Jun 18, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcsgo_translation_update.py
More file actions
68 lines (57 loc) · 2.71 KB
/
Copy pathcsgo_translation_update.py
File metadata and controls
68 lines (57 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import re
import os
import shutil
from datetime import datetime
import zipfile
# 读取csgo_colormod.txt文件
with open("workflow/csgo_colormod.txt", "r", encoding="utf-8") as colormod_file:
colormod_data = colormod_file.read()
# 创建一个字典来存储csgo_colormod.txt的'a'和'b'对应关系
colormod_dict = {}
for match in re.finditer(r'"([^"]+)"\s+"([^"]+)"', colormod_data):
a, b = match.groups()
colormod_dict[a] = b
# 读取csgo_schinese.txt文件
with open("workflow/csgo_schinese.txt", "r", encoding="utf-8") as schinese_file:
schinese_data = schinese_file.read()
# 执行替换操作
for a, b in colormod_dict.items():
pattern = fr'"{a}"\s+"([^"]+)"'
schinese_data = re.sub(pattern, fr'"{a}"\t"{b}"', schinese_data)
# # 写入开头的注释和更新时间(报错)
# current_time = datetime.now().strftime("%Y%m%d%H%M%S") # 使用datetime类
# current_time_formatted = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 格式化的时间
# header = f"""// Text Color Mod
# // Orel 和 spddl 的原始想法,柠檬味雪碧的原始中文翻译。
# // 自 1.0 版起,由 Maxim(MrMaxim / BananaGaming)重新编写和编辑。
# // 自 4.2 版起,由 何仙姑 (https://space.bilibili.com/21249030)重新接手中文翻译。
# // 最新版本下载地址 https://csgo.gkd.plus/textmod?mod
# // 当前版本构建时间:{current_time_formatted} ,请注意更新
#
# """
# schinese_data = header + schinese_data
#
# # 将 "Language" "English" 改为 "Language" "schinese"
# schinese_data = re.sub(r'"Language"\s+"English"', r'"Language" "schinese"', schinese_data)
# 查找无法匹配的项目
unmatched_items = [a for a in colormod_dict if a not in schinese_data]
# 将替换后的数据写入新文件并保存到out目录
output_dir = "workflow/out"
if not os.path.exists(output_dir):
os.makedirs(output_dir)
output_file_path = os.path.join(output_dir, "csgo_schinese.txt")
with open(output_file_path, "w", encoding="utf-8") as output_file:
output_file.write(schinese_data)
# 输出无法匹配的项目
print("无法匹配的项目:")
for item in unmatched_items:
print(item)
# 创建一个zip文件并将csgo_schinese.txt和使用说明.txt添加到其中
output_zip_path = "workflow/out/CS2-TextMod.zip"
# Create a ZIP archive
with zipfile.ZipFile(output_zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
# Write the output file with arcname as "csgo_schinese.txt" (root directory level)
zipf.write(output_file_path, "csgo_schinese.txt")
# Write "使用说明.txt" with arcname as the same (root directory level)
zipf.write("workflow/out/使用说明.txt", "使用说明.txt")
print("任务完成。替换后的文件已保存在 'workflow/out/csgo_schinese.txt' 中。")