imgui-mirror/misc/i18n/tools/extract_strings.py
xuk 08f82c56de i18n: move i18n/ to misc/i18n/ to align with misc/ optional module convention
misc/ already hosts optional supplemental modules (cpp/imgui_stdlib,
freetype/, fonts/). i18n fits the same pattern: opt-in, not part of
the core library. Update all include paths, Makefile, Xcode project
and README accordingly.
2026-06-10 14:27:16 +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]))