opencode-i18n 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -12
- package/package.json +1 -2
- package/plugins/i18n/server.ts +0 -30
- package/commands/i18n.md +0 -18
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ OpenCode TUI 界面本地化插件。
|
|
|
22
22
|
|
|
23
23
|
说明:
|
|
24
24
|
|
|
25
|
-
- 插件已发布到 npm
|
|
25
|
+
- 插件已发布到 npm,可直接从命令面板安装。
|
|
26
26
|
- 安装会自动写入 `opencode.json`(server 端)和 `tui.json`(TUI 端)的 `plugin` 列表。
|
|
27
27
|
- 插件自带默认语言包(`i18n/locales/*.json`),开箱即用。
|
|
28
28
|
- 如需自定义语言包,把文件放到 `~/.config/opencode/i18n/locales/` 即可覆盖默认值。
|
|
@@ -77,7 +77,6 @@ cd opencode-i18n
|
|
|
77
77
|
|
|
78
78
|
- `plugins/i18n/index.ts`
|
|
79
79
|
- `tools/i18n-state.ts`
|
|
80
|
-
- `commands/i18n.md`
|
|
81
80
|
- `i18n/`
|
|
82
81
|
|
|
83
82
|
并合并:
|
|
@@ -93,23 +92,15 @@ cd opencode-i18n
|
|
|
93
92
|
|
|
94
93
|
打开语言选择对话框(由 TUI 插件注册,npm 安装后直接可用)。选择语言即切换,也可在对话框里开关本地化。
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
/i18n status
|
|
98
|
-
/i18n on
|
|
99
|
-
/i18n off
|
|
100
|
-
/i18n toggle
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
管理开关状态(这些带参数形式走服务端命令;npm 安装时 server 插件会自动把 `commands/i18n.md` 写入 `~/.config/opencode/commands/`,无需手动操作)。
|
|
95
|
+
开关和语言也可通过 `i18n-state` 工具管理(AI 可直接调用,支持 `status`、`set`、`toggle`、`locale`、`locales`)。
|
|
104
96
|
|
|
105
97
|
如果界面没有立即刷新,请重启 OpenCode。
|
|
106
98
|
|
|
107
99
|
## 文件说明
|
|
108
100
|
|
|
109
101
|
- `plugins/i18n/index.ts`:TUI 插件,读取语言包和状态,改写界面标题/已有描述;并注册 `/i18n` 命令(语言选择对话框)。
|
|
110
|
-
- `plugins/i18n/server.ts`:server 插件,向 OpenCode 注册 `i18n-state` 工具(npm 安装模式下工具不会自动从 `tools/`
|
|
102
|
+
- `plugins/i18n/server.ts`:server 插件,向 OpenCode 注册 `i18n-state` 工具(npm 安装模式下工具不会自动从 `tools/` 加载)。
|
|
111
103
|
- `tools/i18n-state.ts`:状态工具,负责开关和语言选择。
|
|
112
104
|
- `i18n/lib.ts`:共享路径、状态读取和语言解析逻辑。配置优先读用户目录 `~/.config/opencode/i18n/`,缺失时回退到包内默认数据。
|
|
113
|
-
- `commands/i18n.md`:OpenCode 自定义 command(复制式安装时随脚本复制;npm 安装时由 server 插件自动安装)。
|
|
114
105
|
- `i18n/config.json`:默认语言和内置语言排序。
|
|
115
106
|
- `i18n/locales/*.json`:独立语言包。新增语言时只要添加一个 locale JSON 即可被自动识别;如果想调整显示顺序,可把语言代码加入 `config.json` 的 `locales` 列表。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-i18n",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "OpenCode TUI i18n plugin — localize the interface into 简体中文 / 繁體中文 and more, with one-command install.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"plugins",
|
|
13
13
|
"i18n",
|
|
14
14
|
"tools",
|
|
15
|
-
"commands",
|
|
16
15
|
"README.md",
|
|
17
16
|
"LICENSE"
|
|
18
17
|
],
|
package/plugins/i18n/server.ts
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
1
1
|
import type { Plugin, PluginModule } from "@opencode-ai/plugin"
|
|
2
|
-
import { access, mkdir, readFile, writeFile } from "node:fs/promises"
|
|
3
|
-
import path from "node:path"
|
|
4
|
-
import { fileURLToPath } from "node:url"
|
|
5
|
-
import { CONFIG_ROOT } from "../../i18n/lib.ts"
|
|
6
2
|
import i18nStateTool from "../../tools/i18n-state.ts"
|
|
7
3
|
|
|
8
|
-
const MODULE_ROOT = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
-
const COMMAND_SOURCE = path.resolve(MODULE_ROOT, "../../commands/i18n.md")
|
|
10
|
-
const COMMAND_TARGET = path.join(CONFIG_ROOT, "commands", "i18n.md")
|
|
11
|
-
|
|
12
|
-
async function exists(file: string) {
|
|
13
|
-
try {
|
|
14
|
-
await access(file)
|
|
15
|
-
return true
|
|
16
|
-
} catch {
|
|
17
|
-
return false
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function installCommandFile() {
|
|
22
|
-
try {
|
|
23
|
-
if (await exists(COMMAND_TARGET)) return
|
|
24
|
-
const content = await readFile(COMMAND_SOURCE, "utf8")
|
|
25
|
-
await mkdir(path.dirname(COMMAND_TARGET), { recursive: true })
|
|
26
|
-
await writeFile(COMMAND_TARGET, content, "utf8")
|
|
27
|
-
} catch {
|
|
28
|
-
// Read failure (file missing in copy-based installs) or write failure are
|
|
29
|
-
// non-fatal: the command file is optional.
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
4
|
const server: Plugin = async () => {
|
|
34
|
-
await installCommandFile()
|
|
35
5
|
return {
|
|
36
6
|
tool: {
|
|
37
7
|
"i18n-state": i18nStateTool,
|
package/commands/i18n.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: 管理 OpenCode 界面本地化开关和语言
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
用户想管理 OpenCode 界面的本地化开关和语言。请按以下规则解析参数,并调用 `i18n-state` 工具。
|
|
6
|
-
|
|
7
|
-
参数内容:$ARGUMENTS
|
|
8
|
-
|
|
9
|
-
规则:
|
|
10
|
-
|
|
11
|
-
1. 如果参数为空,先调用 `i18n-state`,传入 `action: "locales"`,读取返回内容末尾的 `QUESTION_DATA:` JSON;然后使用 `question` 工具让用户图形化选择语言。question 的问题文字必须逐字使用 JSON 里的 `question` 字段。选项必须逐项使用 JSON 里的 `options[].label` 和 `options[].description`,不要自行翻译、补充、改写,也不要给选项追加“当前”或“默认”。用户选择后调用 `i18n-state`,传入 `action: "locale"` 和用户选择的语言名称,也就是被选中的 `label`。
|
|
12
|
-
2. 如果参数为 `status`、`状态`,调用 `i18n-state`,传入 `action: "status"`。
|
|
13
|
-
3. 如果参数为 `on`、`enable`、`开启`、`开`,调用 `i18n-state`,传入 `action: "set"` 和 `enabled: true`。
|
|
14
|
-
4. 如果参数为 `off`、`disable`、`关闭`、`关`,调用 `i18n-state`,传入 `action: "set"` 和 `enabled: false`。
|
|
15
|
-
5. 如果参数为 `toggle`、`切换`,调用 `i18n-state`,传入 `action: "toggle"`。
|
|
16
|
-
6. 如果参数无法识别,调用 `i18n-state` 的 `status`,然后简短说明支持的参数只有 `status`、`on`、`off`、`toggle`;切换语言请直接运行 `/i18n` 并在选项中选择。
|
|
17
|
-
|
|
18
|
-
切换开关后,提醒用户:如果当前界面没有立即刷新,请重启 OpenCode。
|