xcstring积垢
CLI工具和MCP服务器,用于对xcstring(字符串目录)文件进行CRUD操作。
动机
大型xcstring文件可以包含数千个跨多种语言的本地化键,从而产生大量的JSON文件。当人工智能助手(如Claude Code)直接读取这些文件时,它们会消耗大量代币——可能超过上下文限制或迅速耗尽代币预算。
此工具提供 令牌高效 通过提供有针对性的CRUD操作:
- 只查询您需要的内容:获取特定密钥或语言,而不是加载整个文件
- 增量更新:在不阅读完整内容的情况下添加或更新单个翻译
- 快速统计:无需解析所有条目即可获取覆盖率和进度摘要
- 字符串目录语义:保留Xcode元数据,例如
shouldTranslate,并从不翻译列表和覆盖率总计中排除不可翻译的密钥 - 字符串目录元数据:在读写操作期间保留Xcode元数据,如自动生成的注释
通过使用MCP服务器或CLI,AI助手可以处理任何大小的xcstring文件,同时将令牌使用量降至最低。
安装
使用Mise
mise use -g ubi:Ryu0118/xcstrings-crud使用巢(mtj0928/巢)
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 | 创建新的xcstring文件 |
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 | 检查钥匙是否存在;当未找到NFKC等效密钥时,建议使用 |
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使用情况
创建操作
# Create a new xcstrings file
xcstrings-crud create path/to/Localizable.xcstrings
# Create with specific source language
xcstrings-crud create path/to/Localizable.xcstrings --source-language ja
# Overwrite existing file
xcstrings-crud create path/to/Localizable.xcstrings --overwrite读取操作
# List all keys
xcstrings-crud list keys --file path/to/Localizable.xcstrings
# List languages
xcstrings-crud list languages --file path/to/Localizable.xcstrings
# List untranslated keys for a language
xcstrings-crud list untranslated --file path/to/Localizable.xcstrings --lang ja
# Keys marked `"shouldTranslate": false` are omitted from untranslated results.
# List stale keys (potentially unused)
xcstrings-crud list stale --file path/to/Localizable.xcstrings
# List stale keys across multiple files
xcstrings-crud batch stale -f file1.xcstrings file2.xcstrings file3.xcstrings
# Get source language
xcstrings-crud get source-language --file path/to/Localizable.xcstrings
# Get translations for a key
xcstrings-crud get key "Hello" --file path/to/Localizable.xcstrings
xcstrings-crud get key "Hello" --file path/to/Localizable.xcstrings --lang ja
# Check if key exists
xcstrings-crud check key "Hello" --file path/to/Localizable.xcstrings
# Check key coverage
xcstrings-crud check coverage "Hello" --file path/to/Localizable.xcstrings
# Non-translatable keys are treated as complete.
# Get overall statistics
xcstrings-crud stats coverage --file path/to/Localizable.xcstrings
# Coverage totals exclude keys marked `"shouldTranslate": false`.
# Get progress for a language
xcstrings-crud stats progress --file path/to/Localizable.xcstrings --lang ja
# Get batch coverage for multiple files
xcstrings-crud stats batch-coverage -f file1.xcstrings file2.xcstrings file3.xcstrings更新操作
# Add translation (single language)
xcstrings-crud add key "Hello" --file path/to/Localizable.xcstrings --lang ja --value "こんにちは"
# Add translation (multiple languages)
xcstrings-crud add key "Hello" --file path/to/Localizable.xcstrings -t ja:こんにちは en:Hello
# Update translation (single language)
xcstrings-crud update key "Hello" --file path/to/Localizable.xcstrings --lang ja --value "こんにちは!"
# Update translations (multiple languages)
xcstrings-crud update key "Hello" --file path/to/Localizable.xcstrings -t ja:こんにちは en:Hello de:Hallo
# Rename key
xcstrings-crud rename key "Hello" --file path/to/Localizable.xcstrings --to "Greeting"删除操作
# Delete entire key
xcstrings-crud delete key "Hello" --file path/to/Localizable.xcstrings
# Delete translation for specific language only
xcstrings-crud delete key "Hello" --file path/to/Localizable.xcstrings -l ja
# Delete translations for multiple languages
xcstrings-crud delete key "Hello" --file path/to/Localizable.xcstrings -l ja en fr批量操作
# List stale keys across multiple files
xcstrings-crud batch stale -f file1.xcstrings file2.xcstrings file3.xcstrings
# Check if multiple keys exist
xcstrings-crud batch check --file path/to/Localizable.xcstrings -k Hello Goodbye Welcome
# Check with specific language
xcstrings-crud batch check --file path/to/Localizable.xcstrings -k Hello Goodbye -l ja
# Add translations for multiple keys at once
xcstrings-crud batch add --file path/to/Localizable.xcstrings \
-e "Hello=ja:こんにちは,en:Hello" \
-e "Goodbye=ja:さようなら,en:Goodbye"
# Add with overwrite (replace existing translations)
xcstrings-crud batch add --file path/to/Localizable.xcstrings --overwrite \
-e "Hello=ja:こんにちは,en:Hello"
# Update translations for multiple keys at once
xcstrings-crud batch update --file path/to/Localizable.xcstrings \
-e "Hello=ja:こんにちは!,en:Hello!" \
-e "Goodbye=ja:さようなら!"常用选项
- `--file
`:xcstring文件路径(必需)
--pretty:打印精美的JSON输出
需求
- macOS 13+
- Swift 6.0+
许可证
麻省理工学院
