内容
# Polylang MCP 服务器
一款 WordPress 插件,允许 AI 助手(Claude、Cursor、VS Code 等)翻译整个 Polylang 支持的网站 — 文章、页面、自定义文章类型、分类、标签和字符串。
## 工作原理
```
您的 AI 助手 ←→ MCP 协议 ←→ 此插件 ←→ Polylang
(Claude Desktop, (13 个工具) (语言,
Cursor 等) 翻译)
```
您将 AI 助手连接到 WordPress 网站。AI 可以查看所有内容,了解需要翻译的内容,并直接创建翻译 — 无需手动复制粘贴或点击 WP 管理后台。
## 要求
- WordPress 6.9+
- Polylang 3.7+(免费或 Pro)
- PHP 8.0+
## 安装
1. 下载或克隆此仓库到 `wp-content/plugins/polylang-mcp/`
2. 在插件目录中运行 `composer install`
3. 在 WP 管理后台 → 插件中激活插件
4. 创建应用程序密码(参见下文)
5. 连接您的 AI 助手(参见下文)
## 设置
### 步骤 1:创建应用程序密码
1. 进入 **WP 管理后台 → 用户 → 个人资料**
2. 滚动到 **应用程序密码**
3. 输入名称(例如 "Claude Desktop")并点击 **添加新的应用程序密码**
4. 复制密码 — 您将在下一步中使用它
### 步骤 2:连接您的 AI 助手
#### Claude Desktop
打开配置文件:
- **Mac:** `~/Library/Application Support/Claude/claude_desktop_config.json`
- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
在 `mcpServers` 部分添加以下内容:
```json
{
"mcpServers": {
"polylang-mcp": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote@latest"],
"env": {
"WP_API_URL": "https://yoursite.com/wp-json/polylang-mcp/mcp",
"WP_API_USERNAME": "your-username",
"WP_API_PASSWORD": "xxxx xxxx xxxx xxxx xxxx xxxx"
}
}
}
}
```
用实际值替换 `yoursite.com`、`your-username` 和密码。
重启 Claude Desktop。您应该会看到 13 个 Polylang 工具可用。
#### Cursor / VS Code
在项目中创建 `.cursor/mcp.json` 或 `.vscode/mcp.json`:
```json
{
"mcpServers": {
"polylang-mcp": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote@latest"],
"env": {
"WP_API_URL": "https://yoursite.com/wp-json/polylang-mcp/mcp",
"WP_API_USERNAME": "your-username",
"WP_API_PASSWORD": "xxxx xxxx xxxx xxxx xxxx xxxx"
}
}
}
}
```
#### 本地开发(WP-CLI / STDIO)
如果您在本地运行 WordPress,可以完全跳过 HTTP 传输:
```json
{
"mcpServers": {
"polylang-mcp": {
"command": "wp",
"args": [
"--path=/path/to/wordpress",
"mcp-adapter", "serve",
"--server=polylang-mcp-server",
"--user=admin"
]
}
}
}
```
## 它能做什么?
连接后,您的 AI 助手拥有 13 个工具:
### 了解网站
| 工具 | 功能 |
|------|-------------|
| `get-site-info` | 网站概览 — WordPress 版本、主题、插件、语言、内容类型 |
| `get-translation-status` | 按内容类型和语言划分的翻译进度 |
| `list-languages` | 所有配置的语言及其详细信息 |
| `list-content-types` | 可翻译的文章类型和分类法 |
### 查找要翻译的内容
| 工具 | 功能 |
|------|-------------|
| `get-untranslated-content` | 列出目标语言缺失翻译的内容 |
| `get-content` | 完整的文章内容(标题、正文、摘要、元数据、分类) |
| `get-term` | 术语详细信息(名称、描述、分类法、父级) |
| `get-string-groups` | 已注册的字符串组及其翻译状态 |
### 翻译
| 工具 | 功能 |
|------|-------------|
| `translate-post` | 创建或更新翻译后的文章(幂等) |
| `translate-term` | 创建或更新翻译后的术语(幂等) |
| `translate-string` | 设置字符串翻译 |
### 管理语言
| 工具 | 功能 |
|------|-------------|
| `create-language` | 添加新语言(仅需本地化) |
| `delete-language` | 删除语言 |
## 示例工作流程
### "将我的网站翻译成法语"
只需告诉您的 AI 助手:
> 将所有未翻译的文章和页面翻译成法语
AI 将:
1. 调用 `get-untranslated-content` 以查找缺失的内容
2. 为每个文章调用 `get-content` 以获取源文本
3. 翻译内容
4. 调用 `translate-post` 以保存每个翻译
### "我的翻译进度如何?"
> 显示所有语言的翻译状态
AI 调用 `get-translation-status` 并为您提供按语言划分的已翻译和未翻译内容的摘要。
### "在我的网站上添加日语"
> 添加日语作为语言并翻译最近的 5 篇文章
AI 调用 `create-language` 并使用本地化 `ja`,然后翻译文章。
## 技术细节
### 架构
插件使用 WordPress 6.9 的 [Abilities API](https://make.wordpress.org/core/) 注册 13 种能力,并使用 [WordPress MCP Adapter](https://github.com/WordPress/mcp-adapter) 将它们公开为 MCP 工具。适配器已捆绑 — 无需额外安装。
### Polylang API
翻译使用 Polylang 的官方 API 函数创建:
- `pll_insert_post()` / `pll_update_post()` 用于文章
- `pll_insert_term()` / `pll_update_term()` 用于术语
- `PLL_MO` 用于字符串翻译
所有写入操作都是 **幂等** 的 — 调用 `translate-post` 两次,对于相同的源语言和目标语言,会更新现有的翻译,而不是创建重复的翻译。
### 权限
- 只读工具:需要 `edit_posts` 或 `read` 权限
- 写工具:需要 `manage_options` 权限(管理员)
身份验证使用 WordPress 应用程序密码,基于 HTTPS。
### 插件结构
```
polylang-mcp/
├── polylang-mcp.php # 插件引导
├── composer.json
├── src/
│ ├── Plugin.php # 钩子注册、MCP 服务器设置
│ ├── Abilities/
│ │ ├── AbstractAbility.php # 基类
│ │ ├── Environment/ # get-site-info, get-translation-status
│ │ ├── Languages/ # list, create, delete languages
│ │ ├── Content/ # list types, get content/terms, find untranslated
│ │ └── Translation/ # translate posts, terms, strings
│ └── Services/
│ ├── LanguageService.php # Polylang 语言 API 包装器
│ ├── ContentService.php # 内容查询
│ ├── TranslationService.php # 文章/术语翻译
│ └── StringService.php # 字符串翻译 via PLL_MO
└── vendor/ # 捆绑依赖(MCP 适配器)
```
## 许可证
GPL-2.0-or-later