fix(i18n): use translate key as fallback (#6702)
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6702
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Otto 2025-01-29 00:12:51 +00:00
commit bd6864fe1f
2 changed files with 4 additions and 3 deletions

View file

@ -158,6 +158,7 @@ commits = fallback value for commits
found := lang1.HasKey("no-such")
assert.False(t, found)
assert.EqualValues(t, "no-such", lang1.TrString("no-such"))
require.NoError(t, ls.Close())
}

View file

@ -225,9 +225,9 @@ func (l *locale) TrString(trKey string, trArgs ...any) string {
format = msg
} else {
// First fallback: old-style translation
idx, ok := l.store.trKeyToIdxMap[trKey]
idx, foundIndex := l.store.trKeyToIdxMap[trKey]
found := false
if ok {
if foundIndex {
if msg, ok := l.idxToMsgMap[idx]; ok {
format = msg // use the found translation
found = true
@ -239,7 +239,7 @@ func (l *locale) TrString(trKey string, trArgs ...any) string {
if defaultLang, ok := l.store.localeMap[l.store.defaultLang]; ok {
if msg := defaultLang.LookupNewStyleMessage(trKey); msg != "" {
format = msg
} else {
} else if foundIndex {
// Third fallback: old-style default language
if msg, ok := defaultLang.idxToMsgMap[idx]; ok {
format = msg