Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the missing i18n key for update checker #18646

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ func AllLangs() []LangType {
return allLangs
}

// TryTr tries to do the translation, if no translation, it returns (format, false)
func TryTr(lang, format string, args ...interface{}) (string, bool) {
s := i18n.Tr(lang, format, args...)
// now the i18n library is not good enough and we can only use this hacky method to detect whether the transaction exists
idx := strings.IndexByte(format, '.')
defaultText := format
if idx > 0 {
defaultText = format[idx+1:]
}
return s, s != defaultText
}

// InitLocales loads the locales
func InitLocales() {
i18n.Reset()
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,7 @@ dashboard.last_gc_pause = Last GC Pause
dashboard.gc_times = GC Times
dashboard.delete_old_actions = Delete all old actions from database
dashboard.delete_old_actions.started = Delete all old actions from database started.
dashboard.update_checker = Update checker

users.user_manage_panel = User Account Management
users.new_account = Create User Account
Expand Down
7 changes: 7 additions & 0 deletions services/cron/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/translation"
)

var (
Expand Down Expand Up @@ -121,6 +122,12 @@ func GetTask(name string) *Task {
// RegisterTask allows a task to be registered with the cron service
func RegisterTask(name string, config Config, fun func(context.Context, *user_model.User, Config) error) error {
log.Debug("Registering task: %s", name)

i18nKey := "admin.dashboard." + name
if _, ok := translation.TryTr("en-US", i18nKey); !ok {
lunny marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("translation is missing for task %q, please add translation for %q", name, i18nKey)
}

_, err := setting.GetCronSettings(name, config)
if err != nil {
log.Error("Unable to register cron task with name: %s Error: %v", name, err)
Expand Down