fix: 1.0 发版前安全审查与优化修复 #3
109
scripts/add_aspect_ratio_i18n.py
Normal file
109
scripts/add_aspect_ratio_i18n.py
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
添加画面比例相关的国际化字符串
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# 画面比例的翻译
|
||||||
|
ASPECT_RATIO_STRINGS = {
|
||||||
|
"aspectRatio.original": {
|
||||||
|
"zh-Hans": "原比例",
|
||||||
|
"zh-Hant": "原比例",
|
||||||
|
"en": "Original",
|
||||||
|
"es": "Original",
|
||||||
|
"ar": "الأصلي",
|
||||||
|
"fr": "Original",
|
||||||
|
"ja": "オリジナル",
|
||||||
|
"ko": "원본 비율"
|
||||||
|
},
|
||||||
|
"aspectRatio.lockScreen": {
|
||||||
|
"zh-Hans": "锁屏",
|
||||||
|
"zh-Hant": "鎖屏",
|
||||||
|
"en": "Lock Screen",
|
||||||
|
"es": "Pantalla de bloqueo",
|
||||||
|
"ar": "شاشة القفل",
|
||||||
|
"fr": "Écran de verrouillage",
|
||||||
|
"ja": "ロック画面",
|
||||||
|
"ko": "잠금 화면"
|
||||||
|
},
|
||||||
|
"aspectRatio.fullScreen": {
|
||||||
|
"zh-Hans": "全屏",
|
||||||
|
"zh-Hant": "全屏",
|
||||||
|
"en": "Full Screen",
|
||||||
|
"es": "Pantalla completa",
|
||||||
|
"ar": "ملء الشاشة",
|
||||||
|
"fr": "Plein écran",
|
||||||
|
"ja": "全画面",
|
||||||
|
"ko": "전체 화면"
|
||||||
|
},
|
||||||
|
"aspectRatio.classic": {
|
||||||
|
"zh-Hans": "4:3",
|
||||||
|
"zh-Hant": "4:3",
|
||||||
|
"en": "4:3",
|
||||||
|
"es": "4:3",
|
||||||
|
"ar": "4:3",
|
||||||
|
"fr": "4:3",
|
||||||
|
"ja": "4:3",
|
||||||
|
"ko": "4:3"
|
||||||
|
},
|
||||||
|
"aspectRatio.square": {
|
||||||
|
"zh-Hans": "1:1",
|
||||||
|
"zh-Hant": "1:1",
|
||||||
|
"en": "1:1",
|
||||||
|
"es": "1:1",
|
||||||
|
"ar": "1:1",
|
||||||
|
"fr": "1:1",
|
||||||
|
"ja": "1:1",
|
||||||
|
"ko": "1:1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def add_strings_to_xcstrings(xcstrings_path: str):
|
||||||
|
"""添加字符串到 .xcstrings 文件"""
|
||||||
|
|
||||||
|
# 读取现有文件
|
||||||
|
with open(xcstrings_path, 'r', encoding='utf-8') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
# 添加新字符串
|
||||||
|
added_count = 0
|
||||||
|
skipped_count = 0
|
||||||
|
|
||||||
|
for key, translations in ASPECT_RATIO_STRINGS.items():
|
||||||
|
if key in data['strings']:
|
||||||
|
print(f"⏭️ 跳过已存在的键: {key}")
|
||||||
|
skipped_count += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 创建新条目
|
||||||
|
localizations = {}
|
||||||
|
for lang, text in translations.items():
|
||||||
|
localizations[lang] = {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data['strings'][key] = {
|
||||||
|
"extractionState": "manual",
|
||||||
|
"localizations": localizations
|
||||||
|
}
|
||||||
|
|
||||||
|
print(f"✅ 添加: {key} = {translations['zh-Hans']}")
|
||||||
|
added_count += 1
|
||||||
|
|
||||||
|
# 写回文件
|
||||||
|
with open(xcstrings_path, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
print(f"\n📊 总计: 添加 {added_count} 个键, 跳过 {skipped_count} 个已存在的键")
|
||||||
|
return added_count > 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
xcstrings_path = "to-live-photo/to-live-photo/Localizable.xcstrings"
|
||||||
|
|
||||||
|
success = add_strings_to_xcstrings(xcstrings_path)
|
||||||
|
sys.exit(0 if success else 1)
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -20,11 +20,11 @@ struct RecentWork: Codable, Identifiable, Hashable {
|
|||||||
|
|
||||||
var aspectRatioDisplayName: String {
|
var aspectRatioDisplayName: String {
|
||||||
switch aspectRatioRaw {
|
switch aspectRatioRaw {
|
||||||
case "original": return "原比例"
|
case "original": return String(localized: "aspectRatio.original")
|
||||||
case "lock_screen": return "锁屏"
|
case "lock_screen": return String(localized: "aspectRatio.lockScreen")
|
||||||
case "full_screen": return "全屏"
|
case "full_screen": return String(localized: "aspectRatio.fullScreen")
|
||||||
case "classic": return "4:3"
|
case "classic": return String(localized: "aspectRatio.classic")
|
||||||
case "square": return "1:1"
|
case "square": return String(localized: "aspectRatio.square")
|
||||||
default: return aspectRatioRaw
|
default: return aspectRatioRaw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user