fix(i18n): preserve translate ok in debug mode
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
94e6c2d5d7
commit
50dcc47836
2 changed files with 25 additions and 0 deletions
|
|
@ -83,3 +83,20 @@ func TestDebugMode_Good_Integration(t *testing.T) {
|
||||||
got = svc.Raw("prompt.yes")
|
got = svc.Raw("prompt.yes")
|
||||||
assert.Equal(t, "[prompt.yes] y", got)
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -905,6 +905,14 @@ func (s *Service) markLocaleProviderLoaded(id int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func translateOK(messageID, value string) bool {
|
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 == "" {
|
if value == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue