@langapi/mcp服务器
MCP(模型上下文协议)服务器 LangAPI -基于人工智能的i18n项目翻译管理。
此软件包使Claude、Cursor和VS Code扩展等AI助手能够以编程方式管理项目中的翻译。
快速开始
# 1. Get your API key at https://langapi.io (1,000 free credits)
# 2. Add to your AI tool (example for Claude Desktop on macOS):
# Edit ~/Library/Application Support/Claude/claude_desktop_config.json
# 3. Start chatting:
# "Scan my project for translations"
# "What keys are missing in German?"
# "Sync all translations"特性
- 区域设置检测:自动检测i18n框架(next intl、i18next、react intl、iOS/macOS)和区域设置文件
- 翻译状态:比较源语言环境和目标语言环境以查找缺失的翻译
- 同步翻译:通过基于信用计费的LangAPI翻译丢失的密钥
- 干运行模式:同步前预览更改和成本(默认启用)
- 格式保存:在写入翻译文件时保持JSON格式
- 增量检测:只翻译新的/更改的密钥,节省高达90%的成本
- 苹果本地化:支持iOS/macOS
.strings,.xcstrings,以及.stringsdict文件
安装
npm install @langapi/mcp-server或者直接与npx一起使用(推荐):
npx @langapi/mcp-server______________________________________________________________________
按工具设置
克劳德桌面版
配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 视窗:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
配置:
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key-here"
}
}
}
}编辑后, 重新启动克劳德桌面 以使更改生效。
______________________________________________________________________
克劳德代码(CLI)
选项1:CLI命令 (最快)
# Add to current project (stored in .mcp.json)
claude mcp add langapi \
--env LANGAPI_API_KEY=your-api-key-here \
-- npx -y @langapi/mcp-server
选项2:项目级配置 (推荐给团队)
创建 .mcp.json 在项目根目录中:
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key-here"
}
}
}
}选项3:用户级配置
添加到 ~/.claude.json:
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key-here"
}
}
}
}选项4:环境变量
export LANGAPI_API_KEY="your-api-key-here"然后MCP服务器将自动接收它。
验证连接:
# List configured servers
claude mcp list
# Check server status inside Claude Code
/mcp删除服务器:
claude mcp remove langapi______________________________________________________________________
光标
配置文件位置:
- 项目级别:
.cursor/mcp.json在项目根目录中 - 全球:
~/.cursor/mcp.json
配置:
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key-here"
}
}
}
}替代方案:通过UI
- 打开光标设置(Cmd/Ctrl+,)
- 搜索“MCP”
- 点击“在settings.json中编辑”
- 添加上面的配置
______________________________________________________________________
VS代码与Cline
- 安装 临床扩展
- 创建
.vscode/cline_mcp_settings.json在您的项目中:
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key-here"
}
}
}
}- 重新加载VS代码窗口(Cmd/Ctrl+Shift+P>“重新加载窗口”)
______________________________________________________________________
VS代码与Roo代码
- 安装 Roo代码扩展
- 创建
.vscode/mcp.json在您的项目中:
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key-here"
}
}
}
}- 重新加载VS代码窗口
______________________________________________________________________
帆板运动
配置文件: ~/.codeium/windsurf/mcp_config.json
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key-here"
}
}
}
}编辑后重新启动Windsurf。
______________________________________________________________________
环境变量
| 变量 | 必填 | 描述 |
|---|---|---|
LANGAPI_API_KEY | 是 | 您的LangAPI API密钥(在 langapi.io) |
LANGAPI_API_URL | 否 | 自定义API URL(默认值: https://api.langapi.io) |
______________________________________________________________________
MCP工具
list_local_locales
扫描您的项目以查找区域设置JSON文件,并检测i18n框架。
输入:
{
"project_path": "/path/to/project", // optional, defaults to cwd
"include_key_count": true // optional, default: true
}输出:
{
"framework": "next-intl",
"confidence": "high",
"source_lang": "en",
"locales_path": "messages",
"locales": [
{
"lang": "en",
"files": [{ "path": "messages/en.json", "namespace": null, "key_count": 150 }],
"total_keys": 150
},
{
"lang": "de",
"files": [{ "path": "messages/de.json", "namespace": null, "key_count": 120 }],
"total_keys": 120
}
],
"config_file": "i18n.ts"
}get_translation_status
将源语言环境与目标语言环境进行比较,以识别缺失的键并估算成本。
输入:
{
"source_lang": "en",
"target_langs": ["de", "fr"], // optional, all non-source by default
"project_path": "/path/to/project" // optional
}输出:
{
"source_lang": "en",
"source_keys": 150,
"targets": [
{
"lang": "de",
"status": "outdated",
"keys": { "total": 120, "missing": ["new.key1", "new.key2"], "extra": [] }
}
],
"cost_estimate": {
"words_to_translate": 45,
"credits_required": 90,
"current_balance": 1000,
"balance_after_sync": 910
}
}sync_translations
通过LangAPI API同步翻译。 为了安全起见,默认值为dry_run=true。
输入:
{
"source_lang": "en",
"target_langs": ["de", "fr"],
"dry_run": true, // default: true (preview mode)
"project_path": "/path/to/project", // optional
"write_to_files": true, // optional, default: true
"skip_keys": ["key.to.skip"] // optional, keys to exclude
}输出(dry_run=true):
{
"success": true,
"dry_run": true,
"delta": {
"new_keys": ["new.key1", "new.key2"],
"changed_keys": [],
"total_keys_to_sync": 2
},
"cost": {
"words_to_translate": 45,
"credits_required": 90,
"current_balance": 1000,
"balance_after_sync": 910
},
"message": "Preview: 2 keys to sync, 90 credits required. Run with dry_run=false to execute."
}输出(dry_run=false):
{
"success": true,
"dry_run": false,
"results": [
{ "language": "de", "translated_count": 2, "file_written": "messages/de.json" },
{ "language": "fr", "translated_count": 2, "file_written": "messages/fr.json" }
],
"cost": {
"credits_used": 90,
"balance_after_sync": 1910
},
"message": "Sync complete. 4 keys translated across 2 languages. 90 credits used."
}______________________________________________________________________
提示示例
扫描您的项目
"Scan my project for translations"
"What i18n framework am I using?"
"List all my locale files"
"How many translation keys do I have?"
"What languages are configured in my project?"检查翻译状态
"What translations are missing?"
"Compare English to all other languages"
"How many keys need to be translated for French?"
"Which languages are out of sync?"
"Show me the missing keys for German"
"How much will it cost to sync all languages?"预览更改(模拟运行)
"Preview what would happen if I sync all languages"
"Do a dry run for French translations"
"Show me what keys will be translated"
"What's the cost estimate for syncing German?"
"Preview the sync without making changes"同步翻译
"Sync all missing translations"
"Translate to German and French"
"Update all locale files with missing keys"
"Sync translations and write to files"
"Execute the translation sync"高级操作
"Are there any extra keys in German that aren't in English?"
"Skip the settings.* keys when syncing"
"Only sync the home.* and nav.* keys"
"Sync to Japanese but skip experimental features"完整工作流示例
You: List the translations in my project
Claude: [Calls list_local_locales]
I found a next-intl project with English (150 keys) and German (120 keys) translations.
You: What translations are missing for German?
Claude: [Calls get_translation_status]
German is missing 30 keys. The sync would cost 85 credits (you have 1000 credits).
You: Sync the German translations
Claude: [Calls sync_translations with dry_run=true]
Preview: 30 keys will be translated, costing 85 credits. Should I proceed?
You: Yes, go ahead
Claude: [Calls sync_translations with dry_run=false]
Done! 30 keys translated. German file updated at messages/de.json.______________________________________________________________________
支持的框架
服务器会自动检测这些i18n框架:
| 框架 | 区域设置模式 | 配置文件 |
|---|---|---|
| 下一个intl | messages/*.json, locales/*.json | i18n.ts, next.config.js |
| i18下一页 | public/locales/*/*.json, locales/*/*.json | i18next.config.js, i18n.js |
| 反应intl | src/lang/*.json, lang/*.json | src/i18n.ts |
| iOS/macOS | .strings, .xcstrings, .stringsdict | Info.plist |
| 通用的 | 各种常见模式 | - |
______________________________________________________________________
故障排除
“找不到MCP服务器”
- 确保
npx在你的路径中 - 试着跑步
npx @langapi/mcp-server手动测试 - 在Windows上,您可能需要使用npx的完整路径
“API密钥无效”或“未经授权”
- 在验证您的API密钥 langapi.io/仪表板
- 检查配置中是否有额外的空格或引号
- 确保钥匙已设置在
env节,不args
“找不到区域设置文件”
- 检查您的区域设置文件是否与支持的模式匹配(请参阅上面的框架)
- 验证文件是否为有效的JSON
- 尝试指定
project_path明确地
写入文件时“权限被拒绝”
- 检查文件/目录写入权限
- 在macOS上,确保您的终端具有磁盘访问权限
服务器未连接
- 完全重新启动IDE/工具(而不仅仅是重新加载)
- 检查配置文件语法(有效的JSON?)
- 在工具的开发人员控制台中查找错误消息
试运行正常,但执行失败
- 在langapi.io查看您的信用余额
- 验证与api.langapi.io的网络连接
______________________________________________________________________
高级配置
多个项目
使用项目级配置文件(.mcp.json, .cursor/mcp.json)每个项目具有不同的API密钥。
自定义API URL
对于自托管或企业部署:
{
"mcpServers": {
"langapi": {
"command": "npx",
"args": ["@langapi/mcp-server"],
"env": {
"LANGAPI_API_KEY": "your-api-key",
"LANGAPI_API_URL": "https://your-api-server.com"
}
}
}
}______________________________________________________________________
积分和账单
LangAPI使用基于信用的计费系统:
- 1学分=1个单词 翻译
- 新用户获得 1000免费积分
- 充值 100000学分,15美元 (无订阅,无过期)
获取API密钥: langapi.io.
______________________________________________________________________
许可证
麻省理工学院
