-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
generate_changelog.py
101 lines (91 loc) · 2.7 KB
/
generate_changelog.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
import re
from slpp import slpp as lua
# 找到最新的更新文档
latest_version = 0
for _, _, files in os.walk("Core/Changelog", topdown=False):
for file in files:
version = re.sub(r"(\.lua)|(^.*\.xml)", "", file)
if version and not version == "_template":
version = float(version)
if version > latest_version:
latest_version = version
# 提取更新记录的 lua 字符串
changelog_path = "Core/Changelog/{:.2f}.lua".format(latest_version)
with open(changelog_path, "r", encoding="utf8") as f:
changelog_lua_string = f.read().replace("\n", "")
start_index = changelog_lua_string.find("{")
changelog_lua_string = changelog_lua_string[start_index:]
# 解析 lua table 到 Python dict
changelog = lua.decode(changelog_lua_string)
locales = [
{
"language": "enUS",
"VERSION": "Version",
"IMPORTANT": "Important",
"NEW": "New",
"IMPROVEMENT": "Improvement",
"RELEASED_STRING": "{} Released"
},
{
"language": "zhCN",
"VERSION": "版本",
"IMPORTANT": "重要",
"NEW": "新增",
"IMPROVEMENT": "改善",
"RELEASED_STRING": "{} 发布"
},
{
"language": "zhTW",
"VERSION": "版本",
"IMPORTANT": "重要",
"NEW": "新增",
"IMPROVEMENT": "改善",
"RELEASED_STRING": "{} 發布"
},
{
"language": "koKR",
"VERSION": "버전",
"IMPORTANT": "중요 사항",
"NEW": "신규 사항",
"IMPROVEMENT": "개선 사항",
"RELEASED_STRING": "{} Released"
},
{
"language": "ruRU",
"VERSION": "Версия",
"IMPORTANT": "Важные",
"NEW": "Новые",
"IMPROVEMENT": "Улучшения",
"RELEASED_STRING": "{} Релиз"
}
]
parts = [
{
"emoji": "❗",
"name": "IMPORTANT",
},
{
"emoji": "✳️",
"name": "NEW",
},
{
"emoji": "💪",
"name": "IMPROVEMENT",
}
]
with open("CHANGELOG.md", "w", encoding="utf8") as f:
for locale in locales:
f.write("# {}: {:.2f}\n".format(locale["VERSION"], latest_version))
f.write(locale["RELEASED_STRING"].format(
changelog["RELEASE_DATE"])+"\n")
for part in parts:
try:
if len(changelog[part["name"]]["zhTW"]) > 0:
f.write("## {} {}\n".format(
part["emoji"], locale[part["name"]]))
for line in changelog[part["name"]][locale["language"]]:
f.write("- {}\n".format(line))
except:
pass
f.write("\n------\n")