Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Sep 3, 2023
1 parent 04f6b3a commit 6eb0b8a
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 65 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "plugin"
name = "plugin" # 名称固定为plugin,请勿更改
version = "1.0.0"
authors = ["Pylogmon"]
authors = ["pot-app"]
edition = "2021"

[lib]
crate-type = ["dylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
crate-type = ["dylib"] # pot只支持dylib类型动态库,请勿修改

[dependencies]
reqwest = {version="0.11.18",features = ["blocking","json"]}
urlencoding = "2.1.3"
serde_json = "1.0"

[target.'cfg(target_os = "linux")'.dependencies]
openssl={version="0.10",features=["vendored"]}
openssl={version="0.10",features=["vendored"]}
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
# Pot 翻译插件 Demo (Bing 为例)
# Pot-App 翻译插件模板仓库 (以 [Lingva](https://github.com/TheDavidDelta/lingva-translate) 为例)

### 此仓库为模板仓库,编写插件时可以直接由此仓库创建插件仓库

## 插件编写指南

### 1. 插件仓库创建

- 以此仓库为模板创建一个新的仓库
- 仓库名为 `pot-app-<插件名>`,例如 `pot-app-lingva`

### 2. 插件信息配置

编辑 `info.json` 文件,修改以下字段:

- `id`:插件唯一 id,必须以`[plugin]`开头,例如 `[plugin].com.pot-app.lingva`
- `display`: 插件显示名称,例如 `Lingva`
- `icon`: 插件图标,例如 `lingva.svg`
- `needs`: 插件依赖,一个数组,每个依赖为一个对象,包含以下字段:
- `key`: 依赖 key,对应该项依赖在配置文件中的名称,例如 `requestPath`
- `display`: 依赖显示名称,对应用户显示的名称,例如 `请求地址`
- `language`: 插件支持的语言映射,将 pot 的语言代码和插件发送请求时的语言代码一一对应

### 3. 插件编写/编译

编辑 `src/lib.rs` 实现 `translate` 函数

```bash
cargo test --package plugin --lib -- tests --nocapture # 运行测试用例
cargo build --release # 编译
```

### 4. 打包 pot 插件

1.`target/release`目录找到`plugin.dll`(Windows)/`libplugin.dylib`(MacOS)/`libplugin.so`(Linux)文件,统一删除`lib`前缀.

2.`plugin.dll`/`libplugin.dylib`/`libplugin.so`文件和`info.json`以及图标文件压缩为 zip 文件。

3. 将文件重命名为`<插件id>.potext`,例如`[plugin].com.pot-app.lingva.potext`,即可得到 pot 需要的插件。

## 自动编译打包

本仓库配置了 Github Actions,可以实现推送后自动编译打包插件。

每次将仓库推送到 GitHub 之后 actions 会自动运行,将打包好的插件上传到 artifact,在 actions 页面可以下载

每次提交 Tag 之后,actions 会自动运行,将打包好的插件上传到 release,在 release 页面可以下载打包好的插件
1 change: 0 additions & 1 deletion icon.svg

This file was deleted.

20 changes: 9 additions & 11 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"id": "[plugin].com.pot-app.bing",
"id": "[plugin].com.pot-app.lingva",
"plugin_type": "translate",
"icon": "icon.svg",
"display": "必应翻译",
"needs": [],
"icon": "lingva.svg",
"display": "Lingva",
"needs": [{ "key": "requestPath", "display": "请求地址" }],
"language": {
"auto": "",
"zh_cn": "zh-Hans",
"zh_tw": "zh-Hant",
"yue": "yue",
"auto": "auto",
"zh_cn": "zh",
"zh_tw": "zh_HANT",
"en": "en",
"ja": "ja",
"ko": "ko",
Expand All @@ -18,16 +17,15 @@
"de": "de",
"it": "it",
"tr": "tr",
"pt": "pt-pt",
"pt": "pt",
"pt_br": "pt",
"vi": "vi",
"id": "id",
"th": "th",
"ms": "ms",
"ar": "ar",
"hi": "hi",
"mn_cy": "mn-Cyrl",
"mn_mo": "mn-Mong",
"mn_cy": "mn",
"km": "km"
}
}
188 changes: 188 additions & 0 deletions lingva.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6eb0b8a

Please sign in to comment.