diff --git a/i18n.go b/i18n.go index cb332f7..e8e2025 100644 --- a/i18n.go +++ b/i18n.go @@ -239,11 +239,9 @@ func N(format string, value any, args ...any) string { // Prompt("yes") // "y" // Prompt("confirm") // "Are you sure?" func Prompt(key string) string { - key = normalizeLookupKey(key) - if key == "" { - return "" - } - return T(namespaceLookupKey("prompt", key)) + return defaultServiceValue("", func(svc *Service) string { + return svc.Prompt(key) + }) } // CurrentPrompt is a short alias for Prompt. @@ -263,21 +261,9 @@ func CurrentPrompt(key string) string { // // Lang("de") // "German" func Lang(key string) string { - key = normalizeLookupKey(key) - if key == "" { - return "" - } - if got := T(namespaceLookupKey("lang", key)); got != namespaceLookupKey("lang", key) { - return got - } - if idx := indexAny(key, "-_"); idx > 0 { - if base := key[:idx]; base != "" { - if got := T(namespaceLookupKey("lang", base)); got != namespaceLookupKey("lang", base) { - return got - } - } - } - return namespaceLookupKey("lang", key) + return defaultServiceValue("", func(svc *Service) string { + return svc.Lang(key) + }) } func normalizeLookupKey(key string) string { diff --git a/service.go b/service.go index da70824..44d0f75 100644 --- a/service.go +++ b/service.go @@ -403,18 +403,24 @@ func (s *Service) Lang(key string) string { return "" } lookupKey := namespaceLookupKey("lang", key) - if text, ok := s.translateWithStatus(lookupKey); ok { + s.mu.RLock() + text := s.resolveDirectLocked(lookupKey, nil) + s.mu.RUnlock() + if text != "" { return text } if idx := indexAny(key, "-_"); idx > 0 { if base := key[:idx]; base != "" { baseLookupKey := namespaceLookupKey("lang", base) - if text, ok := s.translateWithStatus(baseLookupKey); ok { + s.mu.RLock() + text = s.resolveDirectLocked(baseLookupKey, nil) + s.mu.RUnlock() + if text != "" { return text } } } - return lookupKey + return s.handleMissingKey(lookupKey, nil) } func (s *Service) AvailableLanguages() []string {