Files
to-live-photo/scripts/clean_redundant_keys.py

40 lines
1.1 KiB
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
"""清理Localizable.xcstrings中的冗余本地化key"""
import json
# 需要删除的冗余key这些是占位符或自动生成的无用条目
REDUNDANT_KEYS = [
"%lld",
"%lld%%",
"",
"accessibility.aspectRatio %@" # 与 accessibility.aspectRatio 重复
]
def main():
xcstrings_path = "/Users/yuanjiantsui/projects/to-live-photo/to-live-photo/to-live-photo/Localizable.xcstrings"
# 读取现有文件
with open(xcstrings_path, 'r', encoding='utf-8') as f:
data = json.load(f)
# 删除冗余key
removed_count = 0
for key in REDUNDANT_KEYS:
if key in data["strings"]:
del data["strings"][key]
removed_count += 1
print(f"✅ Removed: {key}")
else:
print(f"⚠️ Key '{key}' not found, skipping...")
# 写回文件(保持格式化)
with open(xcstrings_path, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
print(f"\n🎉 Successfully removed {removed_count} redundant keys!")
print(f"📁 Updated: {xcstrings_path}")
if __name__ == "__main__":
main()