@cratis/pi 8.12.0 → 8.14.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/corpus/skills/cratis-arc-localize-application/SKILL.md +50 -0
- package/package/corpus/skills/cratis-arc-localize-application/references/csharp.md +52 -0
- package/package/corpus/skills/cratis-arc-localize-application/references/go.md +44 -0
- package/package/corpus/skills/cratis-arc-localize-application/references/typescript-switcher.md +59 -0
- package/package/corpus/skills/cratis-arc-localize-application/references/typescript-tooling.md +82 -0
- package/package/corpus/skills/cratis-arc-localize-application/references/typescript.md +151 -0
- package/package/corpus/skills/cratis-arc-react-bind-slice/SKILL.md +1 -1
- package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-localization.md +2 -0
- package/package/corpus/skills/cratis-code-review/SKILL.md +1 -1
- package/package/corpus/skills/cratis-components-diagnose-screen/SKILL.md +1 -1
- package/package/corpus/skills/cratis-components-theme-application/SKILL.md +5 -2
- package/package/corpus/skills/cratis-components-theme-application/references/localization.md +1 -0
- package/package/corpus/skills/cratis-migrate-arc-22-to-23/SKILL.md +59 -0
- package/package/corpus/skills/cratis-migrate-arc-22-to-23/references/csharp.md +121 -0
- package/package/corpus/skills/cratis-migrate-arc-23-to-24/SKILL.md +60 -0
- package/package/corpus/skills/cratis-migrate-arc-23-to-24/references/csharp.md +91 -0
- package/package/corpus/skills/cratis-migrate-arc-23-to-24/references/typescript.md +26 -0
- package/package/corpus/skills/cratis-migrate-components-3-to-4/SKILL.md +72 -0
- package/package/corpus/skills/cratis-migrate-components-3-to-4/references/typescript.md +137 -0
- package/package/corpus/skills/cratis-platform-upgrade-application/SKILL.md +2 -2
- package/package/corpus/skills/cratis-platform-upgrade-application/references/typescript.md +1 -1
- package/package/profile-catalog.json +113 -0
- package/package.json +1 -1
- package/package/corpus/skills/cratis-components-theme-application/references/upgrade-from-previous-major.md +0 -141
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cratis-arc-localize-application
|
|
3
|
+
description: Use when an Arc application with a React frontend must show screens, refusals and widget text in more than one language, add a language, add a language switcher or hand translation files to a translation service. Not for the backend culture settings alone (use cratis-arc-host-application), a single-language literal-tree setup (use cratis-arc-react-bind-slice) or restyling Components (use cratis-components-theme-application).
|
|
4
|
+
compatibility: Needs an Arc backend and an Arc React frontend. The optional localization tooling needs a Node.js version its package supports.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Localize an Arc application
|
|
8
|
+
|
|
9
|
+
One shared policy, English beside each slice, one locale root. Three facts decide the rest:
|
|
10
|
+
|
|
11
|
+
- **English is the only built-in language.** Every other language is an opt-in catalog: files the application owns, or an optional pack such as `@cratis/arc.locale.nb` and `@cratis/components.locale.nb`. Packs are never downloaded; a missing one falls back to English.
|
|
12
|
+
- **The nearest Arc locale decides the language.** Read it from the `<Arc locale>` root (or the request on the server). Never pick it from the browser or a message's wording.
|
|
13
|
+
- **Language and regional format are independent.** The UI language never selects date, number, currency or time zone format; set the format locale separately.
|
|
14
|
+
|
|
15
|
+
Read `references/<language>.md` for the project's SDK (`.csproj` → csharp, Node server `package.json` → typescript, `*.kt` → kotlin, `*.java` → java, `go.mod` → go, `mix.exs` → elixir). The React frontend is always in `typescript.md`, plus `typescript-switcher.md` and `typescript-tooling.md`. Kotlin, Java and Elixir backends have no released localization: do the frontend steps and expect English server text. Python has no Arc SDK: localize the service that owns the Arc routes.
|
|
16
|
+
|
|
17
|
+
## Default path
|
|
18
|
+
|
|
19
|
+
1. **Declare the languages once.** Put the supported languages and the default in a shared `localization.json` at the application root, and enable localization on the backend from the same list. Done when a supported `Accept-Language` returns a matching `Content-Language`.
|
|
20
|
+
2. **Write English beside each slice** in `messages.en.json`: flat full message IDs mapped to ICU MessageFormat strings. Show text with the locale's `t(id, values)`, never with a literal. Map each refusal the application authors to an ID by its descriptor (`reason/reasonDetail`). Done when no component renders a literal sentence or server `message`.
|
|
21
|
+
3. **Mount once.** Create one locale store with one catalog registry, pass it to `<Arc locale>` at the root and register every feature the root can show; loaders are lazy per language, not per route. Done when the network panel requests no language outside the selected one, its parents, the default and English.
|
|
22
|
+
4. **Add a language.** Add one translated file per feature, sparse overrides for platform text, and an optional pack for platform text. Omit untranslated keys so they fall back to English. Done when `cratis-l10n check` (or your own check) passes and the screen shows the language.
|
|
23
|
+
5. **Add the switcher and verify on an open route.** Never reload to switch. Done when the switch checks pass, including a late refusal and an unsaved draft.
|
|
24
|
+
6. **Optional: generate loaders and types** with the `cratis-l10n` tool, hand translation files to a translation service and diagnose a missing pack. Hand-written wiring is equally valid.
|
|
25
|
+
|
|
26
|
+
## Rules
|
|
27
|
+
|
|
28
|
+
- **Match descriptors, never prose.** Server text can be reworded or translated. Show framework and mapped refusals from the descriptor; show unmapped authored text as written.
|
|
29
|
+
- **Widget text and accessible names stay configurable.** Supply Components' labels and accessible names through the catalog or `value.messages`, and name custom controls from the catalog, so assistive technology matches the screen.
|
|
30
|
+
- **Tag foreign text.** Text in another language than the UI carries its own `lang`.
|
|
31
|
+
- **Never keep a user's language in process-wide server state**; requests would share it.
|
|
32
|
+
- **Never write `Accept-Language` yourself.** The root sends it; a hand-written header replaces it.
|
|
33
|
+
|
|
34
|
+
## Catalog
|
|
35
|
+
|
|
36
|
+
| Piece | Use it when |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| Shared `localization.json` | Backend and frontend must agree on languages and default. |
|
|
39
|
+
| `messages.en.json` per slice | Texts belong to one feature; English is the source. |
|
|
40
|
+
| `locales/<tag>/<area>.json` | A language translates one feature's texts. |
|
|
41
|
+
| `locales/<tag>/overrides.json` | Reword a few platform (`arc.*`, `components.*`) texts. |
|
|
42
|
+
| Optional pack | A maintained translation of platform text exists for the language. |
|
|
43
|
+
| `value.catalog` on Components | Components-owned labels must follow the UI language. |
|
|
44
|
+
| Format locale | Dates and numbers follow a regional convention other than the UI language. |
|
|
45
|
+
| `LanguageSelector` | The user picks the language; use your own control only when it cannot fit. |
|
|
46
|
+
| `cratis-l10n build`, `add`, `export`, `check` | Generate loaders and types, add a language, write exchange files, validate. |
|
|
47
|
+
|
|
48
|
+
## Related skills
|
|
49
|
+
|
|
50
|
+
Nearest skill: `cratis-arc-react-bind-slice` (single-language literal trees). Backend culture options: `cratis-arc-host-application`. Forms: `cratis-components-submit-form`. Provider and messages: `cratis-components-theme-application`. Accessibility: `cratis-components-accessibility`.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Localize a C# Arc backend
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Enable localization
|
|
6
|
+
- What changes on the server
|
|
7
|
+
- Refusals
|
|
8
|
+
- Avoid
|
|
9
|
+
|
|
10
|
+
The frontend steps are in `typescript.md`. Language tags and the resource name below are illustrative.
|
|
11
|
+
|
|
12
|
+
## Enable localization
|
|
13
|
+
|
|
14
|
+
Set `ArcOptions.Localization` (or `Cratis:Arc:Localization` in configuration) to the same languages as the frontend's `localization.json`. The host does not read that file, so keep the two lists equal by hand or in one build step you own.
|
|
15
|
+
|
|
16
|
+
```csharp
|
|
17
|
+
builder.AddCratisArc(configureOptions: options =>
|
|
18
|
+
{
|
|
19
|
+
options.Localization = new()
|
|
20
|
+
{
|
|
21
|
+
SupportedUICultures = ["en", "nb"],
|
|
22
|
+
DefaultUICulture = "en"
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- Use distinct canonical .NET culture names and include the default. Invalid options stop startup.
|
|
28
|
+
- Without `Localization` Arc negotiates nothing and sends no `Content-Language`.
|
|
29
|
+
- Matching is exact, alias, supported parent, then a unique regional descendant: `nb-NO` selects a supported `nb` and `nb` selects a lone supported `nb-NO`, but `fr-CA` does not select `fr-FR`. Add an alias only when you want one; `Aliases` maps for example `no` to `nb`.
|
|
30
|
+
- Default source is `Accept-Language`. Add `Providers` (`QueryString`, `Cookie`, `AcceptLanguage`, in priority order) only when you need them; the cookie provider makes responses non-cacheable.
|
|
31
|
+
- The Arc client sends a `_cratisUiCulture` hint on stream URLs for you. If you use ASP.NET Core WebSockets, call `UseWebSockets()` before request localization.
|
|
32
|
+
- `UseCratisArc()` installs the middleware. Call `app.UseCratisRequestLocalization()` earlier only when earlier middleware needs the culture. Never run a second request-localization policy.
|
|
33
|
+
- The self-hosted `ArcApplication` listener applies the same policy.
|
|
34
|
+
|
|
35
|
+
Done when a request with `Accept-Language: nb` returns `Content-Language: nb` and an unsupported language returns the default.
|
|
36
|
+
|
|
37
|
+
## What changes on the server
|
|
38
|
+
|
|
39
|
+
The selection sets `CultureInfo.CurrentUICulture` for the request only. Formatting stays on `CultureInfo.InvariantCulture` unless you set `FormattingCulture`, and then it is fixed for every request: a client's language never selects a format or a time zone. Do not copy `CurrentUICulture` into `CurrentCulture`.
|
|
40
|
+
|
|
41
|
+
## Refusals
|
|
42
|
+
|
|
43
|
+
- The server keeps sending a stable `reason`, `reasonDetail` and English `message`. The client maps these to its catalog. There is no server catalog package; the client supplies the text.
|
|
44
|
+
- Server-side localized text only helps for rules that run on the server. Generated proxies run a copy of the rule in the browser by default, so see `cratis-arc-generate-proxies` for the client validation setting.
|
|
45
|
+
- For an application-specific message, resolve the resource inside a lambda so it is read at validation time, after the culture is known: `.WithMessage(_ => ValidationMessages.NameRequired)`. FluentValidation's built-in messages already follow the UI culture.
|
|
46
|
+
- Give each application-specific refusal a stable `reasonDetail` (see `cratis-arc-validate-command`) and a frontend catalog ID. Never make the client branch on message text.
|
|
47
|
+
|
|
48
|
+
## Avoid
|
|
49
|
+
|
|
50
|
+
- Setting `DefaultThreadCurrentUICulture` for the process.
|
|
51
|
+
- A language list on the server that differs from the frontend list.
|
|
52
|
+
- Putting personal data or secrets in a refusal message or its arguments: refusals travel to the client and may be logged.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Localize an Arc.Go backend
|
|
2
|
+
|
|
3
|
+
The frontend steps are in `typescript.md`. This reference applies to Arc.Go releases that include `arc.Options.Localization`. Tags and IDs below are illustrative.
|
|
4
|
+
|
|
5
|
+
## Enable localization
|
|
6
|
+
|
|
7
|
+
```go
|
|
8
|
+
b, err := arc.NewBuilder(arc.Options{
|
|
9
|
+
Localization: &arc.LocalizationOptions{
|
|
10
|
+
Languages: []string{"en", "nb"},
|
|
11
|
+
Default: "en",
|
|
12
|
+
Aliases: map[string]string{"no": "nb"},
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- Languages must be distinct BCP 47 base tags and the default must be one of them.
|
|
18
|
+
- Arc does not read `localization.json`. To share it with the frontend, decode its `languages` and `default` fields into `arc.LocalizationOptions` before building.
|
|
19
|
+
- `Accept-Language` is the default source. `Providers` can add `arc.QueryString` (`ui-culture`) and `arc.Cookie` (`.AspNetCore.Culture`, format `c=en|uic=fr`); the cookie provider makes every response non-cacheable.
|
|
20
|
+
- With localization on, every response sets `Content-Language`. The selection never changes number or date formats, time zones, JSON or stored data.
|
|
21
|
+
- With `Localization` nil, nothing is negotiated.
|
|
22
|
+
|
|
23
|
+
## Messages the server renders
|
|
24
|
+
|
|
25
|
+
Read the tag with `arc.UILanguage(ctx)` (empty when none). Outside HTTP derive one context per recipient with `arc.WithUILanguage(ctx, recipientLanguage)`. Register catalogs before `Build` and look a message up after it:
|
|
26
|
+
|
|
27
|
+
```go
|
|
28
|
+
err = b.AddCatalog(arc.MessageCatalog{
|
|
29
|
+
"en": {"app.notice.saved": "Saved"},
|
|
30
|
+
"nb": {"app.notice.saved": "Lagret"},
|
|
31
|
+
})
|
|
32
|
+
// after Build:
|
|
33
|
+
text, found := app.Message(ctx, "app.notice.saved")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use stable, namespaced IDs. `Message` falls back from the tag to its parent and then to the default, and returns `found == false` when no catalog has the ID. Duplicate IDs for one language are rejected. Arc ships no Go language packs and does not interpret template syntax, so you format any values yourself.
|
|
37
|
+
|
|
38
|
+
## Refusals
|
|
39
|
+
|
|
40
|
+
On a localized host framework findings keep their English `message` and add `reason`, `reasonDetail` and named `messageArguments`; the client formats them from its catalog. Application validators may set `validation.Result.MessageArguments` with strings, booleans or finite numbers. Never put raw request values, secrets or diagnostics in them. Unlocalized hosts keep the previous findings.
|
|
41
|
+
|
|
42
|
+
## Other stacks
|
|
43
|
+
|
|
44
|
+
Kotlin, Java and Elixir follow the same shared contract (the Arc localization specification: tag matching, `Accept-Language`, the `_cratisUiCulture` stream hint, cookie and response headers). Use their API only after the SDK documents it; until then rely on the frontend steps and English server text.
|
package/package/corpus/skills/cratis-arc-localize-application/references/typescript-switcher.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Language switcher and switch verification
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Add the switcher
|
|
6
|
+
- Accessibility
|
|
7
|
+
- Verify a switch on an open route
|
|
8
|
+
- Avoid
|
|
9
|
+
|
|
10
|
+
Language tags and labels below are illustrative.
|
|
11
|
+
|
|
12
|
+
## Add the switcher
|
|
13
|
+
|
|
14
|
+
Under `<Arc locale>`, `LanguageSelector` from `@cratis/components/Localization` needs no props. It lists Arc's supported languages by their own names (for example `English`, `norsk bokmål`), with no flags, and asks Arc to switch without a reload. It renders nothing when it has no options, for example when `<Arc>` has no locale and you pass no props.
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
<Arc locale={locale}>
|
|
18
|
+
<ArcComponentsProvider value={{ catalog }} toaster>
|
|
19
|
+
<LanguageSelector />
|
|
20
|
+
<App />
|
|
21
|
+
</ArcComponentsProvider>
|
|
22
|
+
</Arc>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- `variant="segmented"` renders a native radio group instead of a native `select`.
|
|
26
|
+
- `labels={{ fr: 'Français' }}` replaces one language's displayed name.
|
|
27
|
+
- For application-owned state, pass `value`, `options` and `onChange` (the mounted `CratisComponentsProvider` then needs `value.locale` from the same state).
|
|
28
|
+
- For a custom control, read `useLanguage()` (`language`, `options`, `setLanguage`) and keep the accessibility rules below. Without Arc, `LanguageProvider` is the controlled source.
|
|
29
|
+
- Outside React call `await locale.setLanguage(tag)`. It returns `false` when the tag is unsupported, its catalog fails to load or a newer request supersedes it; `setLocale(tag)` is fire-and-forget.
|
|
30
|
+
|
|
31
|
+
## Accessibility
|
|
32
|
+
|
|
33
|
+
- The control has an accessible name. The default comes from the Components `languageSelector.label` message, so it follows the UI language. Set `label`, `pt.root['aria-label']`, `pt.root['aria-labelledby']` or a visible `<label>` for `pt.root.id` when the product words it differently. Keep the name in the catalog, not a literal in code.
|
|
34
|
+
- Each option carries its own `lang` and `dir`, so a screen reader pronounces a language name correctly; keep that on a custom control.
|
|
35
|
+
- The native `select` announces its own change, so no live region is needed; do not add one.
|
|
36
|
+
- Keyboard: the `select` works with the platform keys. `segmented` moves between languages with the arrow keys and keeps focus on the control after a switch.
|
|
37
|
+
- A switch must not move focus away or reload. Do not announce it by stealing focus; the document `lang` updates with the root.
|
|
38
|
+
- Automated results are not certification: check keyboard-only use, a screen reader, zoom reflow and right-to-left layouts by hand. See `cratis-components-accessibility`.
|
|
39
|
+
|
|
40
|
+
## Verify a switch on an open route
|
|
41
|
+
|
|
42
|
+
Switching rereads the open route in the new language: queries refresh, live subscriptions reconnect, and local React state and input values stay. Prove that on a route with a form:
|
|
43
|
+
|
|
44
|
+
1. **Open route.** Open a route with visible texts, a Components control and a form. Switch. Done when every visible text, the paginator or other Components labels and the `<html lang>` value use the new language, and an untranslated key shows English instead of its ID.
|
|
45
|
+
2. **Unsaved draft.** Type into fields without submitting, then switch. Done when the values, focus order and field errors remain, the form is not submitted again and its validation is not rerun.
|
|
46
|
+
3. **Late refusal.** Submit a command that the server refuses, switch before or while the reply arrives, then let it arrive. Done when the refusal shows once in the new language (mapped by `reason/reasonDetail`, with foreign-language text carrying its own `lang`) and the form still holds the draft. Switch back and confirm it reformats again.
|
|
47
|
+
4. **Streams.** With a live query open, confirm the connection re-established and data is shown in the new language where the server localizes it.
|
|
48
|
+
5. **Reload.** Reload. Done when the stored choice (`storageKey`) or the initial language wins, and a refusal's language matches the screen.
|
|
49
|
+
6. **Fallback.** Remove one translated key or the optional pack in a scratch build. Done when English appears for it without errors, then restore.
|
|
50
|
+
|
|
51
|
+
A custom `fieldContainerComponent` or `errorDisplayComponent` receives `errorLanguage`; apply it to the error text, not the surrounding controls.
|
|
52
|
+
|
|
53
|
+
## Avoid
|
|
54
|
+
|
|
55
|
+
- Reloading the page to switch.
|
|
56
|
+
- Remounting the root on a switch: the draft is lost.
|
|
57
|
+
- Rendering `result.message` or branching on message text instead of descriptors.
|
|
58
|
+
- Showing the language name in the current UI language only; it must be readable by someone who cannot read the current one.
|
|
59
|
+
- Flags as language icons.
|
package/package/corpus/skills/cratis-arc-localize-application/references/typescript-tooling.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# The `cratis-l10n` tool, translation services and missing packs
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Prerequisites
|
|
6
|
+
- Layout the tool reads
|
|
7
|
+
- Commands
|
|
8
|
+
- Run it
|
|
9
|
+
- Translation service file masks
|
|
10
|
+
- Checks to run
|
|
11
|
+
- Diagnose a missing pack
|
|
12
|
+
- Upgrades
|
|
13
|
+
|
|
14
|
+
The tool is optional: the same wiring written by hand is valid (see Register by hand in `typescript.md`). Paths, tags and names are illustrative.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
`cratis-l10n` is an npm executable included in `@cratis/arc` (not a `cratis` subcommand). It and the Vite `localization()` plugin from `@cratis/arc.vite` need Node.js 22.15 or later on 22.x, 23.5 or later on 23.x, or 24 and later. The requirement applies to the tooling only, not the browser. Run `node --version` first.
|
|
19
|
+
|
|
20
|
+
## Layout the tool reads
|
|
21
|
+
|
|
22
|
+
| File | Purpose |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| `localization.json` | `languages`, `default` and optionally `generatedDir`. |
|
|
25
|
+
| `Features/<Feature>/<Slice>/messages.en.json` | English beside the slice: flat full IDs to ICU strings. |
|
|
26
|
+
| `Shell/messages.en.json` | Shared `app.common.*` English. |
|
|
27
|
+
| `locales/<tag>/<feature>.json` | Translations of `app.<feature>.*`. |
|
|
28
|
+
| `locales/<tag>/overrides.json` | Sparse override of `arc.*` and `components.*` texts. |
|
|
29
|
+
| `locales/en/*.json`, `locales/en/.revision.json` | Exchange templates; only `export` writes them. The application always loads English from the slice files. |
|
|
30
|
+
| `generated/` | Generated TypeScript; keep out of version control. |
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
Run from the application root, or add `--root <dir>`.
|
|
35
|
+
|
|
36
|
+
| Command | Does |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `cratis-l10n build` | Writes `localization-types.ts` (`MessageId`, `MessageParameters`) and `localization-loaders.ts` (`catalogLoaders`, `overrideLoaders`, `packLoaders`). |
|
|
39
|
+
| `cratis-l10n add <tag>` | Adds a language and seeds missing keys with English; existing translations stay. |
|
|
40
|
+
| `cratis-l10n export` | Writes the English templates and their revision. Rerun after changing English or IDs, before sending files out. |
|
|
41
|
+
| `cratis-l10n check` | Validates IDs, ICU syntax, placeholder names and types, and coverage. |
|
|
42
|
+
|
|
43
|
+
`check` exits `0` for success (warnings included), `1` for validation errors and `2` for usage or I/O errors. Missing entries in partial catalogs and stale template revisions are warnings.
|
|
44
|
+
|
|
45
|
+
## Run it
|
|
46
|
+
|
|
47
|
+
With Vite, register `localization()` from `@cratis/arc.vite` in `vite.config.ts`: it generates before a build and regenerates as you edit catalogs, translations or the policy in dev. Without Vite, use `"prebuild": "cratis-l10n build"` and `"check:l10n": "cratis-l10n check"` in `package.json`, and run `check:l10n` in CI. Use a bundler that supports literal dynamic JSON imports and enable `resolveJsonModule`.
|
|
48
|
+
|
|
49
|
+
## Translation service file masks
|
|
50
|
+
|
|
51
|
+
The service exchanges the files `export` writes. Use these masks in the service's own syntax (placeholder names differ per service, so take them from its documentation):
|
|
52
|
+
|
|
53
|
+
- Source: `locales/en/*.json`. Exclude `locales/en/.revision.json`.
|
|
54
|
+
- Translation: the same file name under `locales/<tag>/`, so `locales/en/hours.json` becomes `locales/nb/hours.json`.
|
|
55
|
+
- Use canonical tags for the directory (`pt-BR`, not `pt_br`), which may need the service's language-code mapping.
|
|
56
|
+
- Keep ICU placeholders and plural syntax untouched; `check` fails on a renamed placeholder.
|
|
57
|
+
- Do not send `overrides.json` unless you want translators to own platform wording.
|
|
58
|
+
|
|
59
|
+
After import: run `cratis-l10n check`, then `cratis-l10n build`. If English changed since the export, rerun `export` and resend; a stale revision is only a warning, so treat it as a blocker for release yourself.
|
|
60
|
+
|
|
61
|
+
## Checks to run
|
|
62
|
+
|
|
63
|
+
1. `cratis-l10n check` (exit code, warnings read).
|
|
64
|
+
2. The project's type check and build, because `MessageId` and `MessageParameters` help only through your own typed wrapper around `t`; `t` itself accepts any string, so a typo is not a compile error.
|
|
65
|
+
3. The switch checks in `typescript-switcher.md` for one language.
|
|
66
|
+
4. On the backend, the culture-selection checks in `csharp.md` or `go.md`.
|
|
67
|
+
|
|
68
|
+
## Diagnose a missing pack
|
|
69
|
+
|
|
70
|
+
A pack is optional and never downloaded, so a missing one is not an error: the language falls back to English.
|
|
71
|
+
|
|
72
|
+
1. Check that the package is published and installed: `npm ls @cratis/arc.locale.nb`. `@cratis/arc.locale.nb` and `@cratis/components.locale.nb` may not be published yet; if `npm view` finds nothing, the pack does not exist for you yet.
|
|
73
|
+
2. The generator adds a pack to `packLoaders` only when it is installed, listed in the application's `dependencies`, named `@cratis/arc.locale.<tag>` or `@cratis/components.locale.<tag>`, and the tag is a configured language or its parent. Check each.
|
|
74
|
+
3. `build` reports a missing pack as an English fallback. Read its warnings.
|
|
75
|
+
4. Use `packLoaders.arc` in the Arc registry and `packLoaders.components` in a separate Components registry, whose `registry.load(tag)` result is passed as `value.catalog` (see `typescript.md`). For a Components pack the generator compares the pack's same-minor `coreRange` with the installed `@cratis/components` at build time; it warns and omits the loader when the range excludes it or the version cannot be determined, so rerun `build` after updating either package. The generated Components loader needs an Arc release that includes the fix for Cratis/Arc#4079; on an older Arc, and in hosts that do not use the generated loaders, register the pack directly: `{ nb: () => import('@cratis/components.locale.nb') }`.
|
|
76
|
+
5. A pack is refused, with an error reported, when it is malformed, when its manifest locale is invalid, or when its same-minor range excludes your installed core version. A different English template revision only warns and the pack still loads. Pass `onDiagnostic` to read the reports, and upgrade the pack and the library together.
|
|
77
|
+
6. The tag must be in `localization.json`. A pack for an unlisted language is never loaded.
|
|
78
|
+
7. If the pack cannot be installed, put the texts you need in `locales/<tag>/overrides.json`.
|
|
79
|
+
|
|
80
|
+
## Upgrades
|
|
81
|
+
|
|
82
|
+
After upgrading `@cratis/arc` or `@cratis/components`, run `cratis-l10n build` and `check`: new platform texts are English until the pack or your overrides cover them. A changed English text or ID needs a new `export` before translators work again.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Localize an Arc React frontend
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Prerequisites
|
|
6
|
+
- Step 1: declare the languages
|
|
7
|
+
- Step 2: write English and use it
|
|
8
|
+
- Step 3: mount once
|
|
9
|
+
- Step 4: add a language
|
|
10
|
+
- Components text
|
|
11
|
+
- Regional format
|
|
12
|
+
- Register by hand
|
|
13
|
+
- Related references
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
|
|
17
|
+
`@cratis/arc` and `@cratis/arc.react` in the project, and `resolveJsonModule` enabled in `tsconfig.json` because the catalogs are imported as JSON. Language tags, IDs and names below are illustrative, and the same tags (`en`, `nb`) are used in `csharp.md` and `go.md`. The backend side is in `csharp.md` or `go.md`; the switcher and its checks are in `typescript-switcher.md`; the optional tool and translation-service handoff are in `typescript-tooling.md`.
|
|
18
|
+
|
|
19
|
+
## Step 1: declare the languages
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"languages": ["en", "nb"],
|
|
24
|
+
"default": "en"
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Save it as `localization.json` in the frontend root. Use canonical tags and include the default. The backend list must name the same languages, or the server will answer in a language the client cannot show. Done when the file parses and both sides list the same tags.
|
|
29
|
+
|
|
30
|
+
## Step 2: write English and use it
|
|
31
|
+
|
|
32
|
+
Write each slice's texts next to it, as `messages.en.json` with flat, full IDs: `app.<feature>.<name>`. Values are ICU MessageFormat strings; placeholders are named.
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"app.hours.title": "Hours",
|
|
37
|
+
"app.hours.saved": "Saved {count, plural, one {# entry} other {# entries}}."
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Read texts from the locale in a component, and from the injected `LocaleService` (from `@cratis/arc/localization`) in a view model:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { useLocale } from '@cratis/arc.react';
|
|
45
|
+
|
|
46
|
+
export function Title() {
|
|
47
|
+
const t = useLocale()?.t;
|
|
48
|
+
return <h1>{t?.('app.hours.title')}</h1>;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`t` is `undefined` when the root has no locale and returns `undefined` for an unknown ID, so keep the optional chaining. Done when the screen renders `Hours` and a typo in the ID renders nothing instead of the ID.
|
|
53
|
+
|
|
54
|
+
Map each refusal the application authors to an ID by its descriptor, `<reason>/<reasonDetail>`, exactly as it arrives on the result:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
<CommandForm command={RegisterHours} validationDescriptors={{ 'constraintViolation/UniqueHours': 'app.hours.duplicate' }} />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Set the same mapping on `CommandFormDefaults` to cover every form. For a dialog or toast, keep the command result in state and render `CommandFeedback` from `@cratis/arc.react/commands` with the same mapping; for custom rendering call `useCommandFeedbackFormatter(descriptors)`. Never render `result.message` directly: it is server text in the server's language. Known framework failures are translated without a mapping; an unmapped authored message shows as written.
|
|
61
|
+
|
|
62
|
+
## Step 3: mount once
|
|
63
|
+
|
|
64
|
+
Create one locale store at module level and pass it to the single `<Arc>` root. Render after `ready` resolves, because `t` has no catalog until the first load finishes. The store's registry holds everything `useLocale().t` translates, and its loaders are lazy per language, not per route: register every feature map the root can show (here `catalogLoaders.hours` and the shared `catalogLoaders.common`). To keep a route's catalog out of the root, give it its own `createCatalogRegistry` and `await registry.load(tag)`; that translator is not bound to `useLocale().t` and you call it yourself.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { createCatalogRegistry } from '@cratis/arc/localization/catalog';
|
|
68
|
+
import { createLocale } from '@cratis/arc/localization';
|
|
69
|
+
import { Arc } from '@cratis/arc.react';
|
|
70
|
+
import { createRoot } from 'react-dom/client';
|
|
71
|
+
import policy from './localization.json';
|
|
72
|
+
import { catalogLoaders, overrideLoaders, packLoaders } from './generated/localization-loaders';
|
|
73
|
+
|
|
74
|
+
const registry = createCatalogRegistry({
|
|
75
|
+
default: policy.default,
|
|
76
|
+
catalog: [packLoaders.arc, overrideLoaders, catalogLoaders.common, catalogLoaders.hours],
|
|
77
|
+
});
|
|
78
|
+
export const locale = createLocale({
|
|
79
|
+
supported: policy.languages,
|
|
80
|
+
defaultLocale: policy.default,
|
|
81
|
+
catalogRegistry: registry,
|
|
82
|
+
storageKey: 'ui-language',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const root = createRoot(document.getElementById('root')!);
|
|
86
|
+
void locale.ready.then(() => root.render(<Arc locale={locale}><App /></Arc>));
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The `generated/` files come from the tool (keep that directory out of version control); without it, see Register by hand. Each language loader runs only when that language is requested, so a French file is not fetched for an English user. `storageKey` remembers the user's choice. Add `detectBrowserLanguage: true` only to start from the browser's language, and `initialLocale` for a language stored in the user's profile. Done when `locale.getSnapshot().locale` is the expected tag and the network panel shows no request for a language outside the selected one, its parents, the default and English.
|
|
90
|
+
|
|
91
|
+
## Step 4: add a language
|
|
92
|
+
|
|
93
|
+
1. Add the tag to `localization.json` and to the backend list.
|
|
94
|
+
2. Add `locales/<tag>/<feature>.json` per feature; the second segment of the ID names the file (`app.hours.*` → `hours.json`; use canonical tags for directories, such as `pt-BR`). `cratis-l10n add <tag>` creates them with English filled in; for a partial translation, delete the keys you have not translated so the runtime falls back (the tag, its parent `nb-NO` → `nb`, then English).
|
|
95
|
+
3. Optionally reword platform text in `locales/<tag>/overrides.json` using `arc.*` and `components.*` IDs. An application file beats a pack for the same ID.
|
|
96
|
+
4. Optionally install a maintained pack, for example `@cratis/arc.locale.nb` (and `@cratis/components.locale.nb` for Components). Packs are optional: without one that language shows English platform text. If a pack is not published yet, the install fails; leave it out and rely on `overrides.json`.
|
|
97
|
+
|
|
98
|
+
Done when `await locale.setLanguage('nb')` returns `true`, the screen shows the translated text and an untranslated key shows English. A `false` result means the tag is unsupported or its catalog failed to load.
|
|
99
|
+
|
|
100
|
+
## Components text
|
|
101
|
+
|
|
102
|
+
Mount `ArcComponentsProvider` from `@cratis/components/Localization` inside `<Arc>` in place of `CratisComponentsProvider`; never mount both. It follows Arc's UI language and format locale. Give it a catalog for the current language and load a fresh one whenever the language changes:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
const components = createCatalogRegistry({
|
|
106
|
+
default: 'en',
|
|
107
|
+
catalog: [packLoaders.components, overrideLoaders],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
function Shell({ children }: { children: React.ReactNode }) {
|
|
111
|
+
const language = useLocale()?.locale ?? 'en';
|
|
112
|
+
const [catalog, setCatalog] = useState<ComponentsCatalog>();
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
let current = true;
|
|
115
|
+
void components.load(language).then(loaded => { if (current) setCatalog(loaded); });
|
|
116
|
+
return () => { current = false; };
|
|
117
|
+
}, [language]);
|
|
118
|
+
const value = useMemo(() => ({ catalog }), [catalog]);
|
|
119
|
+
return <ArcComponentsProvider value={value} toaster>{children}</ArcComponentsProvider>;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Prefer the generated `packLoaders.components`, as shown: its loader takes the pack's default export, and `cratis-l10n build` checks the pack's same-minor `coreRange` against the installed `@cratis/components` and omits an incompatible pack. The generated Components loader needs an Arc release that includes the fix for Cratis/Arc#4079. On an older Arc, or in a host that does not use the generated loaders, register the pack directly instead: `{ nb: () => import('@cratis/components.locale.nb') }`. If no Components pack exists for the language, keep only your overrides. `ComponentsCatalog` is exported from `@cratis/components/Localization`. Components' labels, including accessible names and overlay content, come from the catalog; English fills the gaps. Reword one label with `value.messages` (for example `messages: { paginator: { page: n => `Side ${n}` } }`); function-valued keys stay functions. Keep `value` stable. Without Arc's locale, put the language on `CratisComponentsProvider` (`value.locale`, `value.catalog`) and own the language state yourself. See `cratis-components-theme-application` for the label groups.
|
|
124
|
+
|
|
125
|
+
## Regional format
|
|
126
|
+
|
|
127
|
+
`createLocale({ formatLocale: 'nb-NO' })` pins date and number formatting. Without it, formatting follows the UI language. On the provider, `value.formatLocale` overrides only the format. Use it when users expect a regional convention that differs from the UI language, for example English text with day-month dates. Never derive a format from the UI language yourself. Done when changing the UI language leaves a pinned date format unchanged.
|
|
128
|
+
|
|
129
|
+
## Register by hand
|
|
130
|
+
|
|
131
|
+
Without the tool, write the generated shape yourself: dynamic imports of JSON, one loader per tag.
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
const registry = createCatalogRegistry({
|
|
135
|
+
default: 'en',
|
|
136
|
+
catalog: [
|
|
137
|
+
{ 'app.hours.title': 'Hours' },
|
|
138
|
+
{ nb: () => import('./locales/nb/hours.json') },
|
|
139
|
+
{ nb: async () => {
|
|
140
|
+
const { default: messages, manifest } = await import('@cratis/arc.locale.nb');
|
|
141
|
+
return { messages, manifest };
|
|
142
|
+
} },
|
|
143
|
+
],
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
A bare dictionary is the application's English. A tag map holds loaders; a pack loader returns `{ messages, manifest }`, and Arc refuses a pack whose manifest range does not include its core version (it reports it and continues in English). Pass `onDiagnostic` to receive those reports instead of the console. Your bundler must support literal dynamic JSON imports.
|
|
148
|
+
|
|
149
|
+
## Related references
|
|
150
|
+
|
|
151
|
+
Open `typescript-switcher.md` for the switcher and checks, and `typescript-tooling.md` for `cratis-l10n`, translation-service file masks and a missing pack.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cratis-arc-react-bind-slice
|
|
3
|
-
description: Use when a developer mounts the Arc React host, binds a generated query or command proxy in a React component, sets
|
|
3
|
+
description: Use when a developer mounts the Arc React host, binds a generated query or command proxy in a React component, sets up a single-language literal-tree UI language of a React application (several languages, packs, a switcher or `cratis-l10n` belong to cratis-arc-localize-application), coordinates several command editors with one Save/Discard (CommandScope), or reads identity, availability or slice context in React, including folder-derived slice locations from the Arc Vite SliceLocationPlugin. Not for a standard table (use cratis-components-display-list), a form that collects command input (use cratis-components-submit-form), view-model classes (use cratis-arc-react-separate-view-model) or producing the proxies (use cratis-arc-generate-proxies).
|
|
4
4
|
compatibility: Requires react, react-dom, reflect-metadata, @cratis/arc, @cratis/arc.react and @cratis/fundamentals, plus proxies generated for React.
|
|
5
5
|
---
|
|
6
6
|
|
package/package/corpus/skills/cratis-arc-react-bind-slice/references/typescript-localization.md
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
- Outside React
|
|
9
9
|
- Avoid
|
|
10
10
|
|
|
11
|
+
For several languages, multi-file catalogs, optional packs, a language switcher or the `cratis-l10n` tool, use `cratis-arc-localize-application`; this page keeps the literal-tree path (`defineTranslations`).
|
|
12
|
+
|
|
11
13
|
This is the home for the client side of the UI language: the texts of the application's own screens and the language Arc sends to the backend. Texts and formats of Cratis Components controls follow it through `ArcComponentsProvider`; see `cratis-components-theme-application` (`references/localization.md`). The backend decides which cultures it honours; see Request localization in `cratis-arc-host-application`. Language tags, text keys and the storage key below are illustrative.
|
|
12
14
|
|
|
13
15
|
## Default path
|
|
@@ -44,7 +44,7 @@ in the findings that matter:
|
|
|
44
44
|
| A focused Chronicle, database, backend or frontend scalability analysis | `cratis-performance-review`; the performance items here are only those visible in passing, so do not duplicate its findings when both ran |
|
|
45
45
|
| Scheduling review passes, rounds and re-reviews | `cratis-engineering-review-rounds` |
|
|
46
46
|
| Reviewing the model itself | `cratis-modeling-review-event-model` |
|
|
47
|
-
| The change raises or pins Cratis packages, tools or images | Also read `cratis-platform-upgrade-application` for version pairing, pinning and upgrade order, and `cratis
|
|
47
|
+
| The change raises or pins Cratis packages, tools or images | Also read `cratis-platform-upgrade-application` for version pairing, pinning and upgrade order, and the matching `cratis/migrate/components-<from>-to-<to>` profile when it crosses a Components major |
|
|
48
48
|
|
|
49
49
|
## How gates and review divide the work
|
|
50
50
|
|
|
@@ -41,7 +41,7 @@ A screen works when three independent things work. Decide which one failed befor
|
|
|
41
41
|
| Symptom | First check | Then |
|
|
42
42
|
| --- | --- | --- |
|
|
43
43
|
| A generated command or query import is missing | The backend slice exists, builds, and proxy generation has run. Never hand-write the command or query class. | `cratis-arc-generate-proxies` |
|
|
44
|
-
| A component import from the package root does not compile | The package root is setup-only (provider, configuration, messages, icons). Import each component from its own subpath. | `cratis-
|
|
44
|
+
| A component import from the package root does not compile | The package root is setup-only (provider, configuration, messages, icons). Import each component from its own subpath. | `cratis-platform-upgrade-application` (the matching `cratis/migrate/components-<from>-to-<to>` profile) |
|
|
45
45
|
| Type check rejects a stylesheet import | The package stylesheets are imported from TypeScript. Import them from one local CSS file instead. | `cratis-components-theme-application` |
|
|
46
46
|
| Components render unstyled | One local CSS file imports `@cratis/components/tokens`, then `@cratis/components/styles`, and the application entry imports that file once. | `cratis-components-theme-application` |
|
|
47
47
|
| Product CSS loses to Components styles | The product stylesheet loads after the package imports. Unlayered product CSS beats the layered structural rules whatever its specificity; a product with its own cascade layers must declare the layer order. The token and theme defaults are unlayered too, so an override of those wins only on equal or higher selector specificity and later order. Confirm which rule won in the inspector's computed styles. | `cratis-components-theme-application`, Cascade layers |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cratis-components-theme-application
|
|
3
|
-
description: Use when wiring Cratis Components CSS (tokens, structural styles, baseline theme, per-area sheets, Designsystemet bridge), branding or replacing the palette through `--cratis-*` tokens, switching light/dark or theming a subtree, styling component parts, configuring `CratisComponentsProvider` (locale, messages, icons, router, dialog header actions, toaster, overlay container) selecting a renderer adapter, authoring one for another design system
|
|
3
|
+
description: Use when wiring Cratis Components CSS (tokens, structural styles, baseline theme, per-area sheets, Designsystemet bridge), branding or replacing the palette through `--cratis-*` tokens, switching light/dark or theming a subtree, styling component parts, configuring `CratisComponentsProvider` (locale, messages, icons, router, dialog header actions, toaster, overlay container) selecting a renderer adapter, or authoring one for another design system. Not for keyboard and ARIA semantics (`cratis-components-accessibility`), raising toasts or busy feedback (`cratis-components-coordinate-feedback`), choosing which control to render (`cratis-components-choose-control`), or upgrading an application across a Components major (`cratis-platform-upgrade-application`).
|
|
4
4
|
compatibility: Requires @cratis/components and a CSS bundler that resolves package imports.
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -18,7 +18,9 @@ compatibility: Requires @cratis/components and a CSS bundler that resolves packa
|
|
|
18
18
|
|
|
19
19
|
Cratis Components splits appearance into three package stylesheets and one runtime provider. `tokens` declares the semantic `--cratis-*` CSS variables with light defaults. `styles` holds component structure and interaction-state rules. The optional `theme` adds document colors, dark mode, forced-colors values and themed subtrees. `CratisComponentsProvider` carries locale, labels, icons, routing, dialog header actions, the toast region and renderer selection. It loads no CSS. Product styling goes through tokens and stable parts, never through internal markup.
|
|
20
20
|
|
|
21
|
-
Read `references/<language>.md` for the project's SDK (`.csproj` → csharp, Node server `package.json` → typescript, `*.kt` → kotlin, `*.java` → java, `go.mod` → go, `mix.exs` → elixir); only the project's languages are installed. Cratis Components is React-only, so its imports and examples are in the typescript reference whatever SDK the backend uses. Language-neutral references: [tokens](references/tokens.md) (every `--cratis-*` variable), [palette](references/palette.md) (selector blocks for palette overrides), [parts](references/parts.md) (every stable part and its states), [renderer adapters](references/renderer-adapters.md) (adapter coverage and setup)
|
|
21
|
+
Read `references/<language>.md` for the project's SDK (`.csproj` → csharp, Node server `package.json` → typescript, `*.kt` → kotlin, `*.java` → java, `go.mod` → go, `mix.exs` → elixir); only the project's languages are installed. Cratis Components is React-only, so its imports and examples are in the typescript reference whatever SDK the backend uses. Language-neutral references: [tokens](references/tokens.md) (every `--cratis-*` variable), [palette](references/palette.md) (selector blocks for palette overrides), [parts](references/parts.md) (every stable part and its states), [renderer adapters](references/renderer-adapters.md) (adapter coverage and setup) and [localization](references/localization.md) (read for UI language, label translations and formats). Names in examples are illustrative.
|
|
22
|
+
|
|
23
|
+
Major upgrades: see `cratis-platform-upgrade-application` for the migration profile.
|
|
22
24
|
|
|
23
25
|
## How it works
|
|
24
26
|
|
|
@@ -145,3 +147,4 @@ Read `references/<language>.md` for the project's SDK (`.csproj` → csharp, Nod
|
|
|
145
147
|
- `cratis-components-accessibility`
|
|
146
148
|
- `cratis-components-coordinate-feedback`
|
|
147
149
|
- `cratis-components-choose-control`
|
|
150
|
+
- `cratis-platform-upgrade-application`
|
package/package/corpus/skills/cratis-components-theme-application/references/localization.md
CHANGED
|
@@ -59,6 +59,7 @@ export const App = () => (
|
|
|
59
59
|
|
|
60
60
|
## Message packs
|
|
61
61
|
|
|
62
|
+
- This is the legacy built-in registration. It still works and is deprecated: Arc and Components are moving to English as the only built-in language, with other languages as opt-in catalogs or packs the application supplies through `value.catalog`. For a new language or a new application, follow `cratis-arc-localize-application`.
|
|
62
63
|
- Components ships two packs: English and Norwegian Bokmål.
|
|
63
64
|
- `nb-NO`, `nb` and `no` select Bokmål. Every other language gets English labels.
|
|
64
65
|
- The English fallback affects Components labels only. `locale` and `formatLocale` keep the values you set, so React Aria texts and formats still follow them.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cratis-migrate-arc-22-to-23
|
|
3
|
+
description: Use when upgrading a C# application from Cratis Arc 22 to Arc 23, including commands that start failing with a read-protection refusal, `CommandReadModelKeysMissing` or `ProtectedReadModelKeyAccessorMissing` after raising `Cratis` or `Cratis.Arc.*`, and a host that no longer compiles on `McpToolCeiling` or `McpRequiresGatedEndpoints`. Not for other Arc majors, new applications (`cratis-platform-start-application`) or the general upgrade loop of versions, kernel order and deployment (`cratis-platform-upgrade-application`).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Move a C# application from Arc 22 to Arc 23
|
|
7
|
+
|
|
8
|
+
Temporary guidance for one upgrade. Reinstall the AI corpus without this profile once the upgrade is merged. Run it inside the loop of `cratis-platform-upgrade-application`, which owns version pairing, kernel order and deployment.
|
|
9
|
+
|
|
10
|
+
## What changed
|
|
11
|
+
|
|
12
|
+
Moving to the latest Arc 23 release turns two protective options on by default for applications that use Arc with Chronicle, and renames part of the MCP hosting API. The npm packages have no change that breaks a build.
|
|
13
|
+
|
|
14
|
+
| Symptom | Cause | Who is affected |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| A command that injects a read model is refused, fails on a concurrent change it used to survive, or stops the host at startup | Read protection is `On` for every project that reaches `Cratis.Arc.Chronicle` (directly, through `Cratis` or through a project reference) and does not set `<CratisReadProtection>`. Arc 22 ran such projects as `Off` | Projects with commands, validators, `Provide()` or `Handle()` that take read models and declare no mode |
|
|
17
|
+
| `CommandReadModelKeysMissing` at startup or on the first command | Key lookup needs the metadata the Arc source generator emits; the reflection fallback is off unless `ReadProtection:RequireGeneratedMetadata` is `false` | Every command under `On` that the generator skips, such as a partial command, whether or not it takes a read model; in any mode, a command with a `[LookUpBy]` parameter |
|
|
18
|
+
| `ProtectedReadModelKeyAccessorMissing` at startup or HTTP 500 during command execution | `ProtectedReadModelKeyOptions.Strict` is `true`: a composite key type needs generated or registered accessors | Commands under `On` whose key is a record or class of several parts that the generator cannot cover |
|
|
19
|
+
| A command spec gets `null` for a read model it used to receive | A replaced or substituted `IReadModels` no longer supplies state to a protected read | Command scenarios that arrange state through a replacement reader |
|
|
20
|
+
| Compile error on `McpToolCeiling` or `McpRequiresGatedEndpoints` | `McpToolCeiling` is `McpToolCatalog`, with no forwarder. `McpRequiresGatedEndpoints` is gone, because MCP no longer needs `CapabilitiesOptions.GatedEndpoints` | Hosts that name either type |
|
|
21
|
+
| Obsolete warning (an error with warnings as errors) on `MapCratisArcMcp`, string `ExposeQuery`, `TenancyOptions.DevelopmentTenantId`, `IntrospectionOptions.TrustForwardedIdentityHeaders` or `HostBuilderExtensions.DefaultArcSectionPaths` | Each has a replacement. The MCP messages say the old form goes in Arc 24; it still compiles there, so treat it as a warning to clear now, not a deadline | Hosts that call them |
|
|
22
|
+
| Header tenancy resolves no tenant | A tenant header with several comma-separated values resolves only when all values are equal | Deployments whose ingress appends to the tenant header instead of replacing it |
|
|
23
|
+
| Subscribing to an observable query over server-sent events returns 404 for a signed-in caller | The connection is owned by the caller's name identifier, subject or name; a caller with none of them cannot manage subscriptions | Applications whose principals carry no such claim |
|
|
24
|
+
| A validator's `WhenCommand()` and `WhenQuery()` rules swap on an MVC action | PUT, PATCH and DELETE count as command validation, as POST does | MVC controllers with those verbs and such rules |
|
|
25
|
+
| A React form shows a validation message twice | `CommandForm` renders a summary for failures no field displays | Forms that already render their own summary |
|
|
26
|
+
|
|
27
|
+
An application without Chronicle, MCP hosting or any row above has nothing to change beyond the version raise.
|
|
28
|
+
|
|
29
|
+
## Inventory before the bump
|
|
30
|
+
|
|
31
|
+
1. List the versions of `Cratis`, `Cratis.Arc.*` and `@cratis/arc*` in every project file, `Directory.Packages.props` and `package.json`.
|
|
32
|
+
2. List every project that holds commands and whether it sets `<CratisReadProtection>`. In each one without it, list the commands and validators that take a read model, and the commands marked `[ReadProtection]` or `[Unprotected]`.
|
|
33
|
+
3. List every command declared `partial`, private, generic or with a base type from another assembly, every read-model key type that is a record or class with more than one property, and every command spec that replaces or substitutes `IReadModels`.
|
|
34
|
+
4. For an MCP host, list the calls to `MapCratisArcMcp` and `ExposeQuery`, the uses of `McpToolCeiling` and `McpRequiresGatedEndpoints`, and the `GatedEndpoints` selection.
|
|
35
|
+
5. Run the specs and save the result. Done when the lists exist and the specs pass on Arc 22.
|
|
36
|
+
|
|
37
|
+
## Order
|
|
38
|
+
|
|
39
|
+
Read `references/<language>.md` for the application's backend (`.csproj` → csharp) before step 1; this profile installs only the C# reference, because the breaking changes are in the .NET packages.
|
|
40
|
+
|
|
41
|
+
1. **Pin the mode.** Set `<CratisReadProtection>Off</CratisReadProtection>` in every project from inventory step 2 that declares none. This is what Arc 22 did implicitly, so nothing changes yet. Done when the specs still pass.
|
|
42
|
+
2. **Raise the packages.** Raise every Arc package, NuGet and npm, to the latest Arc 23 release in one change, as `cratis-platform-upgrade-application` describes. Done when `dotnet restore` succeeds.
|
|
43
|
+
3. **Fix the MCP host and the obsolete calls** with the replacements in the reference. Done when the solution builds without obsolete warnings from Arc.
|
|
44
|
+
4. **Adopt read protection, one project at a time.** Change `Off` to `Measure`, run the specs and the application, fix what is reported, then remove the property so the project takes the default `On`. Choose to stop at `Off` only when the upgrade must ship without behavior changes; record the adoption as open work, because `Off` leaves every decision unguarded. Done when each project is on `On`, or its `Off` has a recorded reason.
|
|
45
|
+
5. **Cover the keys.** For each project on `On`, clear the generator and accessor failures as the reference describes. Done when the host starts and every command has run once without either exception.
|
|
46
|
+
6. **Rebuild and regenerate the proxies** as `cratis-platform-upgrade-application` describes.
|
|
47
|
+
|
|
48
|
+
## Verify
|
|
49
|
+
|
|
50
|
+
1. `dotnet build` with warnings as errors, then run the specs. Done when both pass, with command state arranged through the scenario's own `Given`.
|
|
51
|
+
2. Start the host with its real configuration. Done when startup reports no refused read-model parameter and no command whose mode was lowered.
|
|
52
|
+
3. Run each command that takes a read model. Under `On`, also test a valid key with no instance for a required protected parameter: expect a `rule` validation result and HTTP 400. A nullable protected parameter receives `null`.
|
|
53
|
+
4. For an MCP host, request `/mcp` and one other route on the capabilities port without credentials. Done when `/mcp` is refused and the other route answers as its gate selection intends.
|
|
54
|
+
5. For the tenancy, server-sent-events, MVC and form rows that apply, repeat the affected request and compare with the Arc 22 result.
|
|
55
|
+
6. Arc 23 brings a newer Chronicle client; apply the kernel order from `cratis-platform-upgrade-application`. Read protection changes how commands read and append, not stored events, so it calls for no replay.
|
|
56
|
+
|
|
57
|
+
## Finish
|
|
58
|
+
|
|
59
|
+
Merge the upgrade, then reinstall the AI corpus with the previous profile list: `cratis ai install --profiles <previous> --harnesses <previous> --languages <previous>`. Done when `.cratis/ai.json` no longer lists `cratis/migrate/arc-22-to-23` and this skill is gone.
|