From ad4d893ad57ea01b2eb0912248fa1a6309df8a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Niclas=20Oelschl=C3=A4ger?= Date: Fri, 9 Feb 2024 20:13:10 +0100 Subject: [PATCH] refactor: use translations to support rtl --- modules/templates/helper.go | 1 + modules/templates/util_render.go | 18 ++++++++++++++++++ options/locale/locale_en-US.ini | 4 ++-- templates/shared/issue_dependency.tmpl | 16 ++++------------ templates/shared/issuelist.tmpl | 10 ++++------ 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 0997239a55..532fc7989e 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -165,6 +165,7 @@ func NewFuncMap() template.FuncMap { "RenderMarkdownToHtml": RenderMarkdownToHtml, "RenderLabel": RenderLabel, "RenderLabels": RenderLabels, + "RenderDependencies": RenderDependencies, // ----------------------------------------------------------------- // misc diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index cdff31698c..ead41faa32 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -224,3 +224,21 @@ func RenderLabels(ctx context.Context, labels []*issues_model.Label, repoLink st htmlCode += "" return template.HTML(htmlCode) } + +func RenderDependencies(ctx context.Context, dependencies []*issues_model.DependencyInfo) template.HTML { + if dependencies == nil || len(dependencies) < 1 { + return "" + } + + htmlCode := "" + + for index, dependency := range dependencies { + if index != 0 { + htmlCode += `,` + } + htmlCode += fmt.Sprintf(`#%d`, + dependency.Issue.Link(), dependency.Issue.Index, RenderEmoji(ctx, dependency.Issue.Title), dependency.Issue.Index) + } + + return template.HTML(htmlCode) +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 9df6bf658e..ad7e68bbc1 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1685,9 +1685,9 @@ issues.dependency.issue_close_blocked = You need to close all issues blocking th issues.dependency.issue_batch_close_blocked = "Cannot batch close issues that you choose, because issue #%d still has open dependencies" issues.dependency.pr_close_blocked = You need to close all issues blocking this pull request before you can merge it. issues.dependency.blocks_short = Blocks -issues.dependency.blocks_following = Blocks: +issues.dependency.blocks_following = Blocks: %s issues.dependency.blocked_by_short = Depends on -issues.dependency.blocked_by_following = Depends on: +issues.dependency.blocked_by_following = Depends on: %s issues.dependency.remove_header = Remove Dependency issues.dependency.issue_remove_text = This will remove the dependency from this issue. Continue? issues.dependency.pr_remove_text = This will remove the dependency from this pull request. Continue? diff --git a/templates/shared/issue_dependency.tmpl b/templates/shared/issue_dependency.tmpl index 09d3acd27f..481cba8229 100644 --- a/templates/shared/issue_dependency.tmpl +++ b/templates/shared/issue_dependency.tmpl @@ -1,13 +1,5 @@ -{{if and .DependenciesMap (index .DependenciesMap .ID)}} -
- {{.Title}} - {{$first := true}} - {{range (index .DependenciesMap .ID)}} - {{if not $first}},{{end}} - {{$first = false}} - - #{{.Issue.Index}} - - {{end}} -
+{{if .Dependencies}} +
+ {{(ctx.Locale.Tr .TitleKey (RenderDependencies ctx .Dependencies)) | Safe}} +
{{end}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 7cec6822ae..b040a9083d 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -119,13 +119,11 @@ {{end}} {{template "shared/issue_dependency" (dict - "ID" .ID - "DependenciesMap" $.BlockingDependenciesMap - "Title" (ctx.Locale.Tr "repo.issues.dependency.blocks_following"))}} + "Dependencies" (index $.BlockingDependenciesMap .ID) + "TitleKey" "repo.issues.dependency.blocks_following")}} {{template "shared/issue_dependency" (dict - "ID" .ID - "DependenciesMap" $.BlockedByDependenciesMap - "Title" (ctx.Locale.Tr "repo.issues.dependency.blocked_by_following"))}} + "Dependencies" (index $.BlockedByDependenciesMap .ID) + "TitleKey" "repo.issues.dependency.blocked_by_following")}} {{if .IsPull}} {{$approveOfficial := call $approvalCounts .ID "approve"}} {{$rejectOfficial := call $approvalCounts .ID "reject"}}