From f9a22b335e80bccd5e224c492ecb512c06dcc805 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Mon, 23 Feb 2026 06:03:23 +0100 Subject: [PATCH] fix(ui): hardcode sort options in search syntax hint, improve look (#11381) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to https://codeberg.org/forgejo/forgejo/pulls/9109 Fix issue reported by @mahlzahn that the string was confusing translators and they translated the part that wasn't meant to be translated. Part of this fix was to replace custom IterWithTr with simple dict iteration to allow for placeholders in strings. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11381 Reviewed-by: Shiny Nematoda Reviewed-by: Ellen Εμιλία Άννα Zscheile --- build/lint-locale-usage/handle-tmpl.go | 6 ------ modules/translation/translation.go | 11 ----------- options/locale_next/locale_en-US.json | 2 +- templates/shared/search/issue/syntax.tmpl | 24 +++++++++++------------ 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/build/lint-locale-usage/handle-tmpl.go b/build/lint-locale-usage/handle-tmpl.go index e8d4832f9d..8d03291205 100644 --- a/build/lint-locale-usage/handle-tmpl.go +++ b/build/lint-locale-usage/handle-tmpl.go @@ -73,12 +73,6 @@ func (handler Handler) handleTemplateNode(fset *token.FileSet, node tmplParser.N funcname = nodeVar.Ident[2] } - if funcname == "IterWithTr" { - for i := 2; i < len(nodeCommand.Args); i += 2 { - handler.handleTemplateMsgid(fset, nodeCommand.Args[i]) - } - } - var gotUnexpectedInvoke *int ltf, ok := handler.LocaleTrFunctions[funcname] if !ok { diff --git a/modules/translation/translation.go b/modules/translation/translation.go index fdd71fe608..f2d77ac340 100644 --- a/modules/translation/translation.go +++ b/modules/translation/translation.go @@ -7,7 +7,6 @@ package translation import ( "context" "html/template" - "iter" "sort" "strings" "sync" @@ -329,16 +328,6 @@ func (l *locale) PrettyNumber(v any) string { return l.msgPrinter.Sprintf("%v", number.Decimal(v)) } -func (l *locale) IterWithTr(kvs ...string) iter.Seq2[string, template.HTML] { - return func(yield func(string, template.HTML) bool) { - for i := 0; i < len(kvs); i += 2 { - if !yield(kvs[i], l.TrHTML(kvs[i+1])) { - return - } - } - } -} - func GetPluralRule(l Locale) int { return GetPluralRuleImpl(l.Language()) } diff --git a/options/locale_next/locale_en-US.json b/options/locale_next/locale_en-US.json index 9bd18cd565..9047ca393c 100644 --- a/options/locale_next/locale_en-US.json +++ b/options/locale_next/locale_en-US.json @@ -57,7 +57,7 @@ "repo.issues.filter_reviewers.hint": "Filter by user who reviewed", "repo.issues.filter_mention.hint": "Filter by mentioned user", "repo.issues.filter_modified.hint": "Filter by last modified date", - "repo.issues.filter_sort.hint": "Sort by: created/comments/updated/deadline", + "repo.issues.filter_sort.hint_with_placeholder": "Sort by: %s", "issues.updated": "updated %s", "issues.filters.labels.exclude": "Exclude label", "issues.filters.labels.unexclude": "Clear exclusion", diff --git a/templates/shared/search/issue/syntax.tmpl b/templates/shared/search/issue/syntax.tmpl index 737f386b1b..76e6ef2638 100644 --- a/templates/shared/search/issue/syntax.tmpl +++ b/templates/shared/search/issue/syntax.tmpl @@ -6,26 +6,26 @@ {{range $filter, $tr := - ctx.Locale.IterWithTr - "is:open" "repo.issues.open_title" - "is:closed" "repo.issues.closed_title" - "is:all" "repo.issues.all_title" - "author:" "repo.issues.filter_poster.hint" - "assignee:" "repo.issues.filter_assignee.hint" - "review:" "repo.issues.filter_reviewers.hint" - "mentions:" "repo.issues.filter_mention.hint" - "sort::[asc|desc]" "repo.issues.filter_sort.hint" - "modified:[>|<]" "repo.issues.filter_modified.hint"}} + dict + "is:open" (ctx.Locale.TrString "repo.issues.open_title") + "is:closed" (ctx.Locale.TrString "repo.issues.closed_title") + "is:all" (ctx.Locale.TrString "repo.issues.all_title") + "author:" (ctx.Locale.TrString "repo.issues.filter_poster.hint") + "assignee:" (ctx.Locale.TrString "repo.issues.filter_assignee.hint") + "review:" (ctx.Locale.TrString "repo.issues.filter_reviewers.hint") + "mentions:" (ctx.Locale.TrString "repo.issues.filter_mention.hint") + "sort::[asc|desc]" (ctx.Locale.Tr "repo.issues.filter_sort.hint_with_placeholder" (HTMLFormat "created|comments|updated|deadline")) + "modified:[>|<]" (ctx.Locale.TrString "repo.issues.filter_modified.hint")}} - + {{end}}
{{$filter}}{{$tr | SafeHTML}}{{$tr}}