fix(i18n): preserve translate ok in debug mode

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 06:39:39 +00:00
parent 94e6c2d5d7
commit 50dcc47836
2 changed files with 25 additions and 0 deletions

View file

@ -83,3 +83,20 @@ func TestDebugMode_Good_Integration(t *testing.T) {
got = svc.Raw("prompt.yes")
assert.Equal(t, "[prompt.yes] y", got)
}
func TestTranslate_DebugMode_PreservesOK(t *testing.T) {
svc, err := New()
require.NoError(t, err)
SetDefault(svc)
svc.SetDebug(true)
defer svc.SetDebug(false)
translated := svc.Translate("prompt.yes")
assert.True(t, translated.OK)
assert.Equal(t, "[prompt.yes] y", translated.Value)
missing := svc.Translate("missing.translation.key")
assert.False(t, missing.OK)
assert.Equal(t, "[missing.translation.key] missing.translation.key", missing.Value)
}

View file

@ -905,6 +905,14 @@ func (s *Service) markLocaleProviderLoaded(id int) {
}
func translateOK(messageID, value string) bool {
if value == "" {
return false
}
if strings.HasPrefix(value, "["+messageID+"] ") {
value = strings.TrimPrefix(value, "["+messageID+"] ")
} else if value == "["+messageID+"]" {
value = ""
}
if value == "" {
return false
}