battle_message.c对战文本全汉化

感谢鱼佬、say子、SKT各位
This commit is contained in:
RoamerX 2025-04-19 00:57:06 +08:00
parent 50fe99c11b
commit dcfc7909d0
4 changed files with 861 additions and 804 deletions

Binary file not shown.

View File

@ -0,0 +1,57 @@
import re
import os
from openpyxl import load_workbook
# 文件路径
c_file_path = os.path.abspath(r"c:\Users\Nox\Documents\GitHub\pokeemerald-expansion-Chinese\src\battle_message.c")
xlsx_file_path = os.path.abspath(r"C:\Users\Nox\Documents\GitHub\pokeemerald-expansion-Chinese\python_tools\src\战斗文本.xlsx")
# 读取 xlsx 文件并解析为字典
def load_translations(xlsx_file_path):
translations = {}
workbook = load_workbook(xlsx_file_path)
sheet = workbook.active
for row in sheet.iter_rows(min_row=2, max_col=3, values_only=True): # 从第二行开始读取
if row[0] and row[2]: # 确保第一列和第三列都有内容
key = row[0].strip().lower() # 忽略大小写
value = row[2].strip()
translations[key] = value
return translations
# 替换 C 文件中的内容
def replace_c_file(c_file_path, translations):
with open(c_file_path, "r", encoding="utf-8") as c_file:
lines = c_file.readlines()
updated_lines = []
for line in lines:
# 跳过注释掉的行
if line.strip().startswith("//"):
updated_lines.append(line)
continue
# 查找双引号之间的内容
match = re.search(r'"(.*?)"', line)
if match:
original_text = match.group(1)
# 检查是否有匹配的 key忽略大小写
for key, replacement in translations.items():
if key in line.lower():
# 替换双引号中的内容
escaped_replacement = replacement.replace('"', r'\"') # 保留转义符
line = line[:match.start(1)] + escaped_replacement + line[match.end(1):]
break
updated_lines.append(line)
# 将更新后的内容写回 C 文件
with open(c_file_path, "w", encoding="utf-8") as c_file:
c_file.writelines(updated_lines)
# 主函数
def main():
translations = load_translations(xlsx_file_path)
replace_c_file(c_file_path, translations)
print("替换完成!")
if __name__ == "__main__":
main()

File diff suppressed because it is too large Load Diff

View File

@ -91,8 +91,8 @@ static const u8 sText_BootedUpHM[] = _("启动了秘传招式学习器!");
static const u8 sText_TMHMContainedVar1[] = _("里面有被记录着\n{STR_VAR_1}\p要让宝可梦学会\n{STR_VAR_1}吗?");
static const u8 sText_UsedVar2WildLured[] = _("{PLAYER}\n使用了{STR_VAR_2}\p野生的宝可梦们\n会被引诱过来。{PAUSE_UNTIL_PRESS}");
static const u8 sText_UsedVar2WildRepelled[] = _("{PLAYER}\n使用了{STR_VAR_2}\p野生的宝可梦们\n会被驱赶不再出现。{PAUSE_UNTIL_PRESS}");
static const u8 sText_PlayedPokeFluteCatchy[] = _("{PLAYER}\n吹响了宝可梦之笛!\p嗯……不错的音色{PAUSE_UNTIL_PRESS}");
static const u8 sText_PlayedPokeFlute[] = _("{PLAYER}\n吹响了宝可梦之笛!");
static const u8 sText_PlayedPokeFluteCatchy[] = _("吹响了宝可梦之笛!\p嗯……不错的音色{PAUSE_UNTIL_PRESS}");
static const u8 sText_PlayedPokeFlute[] = _("吹响了宝可梦之笛!");
static const u8 sText_PokeFluteAwakenedMon[] = _("听到宝可梦之笛声音的\n宝可梦醒来了!{PAUSE_UNTIL_PRESS}");
// EWRAM variables