README
🚀 xcstrings-crud
xcstrings-crud 是一款用于对 xcstrings(字符串目录)文件进行 CRUD 操作的命令行工具和 MCP 服务器。它能高效处理包含大量本地化键的大型 xcstrings 文件,为 AI 助手提供了一种节省令牌的方式来操作这些文件。
🚀 快速开始
使用 xcstrings-crud 可以轻松对 xcstrings 文件进行创建、读取、更新和删除操作。无论是通过 MCP 服务器还是命令行工具,都能高效地处理不同规模的 xcstrings 文件。
✨ 主要特性
- 令牌高效:提供有针对性的 CRUD 操作,避免 AI 助手在处理大型 xcstrings 文件时消耗过多令牌。
- 按需查询:可以仅获取所需的特定键或语言,而无需加载整个文件。
- 增量更新:能够在不读取完整内容的情况下添加或更新单个翻译。
- 快速统计:无需解析所有条目即可获取覆盖范围和进度摘要。
📦 安装指南
使用 Mise
mise use -g ubi:Ryu0118/xcstrings-crud
使用 nest (mtj0928/nest)
nest install Ryu0118/xcstrings-crud
从源代码构建
git clone https://github.com/Ryu0118/xcstrings-crud.git
cd xcstrings-crud
swift build -c release
二进制文件将位于 .build/release/xcstrings-crud。
💻 使用示例
MCP 服务器
启动 MCP 服务器
xcstrings-crud mcp
配置
将以下内容添加到你的 Claude Code MCP 设置中:
{
"mcpServers": {
"xcstrings-crud": {
"command": "xcstrings-crud",
"args": ["mcp"]
}
}
}
可用工具
| 工具 | 描述 |
|------|-------------|
| xcstrings_create_file | 创建一个新的 xcstrings 文件 |
| xcstrings_list_keys | 列出所有键 |
| xcstrings_list_languages | 列出支持的语言 |
| xcstrings_list_untranslated | 列出未翻译的键 |
| xcstrings_list_stale | 列出提取状态过时的键 |
| xcstrings_batch_list_stale | 列出多个文件中的过时键 |
| xcstrings_get_source_language | 获取源语言 |
| xcstrings_get_key | 获取某个键的翻译 |
| xcstrings_check_key | 检查键是否存在 |
| xcstrings_check_coverage | 检查键的语言覆盖范围 |
| xcstrings_stats_coverage | 获取整体覆盖统计信息 |
| xcstrings_stats_progress | 按语言获取翻译进度 |
| xcstrings_batch_stats_coverage | 一次性获取多个文件的覆盖范围 |
| xcstrings_batch_check_keys | 检查多个键是否存在 |
| xcstrings_batch_add_translations | 一次性为多个键添加翻译 |
| xcstrings_batch_update_translations | 一次性更新多个键的翻译 |
| xcstrings_add_translation | 为单一语言添加翻译 |
| xcstrings_add_translations | 为多种语言添加翻译 |
| xcstrings_update_translation | 更新单一语言的翻译 |
| xcstrings_update_translations | 更新多种语言的翻译 |
| xcstrings_rename_key | 重命名键 |
| xcstrings_delete_key | 删除整个键 |
| xcstrings_delete_translation | 删除单一语言的翻译 |
| xcstrings_delete_translations | 删除多种语言的翻译 |
CLI 使用
创建操作
# 创建一个新的 xcstrings 文件
xcstrings-crud create path/to/Localizable.xcstrings
# 使用特定源语言创建
xcstrings-crud create path/to/Localizable.xcstrings --source-language ja
# 覆盖现有文件
xcstrings-crud create path/to/Localizable.xcstrings --overwrite
读取操作
# 列出所有键
xcstrings-crud list keys --file path/to/Localizable.xcstrings
# 列出语言
xcstrings-crud list languages --file path/to/Localizable.xcstrings
# 列出某个语言的未翻译键
xcstrings-crud list untranslated --file path/to/Localizable.xcstrings --lang ja
# 列出过时键(可能未使用)
xcstrings-crud list stale --file path/to/Localizable.xcstrings
# 列出多个文件中的过时键
xcstrings-crud batch stale -f file1.xcstrings file2.xcstrings file3.xcstrings
# 获取源语言
xcstrings-crud get source-language --file path/to/Localizable.xcstrings
# 获取某个键的翻译
xcstrings-crud get key "Hello" --file path/to/Localizable.xcstrings
xcstrings-crud get key "Hello" --file path/to/Localizable.xcstrings --lang ja
# 检查键是否存在
xcstrings-crud check key "Hello" --file path/to/Localizable.xcstrings
# 检查键的覆盖范围
xcstrings-crud check coverage "Hello" --file path/to/Localizable.xcstrings
# 获取整体统计信息
xcstrings-crud stats coverage --file path/to/Localizable.xcstrings
# 获取某个语言的进度
xcstrings-crud stats progress --file path/to/Localizable.xcstrings --lang ja
# 获取多个文件的批量覆盖范围
xcstrings-crud stats batch-coverage -f file1.xcstrings file2.xcstrings file3.xcstrings
更新操作
# 添加翻译(单一语言)
xcstrings-crud add key "Hello" --file path/to/Localizable.xcstrings --lang ja --value "こんにちは"
# 添加翻译(多种语言)
xcstrings-crud add key "Hello" --file path/to/Localizable.xcstrings -t ja:こんにちは en:Hello
# 更新翻译(单一语言)
xcstrings-crud update key "Hello" --file path/to/Localizable.xcstrings --lang ja --value "こんにちは!"
# 更新翻译(多种语言)
xcstrings-crud update key "Hello" --file path/to/Localizable.xcstrings -t ja:こんにちは en:Hello de:Hallo
# 重命名键
xcstrings-crud rename key "Hello" --file path/to/Localizable.xcstrings --to "Greeting"
删除操作
# 删除整个键
xcstrings-crud delete key "Hello" --file path/to/Localizable.xcstrings
# 仅删除特定语言的翻译
xcstrings-crud delete key "Hello" --file path/to/Localizable.xcstrings -l ja
# 删除多种语言的翻译
xcstrings-crud delete key "Hello" --file path/to/Localizable.xcstrings -l ja en fr
批量操作
# 列出多个文件中的过时键
xcstrings-crud batch stale -f file1.xcstrings file2.xcstrings file3.xcstrings
# 检查多个键是否存在
xcstrings-crud batch check --file path/to/Localizable.xcstrings -k Hello Goodbye Welcome
# 使用特定语言检查
xcstrings-crud batch check --file path/to/Localizable.xcstrings -k Hello Goodbye -l ja
# 一次性为多个键添加翻译
xcstrings-crud batch add --file path/to/Localizable.xcstrings \
-e "Hello=ja:こんにちは,en:Hello" \
-e "Goodbye=ja:さようなら,en:Goodbye"
# 覆盖添加(替换现有翻译)
xcstrings-crud batch add --file path/to/Localizable.xcstrings --overwrite \
-e "Hello=ja:こんにちは,en:Hello"
# 一次性更新多个键的翻译
xcstrings-crud batch update --file path/to/Localizable.xcstrings \
-e "Hello=ja:こんにちは!,en:Hello!" \
-e "Goodbye=ja:さようなら!"
常用选项
--file <path>:xcstrings 文件路径(必需)--pretty:以美观格式输出 JSON
🔧 技术细节
系统要求
- macOS 13+
- Swift 6.0+
📄 许可证
本项目采用 MIT 许可证。
微信扫一扫