opencode-i18n 0.1.3 → 0.1.5

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 CHANGED
@@ -33,58 +33,6 @@ OpenCode TUI 界面本地化插件。
33
33
  opencode plugin opencode-i18n
34
34
  ```
35
35
 
36
- ## 一句提示词安装
37
-
38
- 把下面这一句发给 OpenCode:
39
-
40
- ```text
41
- 请从 https://github.com/huahai0202/opencode-i18n 安装 OpenCode i18n 插件:克隆仓库,Windows 运行 install.ps1、macOS/Linux 运行 install.sh,或按 README 手动复制文件到我的全局 OpenCode 配置目录,保留我已有配置并合并 tui.json 的 plugin 列表;完成后告诉我重启 OpenCode,并运行 /i18n 选择 English、简体中文或繁體中文。
42
- ```
43
-
44
- ## 手动安装(复制式)
45
-
46
- macOS / Linux:
47
-
48
- ```bash
49
- git clone https://github.com/huahai0202/opencode-i18n.git
50
- cd opencode-i18n
51
- ./install.sh
52
- ```
53
-
54
- Windows PowerShell:
55
-
56
- ```powershell
57
- git clone https://github.com/huahai0202/opencode-i18n.git
58
- cd opencode-i18n
59
- .\install.ps1
60
- ```
61
-
62
- 脚本会安装到(尊重 `XDG_CONFIG_HOME`,默认 `~/.config/opencode`):
63
-
64
- ```text
65
- ~/.config/opencode # macOS / Linux
66
- %USERPROFILE%\.config\opencode # Windows
67
- ```
68
-
69
- 自定义安装路径:
70
-
71
- ```bash
72
- ./install.sh --config-root /path/to/opencode-config # macOS / Linux
73
- .\install.ps1 -ConfigRoot C:\path\to\opencode-config # Windows
74
- ```
75
-
76
- 它会复制这些文件:
77
-
78
- - `plugins/i18n/index.ts`
79
- - `tools/i18n-state.ts`
80
- - `commands/i18n.md`
81
- - `i18n/`
82
-
83
- 并合并:
84
-
85
- - `tui.json` 的 `plugin` 列表
86
- - `package.json` 的 `@opencode-ai/plugin` 依赖
87
-
88
36
  ## 使用
89
37
 
90
38
  ```text
@@ -93,23 +41,15 @@ cd opencode-i18n
93
41
 
94
42
  打开语言选择对话框(由 TUI 插件注册,npm 安装后直接可用)。选择语言即切换,也可在对话框里开关本地化。
95
43
 
96
- ```text
97
- /i18n status
98
- /i18n on
99
- /i18n off
100
- /i18n toggle
101
- ```
102
-
103
- 管理开关状态(这些带参数形式走服务端命令;npm 安装时 server 插件会自动把 `commands/i18n.md` 写入 `~/.config/opencode/commands/`,无需手动操作)。
44
+ 开关和语言也可通过 `i18n-state` 工具管理(AI 可直接调用,支持 `status`、`set`、`toggle`、`locale`、`locales`)。
104
45
 
105
46
  如果界面没有立即刷新,请重启 OpenCode。
106
47
 
107
48
  ## 文件说明
108
49
 
109
50
  - `plugins/i18n/index.ts`:TUI 插件,读取语言包和状态,改写界面标题/已有描述;并注册 `/i18n` 命令(语言选择对话框)。
110
- - `plugins/i18n/server.ts`:server 插件,向 OpenCode 注册 `i18n-state` 工具(npm 安装模式下工具不会自动从 `tools/` 加载),并在首次启动时自动安装 `commands/i18n.md`(已存在则不覆盖)。
51
+ - `plugins/i18n/server.ts`:server 插件,向 OpenCode 注册 `i18n-state` 工具(npm 安装模式下工具不会自动从 `tools/` 加载)。
111
52
  - `tools/i18n-state.ts`:状态工具,负责开关和语言选择。
112
53
  - `i18n/lib.ts`:共享路径、状态读取和语言解析逻辑。配置优先读用户目录 `~/.config/opencode/i18n/`,缺失时回退到包内默认数据。
113
- - `commands/i18n.md`:OpenCode 自定义 command(复制式安装时随脚本复制;npm 安装时由 server 插件自动安装)。
114
54
  - `i18n/config.json`:默认语言和内置语言排序。
115
55
  - `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",
3
+ "version": "0.1.5",
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
  ],
@@ -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。