@juicesharp/rpiv-i18n 1.8.0 → 1.8.2
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/i18n.ts +11 -29
- package/index.ts +3 -2
- package/package.json +51 -48
package/i18n.ts
CHANGED
|
@@ -20,9 +20,7 @@
|
|
|
20
20
|
* Config persists at ~/.config/rpiv-i18n/locale.json (chmod 0o600, best-effort writes).
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
import { homedir } from "node:os";
|
|
25
|
-
import { dirname, join } from "node:path";
|
|
23
|
+
import { configPath, loadJsonConfig, saveJsonConfig } from "@juicesharp/rpiv-config";
|
|
26
24
|
|
|
27
25
|
// ---------------------------------------------------------------------------
|
|
28
26
|
// Types
|
|
@@ -47,9 +45,7 @@ export interface LocaleConfig {
|
|
|
47
45
|
export const I18N_STATE_KEY = Symbol.for("rpiv-i18n");
|
|
48
46
|
const I18N_RUNTIME_KEY = Symbol.for("rpiv-i18n.runtime");
|
|
49
47
|
|
|
50
|
-
const
|
|
51
|
-
const LOCALE_CONFIG_PATH = join(CONFIG_DIR, "locale.json");
|
|
52
|
-
const CONFIG_FILE_MODE = 0o600;
|
|
48
|
+
const LOCALE_CONFIG_PATH = configPath("rpiv-i18n", "locale.json");
|
|
53
49
|
const DEFAULT_FALLBACK_LOCALE = "en";
|
|
54
50
|
|
|
55
51
|
// Supported locales — alphabetical by code (so the /languages picker stays
|
|
@@ -185,37 +181,23 @@ export function getActiveLocale(): string | undefined {
|
|
|
185
181
|
// ---------------------------------------------------------------------------
|
|
186
182
|
|
|
187
183
|
export function loadLocaleConfig(): LocaleConfig {
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
return JSON.parse(readFileSync(LOCALE_CONFIG_PATH, "utf-8")) as LocaleConfig;
|
|
191
|
-
} catch (err) {
|
|
192
|
-
console.warn(
|
|
193
|
-
`rpiv-i18n: invalid locale config at ${LOCALE_CONFIG_PATH}, using default (${(err as Error).message})`,
|
|
194
|
-
);
|
|
195
|
-
return {};
|
|
196
|
-
}
|
|
184
|
+
return loadJsonConfig<LocaleConfig>(LOCALE_CONFIG_PATH);
|
|
197
185
|
}
|
|
198
186
|
|
|
199
187
|
/**
|
|
200
188
|
* Persist the locale preference. Returns `true` on success, `false` if the
|
|
201
|
-
* write failed (disk full,
|
|
202
|
-
*
|
|
189
|
+
* write failed (disk full, EACCES, EROFS, etc.) — caller MUST react. The
|
|
190
|
+
* `/languages` handler relies on this boolean to honor the documented
|
|
191
|
+
* save-then-apply invariant: applying in-memory state after a failed write
|
|
192
|
+
* would silently revert at next start with zero diagnostic surface.
|
|
193
|
+
*
|
|
194
|
+
* The chmod step inside `saveJsonConfig` is best-effort and never affects
|
|
195
|
+
* the return value.
|
|
203
196
|
*/
|
|
204
197
|
export function saveLocaleConfig(locale: string | undefined): boolean {
|
|
205
198
|
const config: LocaleConfig = {};
|
|
206
199
|
if (locale) config.locale = locale;
|
|
207
|
-
|
|
208
|
-
mkdirSync(dirname(LOCALE_CONFIG_PATH), { recursive: true });
|
|
209
|
-
writeFileSync(LOCALE_CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`, "utf-8");
|
|
210
|
-
} catch {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
chmodSync(LOCALE_CONFIG_PATH, CONFIG_FILE_MODE);
|
|
215
|
-
} catch {
|
|
216
|
-
// chmod is non-critical — file persists with default mode
|
|
217
|
-
}
|
|
218
|
-
return true;
|
|
200
|
+
return saveJsonConfig(LOCALE_CONFIG_PATH, config);
|
|
219
201
|
}
|
|
220
202
|
|
|
221
203
|
// ---------------------------------------------------------------------------
|
package/index.ts
CHANGED
|
@@ -62,8 +62,9 @@ export default function (pi: ExtensionAPI): void {
|
|
|
62
62
|
|
|
63
63
|
const next = choice === NO_LOCALE_VALUE ? undefined : choice;
|
|
64
64
|
if (!saveLocaleConfig(next)) {
|
|
65
|
-
//
|
|
66
|
-
// applyLocale
|
|
65
|
+
// Honor the documented save-then-apply invariant: a successful
|
|
66
|
+
// applyLocale followed by a failed disk write would silently
|
|
67
|
+
// revert at next start with no diagnostic surface.
|
|
67
68
|
ctx.ui.notify(MSG_PERSIST_FAILED, "error");
|
|
68
69
|
return;
|
|
69
70
|
}
|
package/package.json
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
2
|
+
"name": "@juicesharp/rpiv-i18n",
|
|
3
|
+
"version": "1.8.2",
|
|
4
|
+
"description": "Pi extension. The localization foundation for rpiv-* skills: locale detection, the /languages command, the --locale flag, and a cross-package locale registry.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"rpiv",
|
|
9
|
+
"i18n",
|
|
10
|
+
"localization"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "juicesharp",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/juicesharp/rpiv-mono.git",
|
|
18
|
+
"directory": "packages/rpiv-i18n"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-i18n#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/juicesharp/rpiv-mono/issues"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "vitest run"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"index.ts",
|
|
32
|
+
"i18n.ts",
|
|
33
|
+
"i18n-ui.ts",
|
|
34
|
+
"docs/",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"exports": {
|
|
39
|
+
".": "./i18n.ts"
|
|
40
|
+
},
|
|
41
|
+
"pi": {
|
|
42
|
+
"extensions": [
|
|
43
|
+
"./index.ts"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@juicesharp/rpiv-config": "^1.8.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
51
|
+
"@earendil-works/pi-tui": "*"
|
|
52
|
+
}
|
|
50
53
|
}
|