imgui-mirror/i18n/tools/extract_strings.py
xuk 22c87d2bf7 i18n: add runtime language switching infrastructure
- Add i18n/ module: imgui_i18n.h (Tr() macro + stub when disabled),
  imgui_i18n.cpp (lookup table, Meyers singleton, placeholder substitution),
  locale/zh_CN.cpp (Simplified Chinese translation table),
  tools/extract_strings.py (helper to extract translatable strings)
- Opt-in via IMGUI_DEMO_ENABLE_I18N build flag; without it Tr(s) expands
  to (s) at compile time with zero overhead and no extra dependencies
- See i18n/README.md for integration guide and how to add a new language
2026-06-08 11:22:10 +08:00

26 lines
799 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
用法:python3 extract_strings.py imgui_demo.cpp 302 737
输出 zh_CN.cpp 条目骨架(key=英文,value 留空供人工翻译)
"""
import sys, re
def extract(path, start, end):
with open(path) as f:
lines = f.readlines()
chunk = ''.join(lines[start-1:end-1])
strings = re.findall(r'"([^"\n]{2,80})"', chunk)
seen = set()
results = []
skip = re.compile(r'^(##|###|%[0-9.]*[dfsx]$|[0-9.]+$)')
for s in strings:
if s in seen or skip.match(s): continue
seen.add(s)
results.append(s)
for s in results:
escaped = s.replace('\\', '\\\\').replace('"', '\\"')
print(f' {{"{escaped}", ""}},')
if __name__ == '__main__':
extract(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))