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.