mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-05-10 02:09:46 +08:00
720ebb535d
- 新增深色/浅色模式切换按钮,位于主窗口底部 - 在配置文件中定义主题颜色(浅色/深色背景、列表背景、前景色) - 更新 UI 工具函数以支持动态主题切换,包括列表斑马纹适配 - 添加翻译条目(Dark Mode/Light Mode)并更新编译脚本 - 修改主窗口创建逻辑,集成主题切换回调 - 调整列表背景色属性从 BACKCOLOR 改为 BGCOLOR 以保持一致性
68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
import struct, re, os
|
|
|
|
def compile_po_to_mo(po_path, mo_path):
|
|
with open(po_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
entries = []
|
|
for match in re.finditer(
|
|
r'msgid "(.+?)"\s*\nmsgstr "(.*?)"',
|
|
content, re.DOTALL
|
|
):
|
|
msgid = match.group(1)
|
|
msgstr = match.group(2)
|
|
if msgid:
|
|
entries.append((msgid, msgstr))
|
|
|
|
if not entries:
|
|
print(f'No entries in {po_path}')
|
|
return
|
|
|
|
N = len(entries)
|
|
header_sz = 28
|
|
table_sz = N * 8 * 2
|
|
|
|
orig_off = header_sz + table_sz
|
|
orig_data = b''
|
|
orig_offsets = []
|
|
for eid, estr in entries:
|
|
orig_offsets.append(len(orig_data))
|
|
orig_data += eid.encode('utf-8') + b'\x00'
|
|
|
|
trans_off = orig_off + len(orig_data)
|
|
trans_data = b''
|
|
trans_offsets = []
|
|
for eid, estr in entries:
|
|
trans_offsets.append(len(trans_data))
|
|
trans_data += estr.encode('utf-8') + b'\x00'
|
|
|
|
buf = bytearray()
|
|
buf += struct.pack('<I', 0x950412de)
|
|
buf += struct.pack('<I', 0)
|
|
buf += struct.pack('<I', N)
|
|
buf += struct.pack('<I', orig_off)
|
|
buf += struct.pack('<I', trans_off)
|
|
buf += struct.pack('<I', 0)
|
|
buf += struct.pack('<I', 0)
|
|
|
|
for i in range(N):
|
|
buf += struct.pack('<II', len(entries[i][0].encode('utf-8')), orig_offsets[i])
|
|
for i in range(N):
|
|
buf += struct.pack('<II', len(entries[i][1].encode('utf-8')), trans_offsets[i])
|
|
|
|
buf += orig_data
|
|
buf += trans_data
|
|
|
|
os.makedirs(os.path.dirname(mo_path), exist_ok=True)
|
|
with open(mo_path, 'wb') as f:
|
|
f.write(buf)
|
|
print(f'{po_path} -> {mo_path} ({N} strings)')
|
|
|
|
base = os.path.dirname(os.path.abspath(__file__))
|
|
root = os.path.dirname(base)
|
|
|
|
compile_po_to_mo(os.path.join(root, 'po', 'zh_CN.po'), os.path.join(root, 'locale', 'zh_CN', 'LC_MESSAGES', 'zh_CN.mo'))
|
|
compile_po_to_mo(os.path.join(root, 'po', 'en_US.po'), os.path.join(root, 'locale', 'en_US', 'LC_MESSAGES', 'en_US.mo'))
|
|
compile_po_to_mo(os.path.join(root, 'po', 'zh_CN.po'), os.path.join(root, 'build', 'locale', 'zh_CN', 'LC_MESSAGES', 'zh_CN.mo'))
|
|
compile_po_to_mo(os.path.join(root, 'po', 'en_US.po'), os.path.join(root, 'build', 'locale', 'en_US', 'LC_MESSAGES', 'en_US.mo'))
|