Skip to content

Commit 5fc7a9e

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Use async await to fix empty quote reply at first time (go-gitea#23168) Fix switched citation format (go-gitea#23250) Improve update-locales script and fix locale processing bug (go-gitea#23240) Refactor `ctx` in templates (go-gitea#23105) Improve frontend guideline (go-gitea#23252) Close the temp file when dumping database to make the temp file can be deleted on Windows (go-gitea#23249) # Conflicts: # templates/repo/issue/view_content/context_menu.tmpl
2 parents a28152f + ffce336 commit 5fc7a9e

File tree

20 files changed

+304
-85
lines changed

20 files changed

+304
-85
lines changed

build/update-locales.sh

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SED=sed
6+
7+
if [[ $OSTYPE == 'darwin'* ]]; then
8+
# for macOS developers, use "brew install gnu-sed"
9+
SED=gsed
10+
fi
11+
12+
if [ ! -f ./options/locale/locale_en-US.ini ]; then
13+
echo "please run this script in the root directory of the project"
14+
exit 1
15+
fi
216

317
mv ./options/locale/locale_en-US.ini ./options/
418

5-
# Make sure to only change lines that have the translation enclosed between quotes
6-
sed -i -r -e '/^[a-zA-Z0-9_.-]+[ ]*=[ ]*".*"$/ {
7-
s/^([a-zA-Z0-9_.-]+)[ ]*="/\1=/
8-
s/\\"/"/g
19+
# the "ini" library for locale has many quirks
20+
# * `a="xx"` gets `xx` (no quote)
21+
# * `a=x\"y` gets `x\"y` (no unescaping)
22+
# * `a="x\"y"` gets `"x\"y"` (no unescaping, the quotes are still there)
23+
# * `a='x\"y'` gets `x\"y` (no unescaping, no quote)
24+
# * `a="foo` gets `"foo` (although the quote is not closed)
25+
# * 'a=`foo`' works like single-quote
26+
# crowdin needs the strings to be quoted correctly and doesn't like incomplete quotes
27+
# crowdin always outputs quoted strings if there are quotes in the strings.
28+
29+
# this script helps to unquote the crowdin outputs for the quirky ini library
30+
# * find all `key="...\"..."` lines
31+
# * remove the leading quote
32+
# * remove the trailing quote
33+
# * unescape the quotes
34+
# * eg: key="...\"..." => key=..."...
35+
$SED -i -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ {
36+
s/^([-.A-Za-z0-9_]+)[ ]*=[ ]*"/\1=/
937
s/"$//
38+
s/\\"/"/g
1039
}' ./options/locale/*.ini
1140

41+
# * if the escaped line is incomplete like `key="...` or `key=..."`, quote it with backticks
42+
# * eg: key="... => key=`"...`
43+
# * eg: key=..." => key=`..."`
44+
$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini
45+
$SED -i -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini
46+
1247
# Remove translation under 25% of en_us
1348
baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1)
1449
baselines=$((baselines / 4))

cmd/dump.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ func runDump(ctx *cli.Context) error {
272272
fatal("Failed to create tmp file: %v", err)
273273
}
274274
defer func() {
275+
_ = dbDump.Close()
275276
if err := util.Remove(dbDump.Name()); err != nil {
276277
log.Warn("Unable to remove temporary file: %s: Error: %v", dbDump.Name(), err)
277278
}

docs/content/doc/developers/guidelines-frontend.en-us.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ It's not recommended to use `async` event listeners, which may lead to problems.
8383
The reason is that the code after await is executed outside the event dispatch.
8484
Reference: https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventdefault.md
8585

86+
If an event listener must be `async`, the `e.preventDefault()` should be before any `await`,
87+
it's recommended to put it at the beginning of the function.
88+
8689
If we want to call an `async` function in a non-async context,
8790
it's recommended to use `const _promise = asyncFoo()` to tell readers
8891
that this is done by purpose, we want to call the async function and ignore the Promise.

options/locale/locale_zh-CN.ini

Lines changed: 185 additions & 8 deletions
Large diffs are not rendered by default.

routers/web/repo/issue.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,7 @@ func ChangeIssueReaction(ctx *context.Context) {
29522952
}
29532953

29542954
html, err := ctx.RenderToString(tplReactions, map[string]interface{}{
2955-
"ctx": ctx.Data,
2955+
"ctxData": ctx.Data,
29562956
"ActionURL": fmt.Sprintf("%s/issues/%d/reactions", ctx.Repo.RepoLink, issue.Index),
29572957
"Reactions": issue.Reactions.GroupByType(),
29582958
})
@@ -3054,7 +3054,7 @@ func ChangeCommentReaction(ctx *context.Context) {
30543054
}
30553055

30563056
html, err := ctx.RenderToString(tplReactions, map[string]interface{}{
3057-
"ctx": ctx.Data,
3057+
"ctxData": ctx.Data,
30583058
"ActionURL": fmt.Sprintf("%s/comments/%d/reactions", ctx.Repo.RepoLink, comment.ID),
30593059
"Reactions": comment.Reactions.GroupByType(),
30603060
})
@@ -3176,7 +3176,7 @@ func updateAttachments(ctx *context.Context, item interface{}, files []string) e
31763176

31773177
func attachmentsHTML(ctx *context.Context, attachments []*repo_model.Attachment, content string) string {
31783178
attachHTML, err := ctx.RenderToString(tplAttachment, map[string]interface{}{
3179-
"ctx": ctx.Data,
3179+
"ctxData": ctx.Data,
31803180
"Attachments": attachments,
31813181
"Content": content,
31823182
})

templates/repo/diff/comments.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
</div>
4343
{{end}}
4444
{{end}}
45-
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $.root "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID)}}
46-
{{template "repo/issue/view_content/context_menu" Dict "ctx" $.root "item" . "delete" true "issue" false "diff" true "IsCommentPoster" (and $.root.IsSigned (eq $.root.SignedUserID .PosterID))}}
45+
{{template "repo/issue/view_content/add_reaction" Dict "ctxData" $.root "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID)}}
46+
{{template "repo/issue/view_content/context_menu" Dict "ctxData" $.root "item" . "delete" true "issue" false "diff" true "IsCommentPoster" (and $.root.IsSigned (eq $.root.SignedUserID .PosterID))}}
4747
</div>
4848
</div>
4949
<div class="ui attached segment comment-body">
@@ -60,7 +60,7 @@
6060
{{$reactions := .Reactions.GroupByType}}
6161
{{if $reactions}}
6262
<div class="ui attached segment reactions">
63-
{{template "repo/issue/view_content/reactions" Dict "ctx" $.root "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) "Reactions" $reactions}}
63+
{{template "repo/issue/view_content/reactions" Dict "ctxData" $.root "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) "Reactions" $reactions}}
6464
</div>
6565
{{end}}
6666
</div>

templates/repo/issue/labels/labels_sidebar.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="ui labels list">
2-
<span class="no-select item {{if .ctx.HasSelectedLabel}}gt-hidden{{end}}">{{.ctx.locale.Tr "repo.issues.new.no_label"}}</span>
2+
<span class="no-select item {{if .root.HasSelectedLabel}}gt-hidden{{end}}">{{.root.locale.Tr "repo.issues.new.no_label"}}</span>
33
<span class="labels-list">
4-
{{range .ctx.Labels}}
4+
{{range .root.Labels}}
55
{{template "repo/issue/labels/label" dict "root" $.root "label" .}}
66
{{end}}
7-
{{range .ctx.OrgLabels}}
7+
{{range .root.OrgLabels}}
88
{{template "repo/issue/labels/label" dict "root" $.root "label" .}}
99
{{end}}
1010
</span>

templates/repo/issue/new_form.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
{{end}}
8181
</div>
8282
</div>
83-
{{template "repo/issue/labels/labels_sidebar" dict "root" $ "ctx" .}}
83+
{{template "repo/issue/labels/labels_sidebar" dict "root" $}}
8484

8585
<div class="ui divider"></div>
8686

templates/repo/issue/view_content.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
{{end}}
6565
{{end}}
6666
{{if not $.Repository.IsArchived}}
67-
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index)}}
68-
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" .Issue "delete" false "issue" true "diff" false "IsCommentPoster" $.IsIssuePoster}}
67+
{{template "repo/issue/view_content/add_reaction" Dict "ctxData" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index)}}
68+
{{template "repo/issue/view_content/context_menu" Dict "ctxData" $ "item" .Issue "delete" false "issue" true "diff" false "IsCommentPoster" $.IsIssuePoster}}
6969
{{end}}
7070
</div>
7171
</div>
@@ -80,13 +80,13 @@
8080
<div id="issue-{{.Issue.ID}}-raw" class="raw-content gt-hidden">{{.Issue.Content}}</div>
8181
<div class="edit-content-zone gt-hidden" data-write="issue-{{.Issue.ID}}-write" data-preview="issue-{{.Issue.ID}}-preview" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/content" data-context="{{.RepoLink}}" data-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/attachments" data-view-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/view-attachments"></div>
8282
{{if .Issue.Attachments}}
83-
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments "Content" .Issue.RenderedContent}}
83+
{{template "repo/issue/view_content/attachments" Dict "ctxData" $ "Attachments" .Issue.Attachments "Content" .Issue.RenderedContent}}
8484
{{end}}
8585
</div>
8686
{{$reactions := .Issue.Reactions.GroupByType}}
8787
{{if $reactions}}
8888
<div class="ui attached segment reactions" role="note">
89-
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) "Reactions" $reactions}}
89+
{{template "repo/issue/view_content/reactions" Dict "ctxData" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) "Reactions" $reactions}}
9090
</div>
9191
{{end}}
9292
</div>

templates/repo/issue/view_content/add_reaction.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{{if .ctx.IsSigned}}
1+
{{if .ctxData.IsSigned}}
22
<div class="item action ui pointing select-reaction dropdown top right" data-action-url="{{.ActionURL}}">
33
<a class="add-reaction">
44
{{svg "octicon-smiley"}}
55
</a>
66
<div class="menu">
7-
<div class="header">{{.ctx.locale.Tr "repo.pick_reaction"}}</div>
7+
<div class="header">{{.ctxData.locale.Tr "repo.pick_reaction"}}</div>
88
<div class="divider"></div>
99
{{range $value := AllowedReactions}}
1010
<a class="item reaction tooltip" data-content="{{$value}}">{{ReactionToEmoji $value}}</a>

0 commit comments

Comments
 (0)