diff --git a/modules/translation/i18n/i18n_test.go b/modules/translation/i18n/i18n_test.go index 66f5d5c402..a0458f0b8e 100644 --- a/modules/translation/i18n/i18n_test.go +++ b/modules/translation/i18n/i18n_test.go @@ -156,7 +156,15 @@ commits = fallback value for commits assert.ElementsMatch(t, []string{"lang1", "lang2"}, langs) assert.ElementsMatch(t, []string{"Lang1", "Lang2"}, descs) - found := lang1.HasKey("no-such") + // Test HasKey for JSON + found := lang2.HasKey("section.json") + assert.True(t, found) + + // Test HasKey for INI + found = lang2.HasKey("section.sub") + assert.True(t, found) + + found = lang1.HasKey("no-such") assert.False(t, found) assert.EqualValues(t, "no-such", lang1.TrString("no-such")) require.NoError(t, ls.Close()) diff --git a/modules/translation/i18n/localestore.go b/modules/translation/i18n/localestore.go index a38e967838..0cfa96810e 100644 --- a/modules/translation/i18n/localestore.go +++ b/modules/translation/i18n/localestore.go @@ -303,6 +303,10 @@ func (l *locale) TrPluralString(count any, trKey string, trArgs ...any) template // HasKey returns whether a key is present in this locale or not func (l *locale) HasKey(trKey string) bool { + _, ok := l.newStyleMessages[trKey] + if ok { + return true + } idx, ok := l.store.trKeyToIdxMap[trKey] if !ok { return false