From d64099b02824770c7bcac2c191e4d383a2c2a4e2 Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 17 Mar 2026 01:31:19 +0000 Subject: [PATCH] feat(core): add LocaleProvider interface for automatic i18n collection Services implementing LocaleProvider have their locale FS collected during RegisterService. The i18n service reads Core.Locales() on startup to load all translations. Zero explicit wiring needed. Co-Authored-By: Virgil --- pkg/core/core.go | 6 ++++++ pkg/core/interfaces.go | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/core/core.go b/pkg/core/core.go index eb7c64b..99b9e37 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -295,7 +295,13 @@ func (c *Core) RegisterTask(handler TaskHandler) { } // RegisterService adds a new service to the Core. +// If the service implements LocaleProvider, its locale FS is collected +// for the i18n service to load during startup. func (c *Core) RegisterService(name string, api any) error { + // Collect locale filesystems from services that provide them + if lp, ok := api.(LocaleProvider); ok { + c.locales = append(c.locales, lp.Locales()) + } return c.svc.registerService(name, api) } diff --git a/pkg/core/interfaces.go b/pkg/core/interfaces.go index 036b4b2..f8b4ad4 100644 --- a/pkg/core/interfaces.go +++ b/pkg/core/interfaces.go @@ -4,6 +4,7 @@ import ( "context" "embed" goio "io" + "io/fs" "slices" "sync" "sync/atomic" @@ -77,6 +78,20 @@ type Stoppable interface { OnShutdown(ctx context.Context) error } +// LocaleProvider is implemented by services that ship their own translation files. +// Core discovers this interface during service registration and collects the +// locale filesystems. The i18n service loads them during startup. +// +// Usage in a service package: +// +// //go:embed locales +// var localeFS embed.FS +// +// func (s *MyService) Locales() fs.FS { return localeFS } +type LocaleProvider interface { + Locales() fs.FS +} + // Core is the central application object that manages services, assets, and communication. type Core struct { App any // GUI runtime (e.g., Wails App) - set by WithApp option @@ -84,12 +99,19 @@ type Core struct { Features *Features svc *serviceManager bus *messageBus + locales []fs.FS // collected from LocaleProvider services taskIDCounter atomic.Uint64 wg sync.WaitGroup shutdown atomic.Bool } +// Locales returns all locale filesystems collected from registered services. +// The i18n service uses this during startup to load translations. +func (c *Core) Locales() []fs.FS { + return c.locales +} + // Config provides access to application configuration. type Config interface { // Get retrieves a configuration value by key and stores it in the 'out' variable.