pi-todo-ledger 0.6.0 → 0.7.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/CONTRACT.md +5 -1
- package/README.md +9 -5
- package/docs/configuration.md +27 -8
- package/docs/overlay.md +98 -16
- package/package.json +1 -1
- package/src/config.ts +32 -1
- package/src/index.ts +4 -4
- package/src/ledger/herdr-owner.ts +13 -5
- package/src/ledger/herdr-runs.ts +44 -0
- package/src/locales/de.json +4 -1
- package/src/locales/en.json +5 -1
- package/src/locales/es.json +4 -1
- package/src/locales/fr.json +4 -1
- package/src/locales/pt-BR.json +4 -1
- package/src/locales/pt.json +4 -1
- package/src/locales/ru.json +4 -1
- package/src/locales/uk.json +4 -1
- package/src/locales/zh-TW.json +36 -0
- package/src/locales/zh.json +5 -1
- package/src/state/i18n-bridge.ts +52 -4
- package/src/todo-overlay.ts +464 -64
- package/src/view/format.ts +2 -1
- package/src/view/live-runs.ts +120 -0
- package/src/view/task-labels.ts +2 -1
package/src/locales/zh.json
CHANGED
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
"overlay.heading": "任务清单",
|
|
10
10
|
"overlay.more": "更多",
|
|
11
|
-
"overlay.
|
|
11
|
+
"overlay.keyHint": "{key} {next}",
|
|
12
|
+
"overlay.next.focus": "焦点",
|
|
13
|
+
"overlay.next.full": "完整",
|
|
14
|
+
"overlay.next.collapsed": "收起",
|
|
12
15
|
"overlay.collapsed": "已折叠",
|
|
16
|
+
"overlay.separator": "、",
|
|
13
17
|
|
|
14
18
|
"command.no_todos": "暂无任务。可以让 agent 添加一些!",
|
|
15
19
|
"command.requires_interactive": "/todos 需要交互模式",
|
package/src/state/i18n-bridge.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* - `t(key, fallback)` is `scope("pi-todo-ledger")` if the SDK is
|
|
7
7
|
* installed (live `/languages` updates propagate). If the SDK is missing
|
|
8
|
-
* (standalone install without rpiv-i18n), `t`
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* (standalone install without rpiv-i18n), `t` returns the inline English
|
|
9
|
+
* fallback at every call site, so the extension stays online with English UI.
|
|
10
|
+
* - Traditional Chinese (`locales/zh-TW.json`) is served here, not by the SDK,
|
|
11
|
+
* whose picker lists only `zh`: see `renderLocale()` for when it applies.
|
|
11
12
|
* - `formatStatusLabel(status)` resolves a TaskStatus to its locale-aware
|
|
12
13
|
* label via the canonical `status.*` namespace, with the English literal
|
|
13
14
|
* as fallback so nothing renders blank if the namespace isn't registered.
|
|
@@ -19,6 +20,8 @@
|
|
|
19
20
|
* `const X = formatStatusLabel(...)`.
|
|
20
21
|
*/
|
|
21
22
|
|
|
23
|
+
import { readFileSync } from 'node:fs';
|
|
24
|
+
import { savedLocale } from "../config.ts";
|
|
22
25
|
import type { TaskStatus } from "../tool/types.ts";
|
|
23
26
|
|
|
24
27
|
export const I18N_NAMESPACE = "pi-todo-ledger";
|
|
@@ -38,6 +41,7 @@ type I18nSDK = { scope: (namespace: string) => ScopeFn };
|
|
|
38
41
|
// Top-level await is required so a synchronous `t(...)` call from any
|
|
39
42
|
// downstream module sees the resolved scope; ESM module loading awaits this
|
|
40
43
|
// before evaluating any importer.
|
|
44
|
+
const traditional: Record<string,string> = JSON.parse(readFileSync(new URL('../locales/zh-TW.json', import.meta.url), 'utf8'));
|
|
41
45
|
let scopeImpl: ScopeFn;
|
|
42
46
|
try {
|
|
43
47
|
const sdk = (await import(I18N_SDK)) as I18nSDK;
|
|
@@ -46,7 +50,51 @@ try {
|
|
|
46
50
|
scopeImpl = (_key, fallback) => fallback;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
const TRADITIONAL = /^zh[-_](?:TW|Hant)(?:[-_.@]|$)/i;
|
|
54
|
+
|
|
55
|
+
// The SDK republishes this plain-data snapshot on every locale change, a /languages pick included.
|
|
56
|
+
const SDK_STATE = Symbol.for("rpiv-i18n");
|
|
57
|
+
type SdkState = { readonly locale?: string } | undefined;
|
|
58
|
+
|
|
59
|
+
/** The `--locale` value Pi was started with (`--locale x` or `--locale=x`). */
|
|
60
|
+
function flagLocale(argv = process.argv): string | undefined {
|
|
61
|
+
for (const [i, arg] of argv.entries()) {
|
|
62
|
+
if (arg.startsWith("--locale=")) return arg.slice(9) || undefined;
|
|
63
|
+
if (arg === "--locale" && argv[i + 1] && !argv[i + 1].startsWith("-")) return argv[i + 1];
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let seenState: SdkState | null = null;
|
|
69
|
+
let chosen: string | undefined;
|
|
70
|
+
/** The user's explicit choice (`--locale`, then the saved /languages pick), re-read when the SDK applies a locale. */
|
|
71
|
+
function explicitLocale(state: SdkState): string | undefined {
|
|
72
|
+
if (state !== seenState) {
|
|
73
|
+
seenState = state;
|
|
74
|
+
chosen = flagLocale() ?? savedLocale();
|
|
75
|
+
}
|
|
76
|
+
return chosen;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The locale to render in. An explicit choice wins as given: `zh` stays Simplified and `zh-TW`
|
|
81
|
+
* is Traditional. Without one, the system locale is the default, read in POSIX order
|
|
82
|
+
* (`LC_ALL`, then `LC_MESSAGES`, then `LANG`). The SDK reads `LANG` first and drops the
|
|
83
|
+
* region, so a Traditional system locale decides here; any other keeps the SDK's code.
|
|
84
|
+
*/
|
|
85
|
+
export function renderLocale(): string {
|
|
86
|
+
const sys = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || '';
|
|
87
|
+
const state = (globalThis as { [k: symbol]: SdkState })[SDK_STATE];
|
|
88
|
+
const locale = state?.locale;
|
|
89
|
+
if (!locale) return sys;
|
|
90
|
+
if (explicitLocale(state) !== undefined) return locale;
|
|
91
|
+
return TRADITIONAL.test(sys) ? sys : locale;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const t: ScopeFn = (key, fallback) => {
|
|
95
|
+
if (TRADITIONAL.test(renderLocale())) return traditional[key] ?? fallback;
|
|
96
|
+
return scopeImpl(key, fallback);
|
|
97
|
+
};
|
|
50
98
|
|
|
51
99
|
const STATUS_LABEL_PENDING = "pending";
|
|
52
100
|
const STATUS_LABEL_IN_PROGRESS = "in progress";
|