@localness/cli 0.0.0-stage → 0.1.0

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/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@localness/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Sync a repository's locale JSON files with a Localness project.",
5
+ "type": "module",
6
+ "bin": {
7
+ "localness": "./dist/cli.mjs"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Hwacc/localness-tools.git",
12
+ "directory": "packages/cli"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "skill"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18.3"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "@localness/contract": "^0.5.1",
26
+ "@localness/sdk": "0.1.0"
27
+ },
28
+ "scripts": {
29
+ "build": "tsdown",
30
+ "test": "vitest run",
31
+ "typecheck": "tsc --noEmit -p tsconfig.json"
32
+ }
6
33
  }
package/skill/SKILL.md ADDED
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: localness
3
+ description: Sync this repository's locale JSON files with its Localness translation project through the `localness` CLI. Use when adding, changing, renaming or removing translatable strings or locale keys, when extracting hardcoded text into locale keys, when touching files under the locale directory named in localness.config.json, or when locale files and the Localness project disagree.
4
+ metadata:
5
+ localness-cli: '{{version}}'
6
+ localness-hash: ''
7
+ ---
8
+
9
+ # Localness
10
+
11
+ The locale JSON files in this repository are synced with a Localness project. The `localness` CLI is the only way to move text between them; if it is not on PATH, run `npx @localness/cli` instead. Each command uses the nearest `localness.config.json` above the working directory, so run it from the package that owns the config. That file names the locale directory, its layout and the project.
12
+
13
+ ## Rules
14
+
15
+ - Write to the project only with `localness apply <id>`, and only after a person approved that plan in this conversation. Never write through the HTTP API, an MCP server or the web app.
16
+ - Never copy text between the locale files and the project by hand: `pull` brings the project's text in, `push` plans sending yours.
17
+ - Never decide a `conflict` or `different` key yourself. Show each side's text and let a person choose.
18
+ - Never pass `--prune` unless a person asked to delete those keys from the files.
19
+ - Edit locale files only for what the task asks for. New or changed product text goes in the source-locale file; other locales are translated in the project unless the task supplies the translations.
20
+ - Never read, print, ask for or write `LOCALNESS_TOKEN`. Never edit or commit `.localness/`.
21
+ - `apply` writes drafts. Publishing happens in the Localness web app, so never say the text is live.
22
+
23
+ ## Tasks
24
+
25
+ Read the reference for the task before running anything:
26
+
27
+ | Task | Read |
28
+ | ----------------------------------------------------------------------------- | ------------------------------------------------------ |
29
+ | Locale files and the project disagree; adding or changing keys and their text | [references/sync.md](references/sync.md) |
30
+ | Moving hardcoded user-facing text in code into locale keys | [references/extract.md](references/extract.md) |
31
+ | Release labels on keys, or the release new keys get | [references/releases.md](references/releases.md) |
32
+ | Reading a command's `--json` output | [references/json-shapes.md](references/json-shapes.md) |
33
+
34
+ ## Problems
35
+
36
+ - `Authentication failed`: the token is missing or invalid. Tell the person; they set `LOCALNESS_TOKEN` in `.env.local` next to the config.
37
+ - `The token may not do this`: the token is read only. Tell the person; never look for another token.
38
+ - No `localness.config.json`: ask the person before running `localness init`.
@@ -0,0 +1,19 @@
1
+ # Extracting hardcoded text
2
+
3
+ When a person asks to move hardcoded user-facing text into locale keys:
4
+
5
+ 1. Only look in the files or folders the person named. Skip text that is not shown to users: log messages, ids, CSS classes, URLs, test data, and text already passed to the i18n function.
6
+ 2. Run `localness match --json "<text>" "<text>" ...` with every string at once. Keys come from the project (`source: "platform"`) and from the source-locale file when not pushed yet (`source: "local"`). A text with exactly one key reuses it. A text with several keys lists them all for the person to pick; never pick one yourself. Mark local keys in the table, and flag one whose name breaks a strict rule of `convention` (prefix, characters other than letters, digits, `.`, `_`, `-`, or an empty segment): push will block it.
7
+ 3. Name a key for each text without one, using `convention` and `namespaces` from the same output:
8
+ - With a `prefix`, start the name with it and `separator`. This is required.
9
+ - Prefer `separator`, write each segment in `style` (`snake_case` or `camelCase`; `none` means match the neighbouring keys), and use at most `maxDepth` segments after the prefix. These are suggestions: push still creates a key that misses them and lists it in `warnings`.
10
+ - Put the key under the namespace of the page or feature it belongs to when one fits; namespace names follow the prefix.
11
+ - Follow `guidance` when it is set, and stay close to the neighbouring keys in the locale file.
12
+ - Never reuse a name another key already has.
13
+ 4. Let the person review on a page. Write `{ "items": [{ "text", "file", "line", "key" }] }` to `.localness/review-input.json` next to the config, one item per text in the order of your list: `file` relative to the current folder, `key` the name you proposed (leave it out for texts with an existing key). Run `localness review start .localness/review-input.json --json`; it opens a page where the person picks reuse, new key or skip per text, edits names checked live against the convention, and approves. With `openedIn: "editor"` the page opened as a tab in their editor (the Localness extension has the project open); with `openedIn: "browser"` give them the `url` it prints. Then run `localness review wait <id>` until `status` is no longer `pending`. `approved` returns `items: [{ index, text, file, line, action, key, source }]`: `reuse` means use `key` (`source: "local"` is a key not pushed yet), `create` means add `key` with `text`, `skip` means leave the text. `cancelled` means change nothing and stop.
14
+ Fall back to a table in the chat when `review start` fails (no browser, remote machine) or the person asks for it. Columns: `#` (1, 2, 3, ...), text, file and line, then either the key to reuse (with its alternatives) or the new name. Below the table, tell the person they can approve everything, or reply with row numbers and what to do, for example `2 use auth_sign_in_title`, `5 rename to cart_coupon_label`, `7 skip`. Apply their instructions, show the updated table with the same numbers, and wait again.
15
+ Either way, change no files before they approve.
16
+ 5. After approval, add the new keys with their text to the source-locale file only, and replace each string in the code with the i18n call the file already uses (same function, import and argument style). Reused keys need no locale file change; skipped texts stay as they are.
17
+ 6. Continue with [sync.md](sync.md) from `localness push --json`: show the plan, and `apply` only after approval. A key blocked with `key-name` breaks the convention: rename it and plan again.
18
+
19
+ Never rename or delete existing keys while extracting, and never touch code outside the scope the person named.
@@ -0,0 +1,10 @@
1
+ # JSON shapes
2
+
3
+ - `diff --json`: `{ sourceLocale, locales, content, hasBase, files, differences: [{ locale, key, kind, local, platform, draft, base, onPlatform }] }`
4
+ - `push --json`: `{ id, path, expiresAt, sourceLocale, release, keys: [{ key, create, locales: { <locale>: { text, platform, draft } } }], blocked, warnings, leftOut }`; `id` is null when there is nothing to push; `release` is the name new keys get, or null.
5
+ - `apply <id> --json`: `{ id, written: [{ key, created, locales }], failed }`
6
+ - `match --json`: `{ matches: [{ text, keys: [{ source, key, sourceText, ... }] }], convention, namespaces }`. `matches` has one entry per text in order; a match is the same source text after whitespace normalisation. `source: "platform"` keys also have `id`, `draft` and `releaseIds`; `source: "local"` keys exist only in the source-locale file and are not pushed yet. `convention` is `{ prefix, separator, style, maxDepth, guidance }` (`style` is `snake_case`, `camelCase` or `none`) (`prefix` has no trailing separator, `''` means none; `guidance` is the project's naming advice or null), or null when the server predates it. `namespaces` lists the project's namespace names, relative to the prefix.
7
+ - `review start --json`: `{ id, url, rows }`. Input file: `{ items: [{ text, file?, line?, key? }] }`.
8
+ - `review wait <id>`: `{ id, status, items }`; `status` is `pending` (also has `url`; run it again), `approved` or `cancelled` (`items` empty). Items: `{ index, text, file, line, action, key, source }`, `action` is `reuse`, `create` or `skip`; `skip` has no `key`, only `reuse` has `source` (`platform` or `local`).
9
+ - `blocked` in `push --json`: `[{ locale, key, reason, violations? }]`; `reason` is `no-source-text`, `reserved-name` or `key-name`, and `violations` lists what a `key-name` key breaks: `prefix`, `charset` or `segment`.
10
+ - `warnings` in `push --json`: `[{ key, violations }]`, new keys that are still created but miss a suggestion: `separator`, `case` or `depth`.
@@ -0,0 +1,7 @@
1
+ # Releases
2
+
3
+ Releases are labels on keys in the project; they never filter what is synced. `release` in `localness.config.json` labels the keys `apply` creates, and the plan's `release` says which one. Existing keys keep their labels.
4
+
5
+ - Never change the config's release, create a release or relabel keys unless a person asked. `localness releases` lists them and marks the current one.
6
+ - `localness releases use <name>` (or `--none`) picks the release for new keys; `releases create <name> --use` creates one and needs a project owner's token.
7
+ - `localness releases add <release> <key...>` and `releases remove …` relabel existing keys and need a read & write token. With `--match <glob>`, first run it without `--yes` and `--json` to list the matched keys, show them to the person, and pass `--yes` only after they approve.
@@ -0,0 +1,32 @@
1
+ # Syncing locale files
2
+
3
+ 1. Run `localness diff --json`. Exit code 0: nothing differs. 1: differences. 2: error.
4
+ 2. Sort each difference by `kind` (table below) and list everything that needs a person.
5
+ 3. Ask the person about those keys and wait for the answer.
6
+ 4. Bring the project's text in: `localness pull`, or `localness pull --keys <a,b>` for keys the person gave to the project.
7
+ 5. Plan local changes: `localness push --json`, or `localness push --keys <a,b> --json` for keys the person gave to the local side. It writes nothing to the project.
8
+ 6. Show the plan to the person: its id, and for each key whether it is created or updated and every locale's old → new text. Also show `blocked`, `warnings` and `leftOut`.
9
+ 7. Only after the person approves, run `localness apply <id>`. If it reports the plan stale or expired, nothing was written: run `diff` again and start over; never retry the same id.
10
+ 8. Report what was written, and that drafts wait for a publish in the web app.
11
+
12
+ `localness sync` does steps 4 and 5 together for the unambiguous kinds. `--dry-run` previews `pull`, `push` and `sync`.
13
+
14
+ | `kind` | Meaning | Action |
15
+ | ------------------ | ------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
16
+ | `platform-added` | The project has text the file lacks | `pull` |
17
+ | `platform-changed` | The project changed it; the file did not | `pull` |
18
+ | `local-added` | The file has text the project lacks | `push` |
19
+ | `local-changed` | The file changed it; the project did not | `push` |
20
+ | `pending-publish` | The file matches an unpublished draft | Nothing; it gets published in the web app |
21
+ | `conflict` | Both sides changed, or a push would overwrite someone's draft | Ask; then `pull --keys` or `push --keys` |
22
+ | `different` | The texts differ and there is no base yet | Ask; then `pull --keys` or `push --keys` |
23
+ | `platform-deleted` | The key left the project; the file still has it | Ask; remove it from the file, or `pull --prune` when the person wants all of them gone |
24
+ | `local-deleted` | The file dropped a key the project still has | Ask; the CLI never deletes project keys, a person does that in the web app |
25
+
26
+ When `hasBase` is false (the first sync), every changed text is `different`. Say so before pulling: a plain `pull` takes the project's text for all of them.
27
+
28
+ ## New keys
29
+
30
+ - Name a new key after the project's key convention (`localness match --json` prints it as `convention`) and the neighbouring keys in the same file. `push` blocks a new key whose name breaks a strict rule (prefix, characters, empty segment), with reason `key-name`: rename it in the locale file and the code, then plan again. New keys off the suggested separator, casing or depth are created and listed in `warnings`; mention them, but they need no rename. `localness suggest-name "<source text>"` asks the project's AI for one name, but it is slow, uses the project's AI quota and needs a read & write token: only use it for a few strings a person asked about. Names starting with `__unnamed_` are reserved.
31
+ - A new key needs its text in the source-locale file. `apply` creates the key and publishes that source text; text in other locales becomes drafts.
32
+ - A plan holds at most 200 keys and expires after an hour.