refactor(i18n): centralise namespace lookups
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 07:43:40 +00:00
parent 7332f5bd1c
commit dd9d0832af
2 changed files with 12 additions and 4 deletions

View file

@ -15,3 +15,11 @@ func defaultServiceValue[T any](fallback T, fn func(*Service) T) T {
} }
return fallback return fallback
} }
// defaultServiceNamespaceValue resolves a namespace key against the default
// service when available, or returns the namespace-qualified key otherwise.
func defaultServiceNamespaceValue(namespace, key string, lookup func(*Service, string) string) string {
return defaultServiceValue(namespaceLookupKey(namespace, key), func(svc *Service) string {
return lookup(svc, key)
})
}

View file

@ -243,8 +243,8 @@ func N(format string, value any, args ...any) string {
// Prompt("yes") // "y" // Prompt("yes") // "y"
// Prompt("confirm") // "Are you sure?" // Prompt("confirm") // "Are you sure?"
func Prompt(key string) string { func Prompt(key string) string {
return defaultServiceValue("", func(svc *Service) string { return defaultServiceNamespaceValue("prompt", key, func(svc *Service, resolved string) string {
return svc.Prompt(key) return svc.Prompt(resolved)
}) })
} }
@ -265,8 +265,8 @@ func CurrentPrompt(key string) string {
// //
// Lang("de") // "German" // Lang("de") // "German"
func Lang(key string) string { func Lang(key string) string {
return defaultServiceValue("", func(svc *Service) string { return defaultServiceNamespaceValue("lang", key, func(svc *Service, resolved string) string {
return svc.Lang(key) return svc.Lang(resolved)
}) })
} }