DeepL 翻译插件
Maven 模块:mms-plugin-deepl。对接 DeepL API,支持 文本与 HTML(标签保护) 翻译;配置走 插件参数,能力可通过 HOST_MVC、tryInvokePeerPlugin 与注册 Bean deeplTranslation 暴露。
白话理解
市场里填 apiKey → 调 /plugin/.../deepl/translate/text|html 即可翻译;安装包必须是 *-standalone.jar(内含 deepl-java)。密钥别超过 sys_config 常见 255 字上限。
标识与运行模式
| 项 | 值 |
|---|---|
| 插件 ID | mms.plugin.deepl |
| runtimeMode | HOST_MVC |
| hostServicesContractVersion | 3 |
| 入口类 | com.sxpcwlkj.plugin.deepl.DeepLPlugin |
插件参数
| 后缀 | 含义 |
|---|---|
apiKey | DeepL 认证密钥(必填) |
api.free | true 时使用免费版 endpoint(https://api-free.deepl.com) |
字段长度
sys_config.config_value 当前常见上限为 255 字符;请确认密钥未超长。
权限
plugin:deepl:translate:调用/deepl/translate/*等接口前需具备该权限。- 示例 SQL:
mms-plugins/mms-plugin-deepl/script/install.sql。
安装包形态
须使用 maven-shade-plugin 生成的 mms-plugin-deepl-*-standalone.jar 上传安装(内含 deepl-java 及传递依赖)。瘦包无法单独运行。
Demo:引入插件
- 在 mms-plus 仓库构建(示例):
cd mms-plugins/mms-plugin-deepl
mvn -DskipTests package
# 安装包:target/mms-plugin-deepl-*-standalone.jar(版本号与 revision 一致)- 管理端 插件市场:上传 standalone JAR → 激活版本 → 在 详情 → 插件参数 中配置
apiKey(免费 API 增加api.free=true)。 - 导入权限 SQL(若尚未执行):
mms-plugins/mms-plugin-deepl/script/install.sql,为角色分配plugin:deepl:translate。 - 用
GET /system/pluginHost/health或市场卡片确认健康(未配apiKey时探针会失败)。
Demo:调用能力
下文 表示管理端接口根路径(如 http://localhost:8080 或网关后的 https://host/prod-api,与 mms-ui 里 VITE_ 接口前缀一致)。
HTTP(需登录 + 权限)
POST {{apiBase}}/plugin/mms.plugin.deepl/deepl/translate/text
Content-Type: application/json
Authorization: <与后台一致的 Token,名称以 sa-token 配置为准>
{"text":"Hello","targetLang":"ZH"}GET {{apiBase}}/plugin/mms.plugin.deepl/deepl/formats
Authorization: <token>更多路径与字段说明见 /deepl/formats 返回体。
对等插件(Java)
在已加载的另一插件的 PluginRuntimeContext 上(例如 onLoad(PluginRuntimeContext ctx) 内):
Object out =
ctx.tryInvokePeerPlugin(
"mms.plugin.deepl",
"translateText",
"Hello",
"ZH");带源语言示例:方法名 translateTextWithSource,args 为 ["Hello","ZH","EN"]。
运维反射 invoke(super_admin)
curl -sS -X POST "{{apiBase}}/system/pluginHost/invoke" \
-H "Content-Type: application/json" \
-H "Authorization: <token>" \
-d '{
"pluginId": "mms.plugin.deepl",
"methodName": "translateText",
"args": ["Hello", "ZH"]
}'HTML 翻译请改 methodName 为 translateHtml,args 为 ["<p>Hi</p>","ZH",null](第三项 null 表示源语言自动检测)。
宿主 Spring Bean(进阶)
onLoad 会注册逻辑名 deeplTranslation 的 DeepLTranslationFacade。宿主业务模块与插件 ClassLoader 不同,通常不要按类型 @Autowired 插件类型;优先 HTTP 或 tryInvokePeerPlugin。
路由速查
前缀 /plugin/mms.plugin.deepl:
| 方法 | 相对路径 | 说明 |
|---|---|---|
| GET | /deepl/formats | 返回配置后缀、invoke 示例说明 |
| POST | /deepl/translate/text | body:text、targetLang、可选 sourceLang |
| POST | /deepl/translate/html | body:html、targetLang、可选 sourceLang |
