#!/usr/bin/env python3 """添加遗漏的硬编码字符串的多语言翻译""" import json # 14个新增字符串的多语言翻译 NEW_STRINGS = { "processing.cancelling": { "zh-Hans": "正在取消...", "zh-Hant": "正在取消...", "en": "Cancelling...", "es": "Cancelando...", "ar": "جارٍ الإلغاء...", "fr": "Annulation...", "ja": "キャンセル中...", "ko": "취소 중..." }, "processing.failed": { "zh-Hans": "生成失败", "zh-Hant": "生成失敗", "en": "Generation Failed", "es": "Error al generar", "ar": "فشل الإنشاء", "fr": "Échec de la génération", "ja": "生成に失敗", "ko": "생성 실패" }, "processing.suggestions": { "zh-Hans": "建议", "zh-Hant": "建議", "en": "Suggestions", "es": "Sugerencias", "ar": "اقتراحات", "fr": "Suggestions", "ja": "提案", "ko": "제안" }, "editor.aspectRatioTitle": { "zh-Hans": "画面比例", "zh-Hant": "畫面比例", "en": "Aspect Ratio", "es": "Relación de aspecto", "ar": "نسبة العرض", "fr": "Rapport d'aspect", "ja": "アスペクト比", "ko": "화면 비율" }, "editor.aspectRatioHint": { "zh-Hans": "选择适合壁纸的比例,锁屏推荐使用「锁屏」或「全屏」", "zh-Hant": "選擇適合桌布的比例,鎖定畫面建議使用「鎖定畫面」或「全螢幕」", "en": "Choose a ratio suitable for wallpaper. 'Lock Screen' or 'Full Screen' is recommended", "es": "Elige una proporción adecuada. Se recomienda 'Pantalla de bloqueo' o 'Pantalla completa'", "ar": "اختر نسبة مناسبة للخلفية. يُوصى بـ 'شاشة القفل' أو 'ملء الشاشة'", "fr": "Choisissez un ratio adapté. 'Écran verrouillé' ou 'Plein écran' est recommandé", "ja": "壁紙に適した比率を選択してください。「ロック画面」または「全画面」を推奨", "ko": "배경화면에 적합한 비율을 선택하세요. '잠금 화면' 또는 '전체 화면'을 권장합니다" }, "editor.coverFrameTitle": { "zh-Hans": "封面帧预览", "zh-Hant": "封面影格預覽", "en": "Cover Frame Preview", "es": "Vista previa del cuadro de portada", "ar": "معاينة الإطار الرئيسي", "fr": "Aperçu de l'image de couverture", "ja": "カバーフレームのプレビュー", "ko": "커버 프레임 미리보기" }, "onboarding.skip": { "zh-Hans": "跳过", "zh-Hant": "跳過", "en": "Skip", "es": "Omitir", "ar": "تخطي", "fr": "Ignorer", "ja": "スキップ", "ko": "건너뛰기" }, "home.loadError": { "zh-Hans": "加载失败: %@", "zh-Hant": "載入失敗:%@", "en": "Loading failed: %@", "es": "Error de carga: %@", "ar": "فشل التحميل: %@", "fr": "Échec du chargement : %@", "ja": "読み込みに失敗しました:%@", "ko": "로드 실패: %@" }, "result.saved": { "zh-Hans": "Live Photo 已保存", "zh-Hant": "Live Photo 已儲存", "en": "Live Photo Saved", "es": "Live Photo guardada", "ar": "تم حفظ Live Photo", "fr": "Live Photo enregistrée", "ja": "Live Photoを保存しました", "ko": "Live Photo가 저장되었습니다" }, "result.saveFailed": { "zh-Hans": "保存失败", "zh-Hant": "儲存失敗", "en": "Save Failed", "es": "Error al guardar", "ar": "فشل الحفظ", "fr": "Échec de l'enregistrement", "ja": "保存に失敗", "ko": "저장 실패" }, "wallpaper.savedToLibrary": { "zh-Hans": "Live Photo 已保存到相册", "zh-Hant": "Live Photo 已儲存至相簿", "en": "Live Photo saved to library", "es": "Live Photo guardada en la biblioteca", "ar": "تم حفظ Live Photo في المكتبة", "fr": "Live Photo enregistrée dans la bibliothèque", "ja": "Live Photoをライブラリに保存しました", "ko": "라이브러리에 Live Photo가 저장되었습니다" }, "wallpaper.deviceSupport": { "zh-Hans": "你的设备支持锁屏动态壁纸", "zh-Hant": "你的裝置支援鎖定畫面動態桌布", "en": "Your device supports lock screen live wallpaper", "es": "Tu dispositivo admite fondos animados en pantalla de bloqueo", "ar": "جهازك يدعم خلفية شاشة القفل الحية", "fr": "Votre appareil prend en charge le fond d'écran animé sur l'écran verrouillé", "ja": "お使いのデバイスはロック画面のライブ壁紙に対応しています", "ko": "기기에서 잠금 화면 라이브 배경화면을 지원합니다" }, "wallpaper.doneButton": { "zh-Hans": "完成,返回首页", "zh-Hant": "完成,返回首頁", "en": "Done, Return to Home", "es": "Listo, volver al inicio", "ar": "تم، العودة إلى الصفحة الرئيسية", "fr": "Terminé, retour à l'accueil", "ja": "完了、ホームに戻る", "ko": "완료, 홈으로 돌아가기" }, "wallpaper.canAlwaysCreate": { "zh-Hans": "你可以随时制作新的 Live Photo", "zh-Hant": "你可以隨時製作新的 Live Photo", "en": "You can create new Live Photos anytime", "es": "Puedes crear nuevas Live Photos en cualquier momento", "ar": "يمكنك إنشاء Live Photos جديدة في أي وقت", "fr": "Vous pouvez créer de nouvelles Live Photos à tout moment", "ja": "いつでも新しいLive Photoを作成できます", "ko": "언제든지 새로운 Live Photo를 만들 수 있습니다" } } 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) # 添加新字符串 added_count = 0 for key, translations in NEW_STRINGS.items(): if key in data["strings"]: print(f"⚠️ Key '{key}' already exists, skipping...") continue # 构建localizations对象 localizations = {} for lang, value in translations.items(): localizations[lang] = { "stringUnit": { "state": "translated", "value": value } } # 添加到strings中 data["strings"][key] = { "extractionState": "manual", "localizations": localizations } added_count += 1 print(f"✅ Added: {key}") # 写回文件(保持格式化) with open(xcstrings_path, 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=2) print(f"\n🎉 Successfully added {added_count} new localization keys!") print(f"📁 Updated: {xcstrings_path}") if __name__ == "__main__": main()