feat(04-02): load namespaced translations from embedded plugins

- Walk HasLang FS for lang/<locale>/<group>.yaml and flatten nested keys
- Publish one phrasebook.Translator before Boot with en/en defaults
- Hello plugin resolves en/pl vendor.plugin::group.key after Activate

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-09-18 13:47:45 +02:00
parent e7dba5c4fb
commit f824e55c81
9 changed files with 635 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ import (
"git.golem15.com/golem15/summercms/compass"
"git.golem15.com/golem15/summercms/pact"
"git.golem15.com/golem15/summercms/party"
"git.golem15.com/golem15/summercms/phrasebook"
"git.golem15.com/golem15/summercms/surf"
)
@@ -107,6 +108,30 @@ func TestBuiltBinaryGreeterHello(t *testing.T) {
assertGreeting(t, got, want)
}
func TestHelloPluginResolvesLang(t *testing.T) {
cfg, err := compass.Load("config")
if err != nil {
t.Fatal(err)
}
app := backpack.New(cfg)
if _, err := party.Activate(app, []string{"golem15.hello"}); err != nil {
t.Fatal(err)
}
tr, ok := app.Lookup[*phrasebook.Translator]()
if !ok {
t.Fatal("translator not published")
}
if got := tr.GetIn("en", "golem15.hello::lang.labels.pluginName", nil); got != "Hello plugin" {
t.Fatalf("en = %q", got)
}
if got := tr.GetIn("pl", "golem15.hello::lang.labels.pluginName", nil); got != "Wtyczka Hello" {
t.Fatalf("pl = %q", got)
}
if got := tr.GetIn("en", "golem15.hello::lang.greeting", nil); got != "Hello" {
t.Fatalf("greeting = %q", got)
}
}
func TestTypedItemRoute(t *testing.T) {
cfg, err := compass.Load("config")
if err != nil {

View File

@@ -0,0 +1,3 @@
greeting: Hello
labels:
pluginName: Hello plugin

View File

@@ -0,0 +1,3 @@
greeting: Cześć
labels:
pluginName: Wtyczka Hello

View File

@@ -9,11 +9,17 @@ import (
"git.golem15.com/golem15/summercms/party"
)
var _ pact.HasConfig = (*Plugin)(nil)
var (
_ pact.HasConfig = (*Plugin)(nil)
_ pact.HasLang = (*Plugin)(nil)
)
//go:embed config
var configFS embed.FS
//go:embed lang
var langFS embed.FS
// Plugin is the golem15.hello plugin.
type Plugin struct{}
@@ -24,6 +30,7 @@ func (p *Plugin) Register(*backpack.App) error { return nil }
func (p *Plugin) Boot(*backpack.App) error { return nil }
func (p *Plugin) ConfigFS() fs.FS { return configFS }
func (p *Plugin) LangFS() fs.FS { return langFS }
func init() {
party.Register(&Plugin{})