feat(14.2.1-05): hydrate ML create/GET/save through TranslatedExact

Form schema meta lists enabled locales, Show/save expand mltext maps
without D-11 fallback, and the SPA seeds and adopt-merges every locale.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-10-06 15:37:00 +02:00
parent ed81f2a0c1
commit 0f8d13738d
11 changed files with 309 additions and 34 deletions

View File

@@ -95,6 +95,25 @@ func (w *recordingWriter) WriteTranslated(_ context.Context, _ *gorm.DB, model a
return nil
}
func (w *recordingWriter) TranslatedExact(_ context.Context, _ *gorm.DB, model any, field, locale string) (string, bool, error) {
if locale == w.defaultLocale {
post, _ := model.(*mlPost)
if post == nil {
return "", false, nil
}
return post.Title, true, nil
}
if w.attrs == nil {
return "", false, nil
}
vals := w.attrs[locale]
if vals == nil {
return "", false, nil
}
text, ok := vals[field]
return text, ok, nil
}
func mlFS() fstest.MapFS {
return fstest.MapFS{
"controllers/posts/config_list.yaml": &fstest.MapFile{Data: []byte(mlListConfig)},
@@ -181,8 +200,13 @@ func TestMLNestedSaveSmoke(t *testing.T) {
if err != nil {
t.Fatalf("create: %v", err)
}
if rec["title"] != "Hello" {
t.Fatalf("projected title = %#v, want Hello", rec["title"])
if rec["title"] != nil {
got, ok := rec["title"].(map[string]string)
if !ok || got["en"] != "Hello" || got["pl"] != "Witaj" {
t.Fatalf("projected title = %#v, want hydrated en+pl map", rec["title"])
}
} else {
t.Fatalf("projected title = %#v, want hydrated en+pl map", rec["title"])
}
var row mlPost
if err := db.First(&row).Error; err != nil {