fix(i18n): make HasKey aware of newStyleMessages (#7166)
Followup to https://codeberg.org/forgejo/forgejo/pulls/6203 Related to https://codeberg.org/forgejo/forgejo/pulls/6154 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7166 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
parent
eb78c6618b
commit
3db9de3b53
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue