Skip to content

Commit 3db9de3

Browse files
0koGusted
authored andcommitted
fix(i18n): make HasKey aware of newStyleMessages (go-gitea#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 <[email protected]> Co-authored-by: 0ko <[email protected]> Co-committed-by: 0ko <[email protected]>
1 parent eb78c66 commit 3db9de3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

modules/translation/i18n/i18n_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,15 @@ commits = fallback value for commits
156156
assert.ElementsMatch(t, []string{"lang1", "lang2"}, langs)
157157
assert.ElementsMatch(t, []string{"Lang1", "Lang2"}, descs)
158158

159-
found := lang1.HasKey("no-such")
159+
// Test HasKey for JSON
160+
found := lang2.HasKey("section.json")
161+
assert.True(t, found)
162+
163+
// Test HasKey for INI
164+
found = lang2.HasKey("section.sub")
165+
assert.True(t, found)
166+
167+
found = lang1.HasKey("no-such")
160168
assert.False(t, found)
161169
assert.EqualValues(t, "no-such", lang1.TrString("no-such"))
162170
require.NoError(t, ls.Close())

modules/translation/i18n/localestore.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ func (l *locale) TrPluralString(count any, trKey string, trArgs ...any) template
303303

304304
// HasKey returns whether a key is present in this locale or not
305305
func (l *locale) HasKey(trKey string) bool {
306+
_, ok := l.newStyleMessages[trKey]
307+
if ok {
308+
return true
309+
}
306310
idx, ok := l.store.trKeyToIdxMap[trKey]
307311
if !ok {
308312
return false

0 commit comments

Comments
 (0)