Skip to content

Commit

Permalink
Use correct translation key for error messages due to max repo limits (
Browse files Browse the repository at this point in the history
…#18135 & #18153) (#18152)

- Backport #18135
- Backport #18153
  • Loading branch information
Gusted authored Jan 2, 2022
1 parent 7e08434 commit f9bbed0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 8 additions & 1 deletion routers/web/repo/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam
case migrations.IsTwoFactorAuthError(err):
ctx.RenderWithErr(ctx.Tr("form.2fa_auth_required"), tpl, form)
case models.IsErrReachLimitOfRepo(err):
ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form)
var msg string
maxCreationLimit := owner.MaxCreationLimit()
if maxCreationLimit == 1 {
msg = ctx.Tr("repo.form.reach_limit_of_creation_1", maxCreationLimit)
} else {
msg = ctx.Tr("repo.form.reach_limit_of_creation_n", maxCreationLimit)
}
ctx.RenderWithErr(msg, tpl, form)
case models.IsErrRepoAlreadyExist(err):
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form)
Expand Down
9 changes: 8 additions & 1 deletion routers/web/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ func Create(ctx *context.Context) {
func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
switch {
case models.IsErrReachLimitOfRepo(err):
ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form)
var msg string
maxCreationLimit := owner.MaxCreationLimit()
if maxCreationLimit == 1 {
msg = ctx.Tr("repo.form.reach_limit_of_creation_1", maxCreationLimit)
} else {
msg = ctx.Tr("repo.form.reach_limit_of_creation_n", maxCreationLimit)
}
ctx.RenderWithErr(msg, tpl, form)
case models.IsErrRepoAlreadyExist(err):
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form)
Expand Down
7 changes: 6 additions & 1 deletion routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,12 @@ func SettingsPost(ctx *context.Context) {
}

if !ctx.Repo.Owner.CanCreateRepo() {
ctx.Flash.Error(ctx.Tr("repo.form.reach_limit_of_creation", ctx.User.MaxCreationLimit()))
maxCreationLimit := ctx.Repo.Owner.MaxCreationLimit()
if maxCreationLimit == 1 {
ctx.Flash.Error(ctx.Tr("repo.form.reach_limit_of_creation_1", maxCreationLimit))
} else {
ctx.Flash.Error(ctx.Tr("repo.form.reach_limit_of_creation_n", maxCreationLimit))
}
ctx.Redirect(repo.Link() + "/settings")
return
}
Expand Down

0 comments on commit f9bbed0

Please sign in to comment.