Skip to content

Commit 67e81c6

Browse files
wxiaoguangStelios Malathouras
authored and
Stelios Malathouras
committed
Fix the missing i18n key for update checker (go-gitea#18646)
1 parent 303045c commit 67e81c6

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

modules/translation/translation.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ func AllLangs() []LangType {
3939
return allLangs
4040
}
4141

42+
// TryTr tries to do the translation, if no translation, it returns (format, false)
43+
func TryTr(lang, format string, args ...interface{}) (string, bool) {
44+
s := i18n.Tr(lang, format, args...)
45+
// now the i18n library is not good enough and we can only use this hacky method to detect whether the transaction exists
46+
idx := strings.IndexByte(format, '.')
47+
defaultText := format
48+
if idx > 0 {
49+
defaultText = format[idx+1:]
50+
}
51+
return s, s != defaultText
52+
}
53+
4254
// InitLocales loads the locales
4355
func InitLocales() {
4456
i18n.Reset()

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,7 @@ dashboard.last_gc_pause = Last GC Pause
24362436
dashboard.gc_times = GC Times
24372437
dashboard.delete_old_actions = Delete all old actions from database
24382438
dashboard.delete_old_actions.started = Delete all old actions from database started.
2439+
dashboard.update_checker = Update checker
24392440

24402441
users.user_manage_panel = User Account Management
24412442
users.new_account = Create User Account

services/cron/tasks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"code.gitea.io/gitea/modules/log"
1818
"code.gitea.io/gitea/modules/process"
1919
"code.gitea.io/gitea/modules/setting"
20+
"code.gitea.io/gitea/modules/translation"
2021
)
2122

2223
var (
@@ -121,6 +122,12 @@ func GetTask(name string) *Task {
121122
// RegisterTask allows a task to be registered with the cron service
122123
func RegisterTask(name string, config Config, fun func(context.Context, *user_model.User, Config) error) error {
123124
log.Debug("Registering task: %s", name)
125+
126+
i18nKey := "admin.dashboard." + name
127+
if _, ok := translation.TryTr("en-US", i18nKey); !ok {
128+
return fmt.Errorf("translation is missing for task %q, please add translation for %q", name, i18nKey)
129+
}
130+
124131
_, err := setting.GetCronSettings(name, config)
125132
if err != nil {
126133
log.Error("Unable to register cron task with name: %s Error: %v", name, err)

0 commit comments

Comments
 (0)