feat(10-02): backend strings, controller messages and declarative toolbar

- phrasebook ships the backend::lang admin strings (pl, en) with CLDR
  plural maps, loads them as namespace backend, applies
  pact.HasLangOverrides trees (lang/<locale>/<namespace>/<group>.yaml)
  after every namespace, and fails activation when a backend key cannot
  convert to plural forms
- Translator.Forms, Bundle, Resolved and Has serve keys as CLDR form maps
- Public GET /lang returns every backend::lang key for the request
  locale over the fallback locale, Cache-Control no-cache
- config_list, config_form and config_relation accept a strict messages
  block; omitted keys take framework defaults, schemas serve every message
  as CLDR forms, and activation fails on a missing phrase key
- toolbar.buttons is an ordered [create, delete] list; the Winter string
  form, duplicates, unknown actions and delete without showCheckboxes fail
  at boot, and create is dropped when the controller has no form
- Form schema serves the raw Winter redirects; scaffold emits the list
  syntax; form and relation schema routes are typed in the admin OpenAPI
This commit is contained in:
Jakub Zych
2026-09-27 16:16:32 +02:00
parent fe04dbc89e
commit c87148a34f
24 changed files with 2148 additions and 45 deletions

View File

@@ -1,6 +1,9 @@
package cabana
import "encoding/json"
import (
"context"
"encoding/json"
)
// ListSort is the compiled default sort. Direction is exactly asc or desc.
type ListSort struct {
@@ -68,11 +71,20 @@ type ListSchema struct {
Filters []ListFilter `json:"filters"`
RowActions []RowAction `json:"rowActions"`
BulkActions []BulkAction `json:"bulkActions"`
Meta *FormMeta `json:"meta,omitempty"`
// Messages is the list's copy (D-13). The cached schema carries each
// phrase key as its own form; a response resolves them in its locale.
Messages *ListMessages `json:"messages"`
Meta *FormMeta `json:"meta,omitempty"`
messageKeys listMessageKeys
}
// MarshalJSON keeps omitted collections as arrays so a partial copy cannot emit null.
func (s ListSchema) MarshalJSON() ([]byte, error) {
if s.Messages == nil {
keys := localizeMessages[listMessageKeys, ListMessages](context.Background(), nil, s.listMessageKeySet())
s.Messages = &keys
}
type alias ListSchema
out := alias(s)
if out.PerPageOptions == nil {
@@ -102,6 +114,9 @@ type FormSchema struct {
Name string `json:"name,omitempty"`
ModelClass string `json:"modelClass,omitempty"`
Fields []FormField `json:"fields"`
messageKeys formMessageKeys
redirects FormRedirects
}
// FormView is one request's localized form, including the locale actually used.
@@ -109,7 +124,25 @@ type FormView struct {
Name string `json:"name,omitempty"`
ModelClass string `json:"modelClass,omitempty"`
Fields []FormField `json:"fields"`
Meta FormMeta `json:"meta"`
// Messages is the form's copy resolved in the request locale (D-13).
Messages FormMessages `json:"messages"`
// Redirects are the raw Winter config_form.yaml targets; the SPA maps
// them onto its routes.
Redirects FormRedirects `json:"redirects"`
Meta FormMeta `json:"meta"`
}
// FormRedirects are config_form.yaml defaultRedirect, create.* and update.*.
type FormRedirects struct {
Default string `json:"default"`
Create FormRedirect `json:"create"`
Update FormRedirect `json:"update"`
}
// FormRedirect is one Winter redirect pair.
type FormRedirect struct {
Redirect string `json:"redirect"`
RedirectClose string `json:"redirectClose"`
}
// FormMeta reports the locale selected for a schema response.