mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-04 08:14:43 +01:00
fix(i18n): use translate key as fallback
- If the translate key is nonsense (not seen in any of the languages) then the translate key as-is should be returned as value, this helps during development. Currently it displays the first entry of the locale store which is "Home". - Regression from forgejo/forgejo#6203. - Added unit test.
This commit is contained in:
parent
9f3507e726
commit
15aa35a809
2 changed files with 4 additions and 3 deletions
|
@ -158,6 +158,7 @@ commits = fallback value for commits
|
||||||
|
|
||||||
found := lang1.HasKey("no-such")
|
found := lang1.HasKey("no-such")
|
||||||
assert.False(t, found)
|
assert.False(t, found)
|
||||||
|
assert.EqualValues(t, "no-such", lang1.TrString("no-such"))
|
||||||
require.NoError(t, ls.Close())
|
require.NoError(t, ls.Close())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,9 +225,9 @@ func (l *locale) TrString(trKey string, trArgs ...any) string {
|
||||||
format = msg
|
format = msg
|
||||||
} else {
|
} else {
|
||||||
// First fallback: old-style translation
|
// First fallback: old-style translation
|
||||||
idx, ok := l.store.trKeyToIdxMap[trKey]
|
idx, foundIndex := l.store.trKeyToIdxMap[trKey]
|
||||||
found := false
|
found := false
|
||||||
if ok {
|
if foundIndex {
|
||||||
if msg, ok := l.idxToMsgMap[idx]; ok {
|
if msg, ok := l.idxToMsgMap[idx]; ok {
|
||||||
format = msg // use the found translation
|
format = msg // use the found translation
|
||||||
found = true
|
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 defaultLang, ok := l.store.localeMap[l.store.defaultLang]; ok {
|
||||||
if msg := defaultLang.LookupNewStyleMessage(trKey); msg != "" {
|
if msg := defaultLang.LookupNewStyleMessage(trKey); msg != "" {
|
||||||
format = msg
|
format = msg
|
||||||
} else {
|
} else if foundIndex {
|
||||||
// Third fallback: old-style default language
|
// Third fallback: old-style default language
|
||||||
if msg, ok := defaultLang.idxToMsgMap[idx]; ok {
|
if msg, ok := defaultLang.idxToMsgMap[idx]; ok {
|
||||||
format = msg
|
format = msg
|
||||||
|
|
Loading…
Add table
Reference in a new issue