Skip to content

DeepL 翻译插件

Maven 模块:mms-plugin-deepl。对接 DeepL API,支持 文本HTML(标签保护) 翻译;配置走 插件参数,能力可通过 HOST_MVCtryInvokePeerPlugin 与注册 Bean deeplTranslation 暴露。

白话理解

市场里填 apiKey → 调 /plugin/.../deepl/translate/text|html 即可翻译;安装包必须是 *-standalone.jar(内含 deepl-java)。密钥别超过 sys_config 常见 255 字上限。

标识与运行模式

插件 IDmms.plugin.deepl
runtimeModeHOST_MVC
hostServicesContractVersion3
入口类com.sxpcwlkj.plugin.deepl.DeepLPlugin

插件参数

后缀含义
apiKeyDeepL 认证密钥(必填
api.freetrue 时使用免费版 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:引入插件

  1. mms-plus 仓库构建(示例):
bash
cd mms-plugins/mms-plugin-deepl
mvn -DskipTests package
# 安装包:target/mms-plugin-deepl-*-standalone.jar(版本号与 revision 一致)
  1. 管理端 插件市场:上传 standalone JAR → 激活版本 → 在 详情 → 插件参数 中配置 apiKey(免费 API 增加 api.free = true)。
  2. 导入权限 SQL(若尚未执行):mms-plugins/mms-plugin-deepl/script/install.sql,为角色分配 plugin:deepl:translate
  3. GET /system/pluginHost/health 或市场卡片确认健康(未配 apiKey 时探针会失败)。

Demo:调用能力

下文 表示管理端接口根路径(如 http://localhost:8080 或网关后的 https://host/prod-api,与 mms-uiVITE_ 接口前缀一致)。

HTTP(需登录 + 权限)

http
POST {{apiBase}}/plugin/mms.plugin.deepl/deepl/translate/text
Content-Type: application/json
Authorization: <与后台一致的 Token,名称以 sa-token 配置为准>

{"text":"Hello","targetLang":"ZH"}
http
GET {{apiBase}}/plugin/mms.plugin.deepl/deepl/formats
Authorization: <token>

更多路径与字段说明见 /deepl/formats 返回体。

对等插件(Java)

在已加载的另一插件的 PluginRuntimeContext 上(例如 onLoad(PluginRuntimeContext ctx) 内):

java
Object out =
    ctx.tryInvokePeerPlugin(
        "mms.plugin.deepl",
        "translateText",
        "Hello",
        "ZH");

带源语言示例:方法名 translateTextWithSourceargs["Hello","ZH","EN"]

运维反射 invoke(super_admin)

bash
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 翻译请改 methodNametranslateHtmlargs["<p>Hi</p>","ZH",null](第三项 null 表示源语言自动检测)。

宿主 Spring Bean(进阶)

onLoad 会注册逻辑名 deeplTranslationDeepLTranslationFacade。宿主业务模块与插件 ClassLoader 不同,通常不要按类型 @Autowired 插件类型;优先 HTTPtryInvokePeerPlugin

路由速查

前缀 /plugin/mms.plugin.deepl

方法相对路径说明
GET/deepl/formats返回配置后缀、invoke 示例说明
POST/deepl/translate/textbody:texttargetLang、可选 sourceLang
POST/deepl/translate/htmlbody:htmltargetLang、可选 sourceLang

参见

Released under the MIT License.