Pot-App 翻译插件模板仓库 (以 Lingva 为例)
- 以此仓库为模板创建一个新的仓库
- 仓库名为
pot-app-translate-plugin-<插件名>,例如pot-app-translate-plugin-lingva
编辑 info.json 文件,修改以下字段:
id:插件唯一 id,必须以plugin开头,例如plugin.com.pot-app.lingvahomepage: 插件主页,填写你的仓库地址即可,例如https://github.com/pot-app/pot-app-translate-plugin-templatedisplay: 插件显示名称,例如Lingvaicon: 插件图标,例如lingva.svgneeds: 插件依赖,一个数组,每个依赖为一个对象,包含以下字段:key: 依赖 key,对应该项依赖在配置文件中的名称,例如requestPathdisplay: 依赖显示名称,对应用户显示的名称,例如请求地址type: 组件类型input|selectoptions: 选项列表(仅 select 组件需要),例如{"engine_a":"Engina A","engine_b":"Engina B"}
language: 插件支持的语言映射,将 pot 的语言代码和插件发送请求时的语言代码一一对应
编辑 main.js 实现 translate 函数
// config: config map
// detect: detected source language
// setResult: function to set result text
// utils: some tools
// http: tauri http module
// readBinaryFile: function
// readTextFile: function
// Database: tauri Database class
// CryptoJS: CryptoJS module
// cacheDir: cache dir path
// pluginDir: current plugin dir
// osType: "Windows_NT" | "Darwin" | "Linux"
async function translate(text, from, to, options) {
const { config, detect, setResult, utils } = options;
const { http, readBinaryFile, readTextFile, Database, CryptoJS, run, cacheDir, pluginDir, osType } = utils;
const { fetch, Body } = http;
}// 文本翻译直接返回字符串
return "result";
// 流式输出使用options中的setResult函数
setResult("result");词典返回 json 示例:
{
"pronunciations": [
{
"region": "", // 地区
"symbol": "", // 音标
"voice": [u8] // 语音字节数组
}
],
"explanations": [
{
"trait": "", // 词性
"explains": [""] // 释义
}
],
"associations": [""], // 联想/变形
"sentence": [
{
"source": "", // 原文
"target": "" // 译文
}
]
}-
将
main.js文件和info.json以及图标文件压缩为 zip 文件。 -
将文件重命名为
<插件id>.potext,例如plugin.com.pot-app.lingva.potext,即可得到 pot 需要的插件。
本仓库配置了 Github Actions,可以实现推送后自动编译打包插件。
每次将仓库推送到 GitHub 之后 actions 会自动运行,将打包好的插件上传到 artifact,在 actions 页面可以下载
每次提交 Tag 之后,actions 会自动运行,将打包好的插件上传到 release,在 release 页面可以下载打包好的插件