pi-extensions-i18n 0.3.0 → 0.3.1
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 +4 -4
- package/README.zh-CN.md +4 -4
- package/package.json +1 -1
- package/src/index.ts +5 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Independent Pi extensions still need the same operational pieces: a portable con
|
|
|
11
11
|
- `zh-CN`, `en-US`, and `auto` locale preferences.
|
|
12
12
|
- Persistent setting at `~/.pi/agent/extensions/pi-extensions-i18n/config.json`.
|
|
13
13
|
- `PI_EXTENSIONS_LOCALE` environment-variable override.
|
|
14
|
-
- `/
|
|
14
|
+
- `/config:language` interactive command, plus `/config:language en-US` direct selection.
|
|
15
15
|
- Catalog loading and validation requiring both language entries for every message key.
|
|
16
16
|
- Translator interpolation for user-facing UI, command descriptions, and agent prompts.
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ Independent Pi extensions still need the same operational pieces: a portable con
|
|
|
21
21
|
pi install npm:pi-extensions-i18n
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Feature packages
|
|
24
|
+
Feature packages use it as a shared dependency and load its extension entry automatically, so installing a feature package is enough to provide the locale command. Install this package directly only when you want the locale command without another feature package.
|
|
25
25
|
|
|
26
26
|
Reload Pi after installation:
|
|
27
27
|
|
|
@@ -46,7 +46,7 @@ PI_EXTENSIONS_LOCALE=en-US pi
|
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
```text
|
|
49
|
-
/
|
|
49
|
+
/config:language en-US
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
## Extension author API
|
|
@@ -83,7 +83,7 @@ Invalid catalogs fail during loading, which makes missing translations visible i
|
|
|
83
83
|
## Requirements
|
|
84
84
|
|
|
85
85
|
- Node.js 22 or newer.
|
|
86
|
-
- Pi's extension runtime when using the `/pi-language`
|
|
86
|
+
- Pi's extension runtime when using the `/config:language` command. `/pi-language` remains available as a compatibility alias.
|
|
87
87
|
|
|
88
88
|
## License
|
|
89
89
|
|
package/README.zh-CN.md
CHANGED
|
@@ -11,7 +11,7 @@ Pi 扩展公共国际化运行时。它提供基于 catalog 的小型 API,支
|
|
|
11
11
|
- 支持 `zh-CN`、`en-US` 和 `auto` 语言偏好。
|
|
12
12
|
- 将设置持久化到 `~/.pi/agent/extensions/pi-extensions-i18n/config.json`。
|
|
13
13
|
- 支持 `PI_EXTENSIONS_LOCALE` 环境变量覆盖。
|
|
14
|
-
- 提供 `/
|
|
14
|
+
- 提供 `/config:language` 交互式命令,也支持 `/config:language en-US` 直接设置。
|
|
15
15
|
- 加载并校验 catalog,要求每个消息 key 同时提供两种语言。
|
|
16
16
|
- 为 UI、命令描述和 Agent prompt 提供用户文案插值。
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ Pi 扩展公共国际化运行时。它提供基于 catalog 的小型 API,支
|
|
|
21
21
|
pi install npm:pi-extensions-i18n
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
各功能包会自动安装并加载这个公共依赖,因此安装任意使用它的功能包即可使用语言命令。只有不安装其他功能包、想单独使用语言命令时,才需要直接安装本包。
|
|
25
25
|
|
|
26
26
|
安装后重新加载 Pi:
|
|
27
27
|
|
|
@@ -46,7 +46,7 @@ PI_EXTENSIONS_LOCALE=en-US pi
|
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
```text
|
|
49
|
-
/
|
|
49
|
+
/config:language en-US
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
## 扩展作者 API
|
|
@@ -83,7 +83,7 @@ catalog 条目必须同时包含两种语言:
|
|
|
83
83
|
## 要求
|
|
84
84
|
|
|
85
85
|
- Node.js 22 或更高版本。
|
|
86
|
-
- 使用 `/
|
|
86
|
+
- 使用 `/config:language` 命令时需要 Pi 扩展运行时;`/pi-language` 仍作为兼容别名保留。
|
|
87
87
|
|
|
88
88
|
## 许可证
|
|
89
89
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -192,7 +192,7 @@ const commandMessages = loadCatalog(
|
|
|
192
192
|
|
|
193
193
|
function registerLocaleCommand(pi: ExtensionAPI): void {
|
|
194
194
|
const i18n = createTranslator(commandMessages);
|
|
195
|
-
|
|
195
|
+
const command = {
|
|
196
196
|
description: i18n.t("description"),
|
|
197
197
|
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
198
198
|
if (!ctx.hasUI) {
|
|
@@ -246,7 +246,10 @@ function registerLocaleCommand(pi: ExtensionAPI): void {
|
|
|
246
246
|
ctx.ui.notify(i18n.t("failed", { error: String(error) }), "error");
|
|
247
247
|
}
|
|
248
248
|
},
|
|
249
|
-
}
|
|
249
|
+
};
|
|
250
|
+
for (const name of ["config:language", "pi-language"] as const) {
|
|
251
|
+
pi.registerCommand(name, command);
|
|
252
|
+
}
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
export default function piI18n(pi: ExtensionAPI): void {
|