Skip to content

Commit d5f70c6

Browse files
committed
pass language to metas
1 parent 262ef11 commit d5f70c6

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

modules/markup/html.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ package markup
55

66
import (
77
"bytes"
8+
"fmt"
89
"io"
910
"net/url"
1011
"path"
1112
"path/filepath"
12-
"reflect"
1313
"regexp"
1414
"strings"
1515
"sync"
@@ -809,6 +809,8 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) {
809809
if ctx.Metas == nil {
810810
return
811811
}
812+
fmt.Println("ctx.Metas")
813+
fmt.Println(ctx.Metas)
812814
next := node.NextSibling
813815
for node != nil && node != next {
814816
m := getIssueFullPattern().FindStringSubmatchIndex(node.Data)
@@ -828,7 +830,7 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) {
828830
// if m[4] and m[5] is not -1, then link is to a comment
829831
// indicate that in the text by appending (comment)
830832
if m[4] != -1 && m[5] != -1 {
831-
locale := reflect.ValueOf(ctx.Ctx).Elem().FieldByName("Locale").Interface().(translation.Locale)
833+
locale := translation.NewLocale(ctx.Metas["language"])
832834
id += " " + locale.Tr("repo.from_comment")
833835
}
834836

routers/common/markup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func RenderMarkup(ctx *context.Context, mode, text, urlPrefix, filePath string,
7373
if mode != "comment" {
7474
meta["mode"] = "document"
7575
}
76-
76+
meta["language"] = ctx.Locale.Language()
7777
if err := markup.Render(&markup.RenderContext{
7878
Ctx: ctx,
7979
URLPrefix: urlPrefix,

routers/web/repo/issue.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,11 @@ func ViewIssue(ctx *context.Context) {
13191319
}
13201320
}
13211321
ctx.Data["IssueWatch"] = iw
1322-
1322+
metas := ctx.Repo.Repository.ComposeMetas()
1323+
metas["language"] = ctx.Locale.Language()
13231324
issue.RenderedContent, err = markdown.RenderString(&markup.RenderContext{
13241325
URLPrefix: ctx.Repo.RepoLink,
1325-
Metas: ctx.Repo.Repository.ComposeMetas(),
1326+
Metas: metas,
13261327
GitRepo: ctx.Repo.GitRepo,
13271328
Ctx: ctx,
13281329
}, issue.Content)
@@ -2021,10 +2022,11 @@ func UpdateIssueContent(ctx *context.Context) {
20212022
return
20222023
}
20232024
}
2024-
2025+
metas := ctx.Repo.Repository.ComposeMetas()
2026+
metas["language"] = ctx.Locale.Language()
20252027
content, err := markdown.RenderString(&markup.RenderContext{
20262028
URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ?
2027-
Metas: ctx.Repo.Repository.ComposeMetas(),
2029+
Metas: metas,
20282030
GitRepo: ctx.Repo.GitRepo,
20292031
Ctx: ctx,
20302032
}, issue.Content)
@@ -2829,10 +2831,11 @@ func UpdateCommentContent(ctx *context.Context) {
28292831
return
28302832
}
28312833
}
2832-
2834+
metas := ctx.Repo.Repository.ComposeMetas()
2835+
metas["language"] = ctx.Locale.Language()
28332836
content, err := markdown.RenderString(&markup.RenderContext{
28342837
URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ?
2835-
Metas: ctx.Repo.Repository.ComposeMetas(),
2838+
Metas: metas,
28362839
GitRepo: ctx.Repo.GitRepo,
28372840
Ctx: ctx,
28382841
}, comment.Content)

0 commit comments

Comments
 (0)