Skip to content

Instantly share code, notes, and snippets.

@qoli
Created June 3, 2025 10:29
Show Gist options
  • Save qoli/30e5f9da0090edf6c61eeebae02bf672 to your computer and use it in GitHub Desktop.
Save qoli/30e5f9da0090edf6c61eeebae02bf672 to your computer and use it in GitHub Desktop.
增加 localizations 字段
import json
def add_localization(filepath):
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
data = json.loads(content)
except json.JSONDecodeError as e:
print(f"JSON 解碼錯誤:{e}")
return
strings = data.get('strings', {})
for key, value in strings.items():
if 'localizations' not in value:
strings[key] = {
"localizations": {
"zh-HK": {
"stringUnit": {
"state": "new",
"value": key
}
}
}
}
data['strings'] = strings
with open(filepath, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
# 範例用法
filepath = 'Localization/Localizable.xcstrings'
add_localization(filepath)
print(f"已完成 {filepath} 的 localizations 增加。")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment