mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-08 18:04:14 +01:00
Make better use of i18n (#20096)
* Prototyping * Start work on creating offsets * Modify tests * Start prototyping with actual MPH * Twiddle around * Twiddle around comments * Convert templates * Fix external languages * Fix latest translation * Fix some test * Tidy up code * Use simple map * go mod tidy * Move back to data structure - Uses less memory by creating for each language a map. * Apply suggestions from code review Co-authored-by: delvh <dev.lh@web.de> * Add some comments * Fix tests * Try to fix tests * Use en-US as defacto fallback * Use correct slices * refactor (#4) * Remove TryTr, add log for missing translation key * Refactor i18n - Separate dev and production locale stores. - Allow for live-reloading in dev mode. Co-authored-by: zeripath <art27@cantab.net> * Fix live-reloading & check for errors * Make linter happy * live-reload with periodic check (#5) * Fix tests Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
711cbcce8d
commit
5d3f99c7c6
60 changed files with 340 additions and 282 deletions
|
@ -16,7 +16,7 @@ import (
|
|||
"code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -275,8 +275,7 @@ func TestLDAPUserSigninFailed(t *testing.T) {
|
|||
addAuthSourceLDAP(t, "")
|
||||
|
||||
u := otherLDAPUsers[0]
|
||||
|
||||
testLoginFailed(t, u.UserName, u.Password, i18n.Tr("en", "form.username_password_incorrect"))
|
||||
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").Tr("form.username_password_incorrect"))
|
||||
}
|
||||
|
||||
func TestLDAPUserSSHKeySync(t *testing.T) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"net/url"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -37,7 +37,7 @@ func TestUndoDeleteBranch(t *testing.T) {
|
|||
htmlDoc, name := branchAction(t, ".undo-button")
|
||||
assert.Contains(t,
|
||||
htmlDoc.doc.Find(".ui.positive.message").Text(),
|
||||
i18n.Tr("en", "repo.branch.restore_success", name),
|
||||
translation.NewLocale("en-US").Tr("repo.branch.restore_success", name),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func deleteBranch(t *testing.T) {
|
|||
htmlDoc, name := branchAction(t, ".delete-branch-button")
|
||||
assert.Contains(t,
|
||||
htmlDoc.doc.Find(".ui.positive.message").Text(),
|
||||
i18n.Tr("en", "repo.branch.deletion_success", name),
|
||||
translation.NewLocale("en-US").Tr("repo.branch.deletion_success", name),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/services/pull"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
|
@ -204,7 +204,7 @@ func TestCantMergeWorkInProgress(t *testing.T) {
|
|||
text := strings.TrimSpace(htmlDoc.doc.Find(".merge-section > .item").Last().Text())
|
||||
assert.NotEmpty(t, text, "Can't find WIP text")
|
||||
|
||||
assert.Contains(t, text, i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress"), "Unable to find WIP text")
|
||||
assert.Contains(t, text, translation.NewLocale("en-US").Tr("repo.pulls.cannot_merge_work_in_progress"), "Unable to find WIP text")
|
||||
assert.Contains(t, text, "[wip]", "Unable to find WIP text")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -86,7 +86,7 @@ func TestCreateRelease(t *testing.T) {
|
|||
session := loginUser(t, "user2")
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 4)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.stable"), 4)
|
||||
}
|
||||
|
||||
func TestCreateReleasePreRelease(t *testing.T) {
|
||||
|
@ -95,7 +95,7 @@ func TestCreateReleasePreRelease(t *testing.T) {
|
|||
session := loginUser(t, "user2")
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 4)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.prerelease"), 4)
|
||||
}
|
||||
|
||||
func TestCreateReleaseDraft(t *testing.T) {
|
||||
|
@ -104,7 +104,7 @@ func TestCreateReleaseDraft(t *testing.T) {
|
|||
session := loginUser(t, "user2")
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 4)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.draft"), 4)
|
||||
}
|
||||
|
||||
func TestCreateReleasePaging(t *testing.T) {
|
||||
|
@ -124,11 +124,11 @@ func TestCreateReleasePaging(t *testing.T) {
|
|||
}
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.12", "v0.0.12", false, true)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.12", i18n.Tr("en", "repo.release.draft"), 10)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.12", translation.NewLocale("en-US").Tr("repo.release.draft"), 10)
|
||||
|
||||
// Check that user4 does not see draft and still see 10 latest releases
|
||||
session2 := loginUser(t, "user4")
|
||||
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", i18n.Tr("en", "repo.release.stable"), 10)
|
||||
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", translation.NewLocale("en-US").Tr("repo.release.stable"), 10)
|
||||
}
|
||||
|
||||
func TestViewReleaseListNoLogin(t *testing.T) {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -52,37 +52,37 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
|
|||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "feature/test1",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test1"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature/test1"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "form.NewBranchName") + i18n.Tr("en", "form.require_error"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("form.NewBranchName") + translation.NewLocale("en-US").Tr("form.require_error"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "feature=test1",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature=test1"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature=test1"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: strings.Repeat("b", 101),
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "form.NewBranchName") + i18n.Tr("en", "form.max_size_error", "100"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("form.NewBranchName") + translation.NewLocale("en-US").Tr("form.max_size_error", "100"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "master",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "repo.branch.branch_already_exists", "master"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.branch_already_exists", "master"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "master/test",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "repo.branch.branch_name_conflict", "master/test", "master"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.branch_name_conflict", "master/test", "master"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "commit/acd1d892867872cb47f3993468605b8aa59aa2e0",
|
||||
|
@ -93,21 +93,21 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
|
|||
OldRefSubURL: "commit/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
||||
NewBranch: "feature/test3",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test3"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature/test3"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "v1.0.0",
|
||||
CreateRelease: "v1.0.0",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "repo.branch.tag_collision", "v1.0.0"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.tag_collision", "v1.0.0"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "tag/v1.0.0",
|
||||
NewBranch: "feature/test4",
|
||||
CreateRelease: "v1.0.1",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test4"),
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature/test4"),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -47,10 +47,10 @@ func TestSignin(t *testing.T) {
|
|||
password string
|
||||
message string
|
||||
}{
|
||||
{username: "wrongUsername", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
|
||||
{username: "wrongUsername", password: "password", message: i18n.Tr("en", "form.username_password_incorrect")},
|
||||
{username: "user15", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
|
||||
{username: "user1@example.com", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
|
||||
{username: "wrongUsername", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
{username: "wrongUsername", password: "password", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
{username: "user15", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
{username: "user1@example.com", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
}
|
||||
|
||||
for _, s := range samples {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -68,9 +68,9 @@ func TestSignupEmail(t *testing.T) {
|
|||
wantStatus int
|
||||
wantMsg string
|
||||
}{
|
||||
{"exampleUser@example.com\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
|
||||
{"exampleUser@example.com\r", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
|
||||
{"exampleUser@example.com\n", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
|
||||
{"exampleUser@example.com\r\n", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||||
{"exampleUser@example.com\r", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||||
{"exampleUser@example.com\n", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||||
{"exampleUser@example.com", http.StatusSeeOther, ""},
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
user_model "code.gitea.io/gitea/models/user"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -67,7 +67,7 @@ func TestRenameInvalidUsername(t *testing.T) {
|
|||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
assert.Contains(t,
|
||||
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
||||
i18n.Tr("en", "form.alpha_dash_dot_error"),
|
||||
translation.NewLocale("en-US").Tr("form.alpha_dash_dot_error"),
|
||||
)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: invalidUsername})
|
||||
|
@ -131,7 +131,7 @@ func TestRenameReservedUsername(t *testing.T) {
|
|||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
assert.Contains(t,
|
||||
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
||||
i18n.Tr("en", "user.form.name_reserved", reservedUsername),
|
||||
translation.NewLocale("en-US").Tr("user.form.name_reserved", reservedUsername),
|
||||
)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: reservedUsername})
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"net/url"
|
||||
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/yuin/goldmark/ast"
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ func createTOCNode(toc []markup.Header, lang string) ast.Node {
|
|||
details := NewDetails()
|
||||
summary := NewSummary()
|
||||
|
||||
summary.AppendChild(summary, ast.NewString([]byte(i18n.Tr(lang, "toc"))))
|
||||
summary.AppendChild(summary, ast.NewString([]byte(translation.NewLocale(lang).Tr("toc"))))
|
||||
details.AppendChild(details, summary)
|
||||
ul := ast.NewList('-')
|
||||
details.AppendChild(details, ul)
|
||||
|
|
|
@ -105,7 +105,6 @@ func NewFuncMap() []template.FuncMap {
|
|||
"Str2html": Str2html,
|
||||
"TimeSince": timeutil.TimeSince,
|
||||
"TimeSinceUnix": timeutil.TimeSinceUnix,
|
||||
"RawTimeSince": timeutil.RawTimeSince,
|
||||
"FileSize": base.FileSize,
|
||||
"PrettyNumber": base.PrettyNumber,
|
||||
"JsPrettyNumber": JsPrettyNumber,
|
||||
|
@ -484,7 +483,6 @@ func NewTextFuncMap() []texttmpl.FuncMap {
|
|||
},
|
||||
"TimeSince": timeutil.TimeSince,
|
||||
"TimeSinceUnix": timeutil.TimeSinceUnix,
|
||||
"RawTimeSince": timeutil.RawTimeSince,
|
||||
"DateFmtLong": func(t time.Time) string {
|
||||
return t.Format(time.RFC1123Z)
|
||||
},
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
)
|
||||
|
||||
// Seconds-based time units
|
||||
|
@ -29,146 +29,146 @@ func round(s float64) int64 {
|
|||
return int64(math.Round(s))
|
||||
}
|
||||
|
||||
func computeTimeDiffFloor(diff int64, lang string) (int64, string) {
|
||||
var diffStr string
|
||||
func computeTimeDiffFloor(diff int64, lang translation.Locale) (int64, string) {
|
||||
diffStr := ""
|
||||
switch {
|
||||
case diff <= 0:
|
||||
diff = 0
|
||||
diffStr = i18n.Tr(lang, "tool.now")
|
||||
diffStr = lang.Tr("tool.now")
|
||||
case diff < 2:
|
||||
diff = 0
|
||||
diffStr = i18n.Tr(lang, "tool.1s")
|
||||
diffStr = lang.Tr("tool.1s")
|
||||
case diff < 1*Minute:
|
||||
diffStr = i18n.Tr(lang, "tool.seconds", diff)
|
||||
diffStr = lang.Tr("tool.seconds", diff)
|
||||
diff = 0
|
||||
|
||||
case diff < 2*Minute:
|
||||
diff -= 1 * Minute
|
||||
diffStr = i18n.Tr(lang, "tool.1m")
|
||||
diffStr = lang.Tr("tool.1m")
|
||||
case diff < 1*Hour:
|
||||
diffStr = i18n.Tr(lang, "tool.minutes", diff/Minute)
|
||||
diffStr = lang.Tr("tool.minutes", diff/Minute)
|
||||
diff -= diff / Minute * Minute
|
||||
|
||||
case diff < 2*Hour:
|
||||
diff -= 1 * Hour
|
||||
diffStr = i18n.Tr(lang, "tool.1h")
|
||||
diffStr = lang.Tr("tool.1h")
|
||||
case diff < 1*Day:
|
||||
diffStr = i18n.Tr(lang, "tool.hours", diff/Hour)
|
||||
diffStr = lang.Tr("tool.hours", diff/Hour)
|
||||
diff -= diff / Hour * Hour
|
||||
|
||||
case diff < 2*Day:
|
||||
diff -= 1 * Day
|
||||
diffStr = i18n.Tr(lang, "tool.1d")
|
||||
diffStr = lang.Tr("tool.1d")
|
||||
case diff < 1*Week:
|
||||
diffStr = i18n.Tr(lang, "tool.days", diff/Day)
|
||||
diffStr = lang.Tr("tool.days", diff/Day)
|
||||
diff -= diff / Day * Day
|
||||
|
||||
case diff < 2*Week:
|
||||
diff -= 1 * Week
|
||||
diffStr = i18n.Tr(lang, "tool.1w")
|
||||
diffStr = lang.Tr("tool.1w")
|
||||
case diff < 1*Month:
|
||||
diffStr = i18n.Tr(lang, "tool.weeks", diff/Week)
|
||||
diffStr = lang.Tr("tool.weeks", diff/Week)
|
||||
diff -= diff / Week * Week
|
||||
|
||||
case diff < 2*Month:
|
||||
diff -= 1 * Month
|
||||
diffStr = i18n.Tr(lang, "tool.1mon")
|
||||
diffStr = lang.Tr("tool.1mon")
|
||||
case diff < 1*Year:
|
||||
diffStr = i18n.Tr(lang, "tool.months", diff/Month)
|
||||
diffStr = lang.Tr("tool.months", diff/Month)
|
||||
diff -= diff / Month * Month
|
||||
|
||||
case diff < 2*Year:
|
||||
diff -= 1 * Year
|
||||
diffStr = i18n.Tr(lang, "tool.1y")
|
||||
diffStr = lang.Tr("tool.1y")
|
||||
default:
|
||||
diffStr = i18n.Tr(lang, "tool.years", diff/Year)
|
||||
diffStr = lang.Tr("tool.years", diff/Year)
|
||||
diff -= (diff / Year) * Year
|
||||
}
|
||||
return diff, diffStr
|
||||
}
|
||||
|
||||
func computeTimeDiff(diff int64, lang string) (int64, string) {
|
||||
var diffStr string
|
||||
func computeTimeDiff(diff int64, lang translation.Locale) (int64, string) {
|
||||
diffStr := ""
|
||||
switch {
|
||||
case diff <= 0:
|
||||
diff = 0
|
||||
diffStr = i18n.Tr(lang, "tool.now")
|
||||
diffStr = lang.Tr("tool.now")
|
||||
case diff < 2:
|
||||
diff = 0
|
||||
diffStr = i18n.Tr(lang, "tool.1s")
|
||||
diffStr = lang.Tr("tool.1s")
|
||||
case diff < 1*Minute:
|
||||
diffStr = i18n.Tr(lang, "tool.seconds", diff)
|
||||
diffStr = lang.Tr("tool.seconds", diff)
|
||||
diff = 0
|
||||
|
||||
case diff < Minute+Minute/2:
|
||||
diff -= 1 * Minute
|
||||
diffStr = i18n.Tr(lang, "tool.1m")
|
||||
diffStr = lang.Tr("tool.1m")
|
||||
case diff < 1*Hour:
|
||||
minutes := round(float64(diff) / Minute)
|
||||
if minutes > 1 {
|
||||
diffStr = i18n.Tr(lang, "tool.minutes", minutes)
|
||||
diffStr = lang.Tr("tool.minutes", minutes)
|
||||
} else {
|
||||
diffStr = i18n.Tr(lang, "tool.1m")
|
||||
diffStr = lang.Tr("tool.1m")
|
||||
}
|
||||
diff -= diff / Minute * Minute
|
||||
|
||||
case diff < Hour+Hour/2:
|
||||
diff -= 1 * Hour
|
||||
diffStr = i18n.Tr(lang, "tool.1h")
|
||||
diffStr = lang.Tr("tool.1h")
|
||||
case diff < 1*Day:
|
||||
hours := round(float64(diff) / Hour)
|
||||
if hours > 1 {
|
||||
diffStr = i18n.Tr(lang, "tool.hours", hours)
|
||||
diffStr = lang.Tr("tool.hours", hours)
|
||||
} else {
|
||||
diffStr = i18n.Tr(lang, "tool.1h")
|
||||
diffStr = lang.Tr("tool.1h")
|
||||
}
|
||||
diff -= diff / Hour * Hour
|
||||
|
||||
case diff < Day+Day/2:
|
||||
diff -= 1 * Day
|
||||
diffStr = i18n.Tr(lang, "tool.1d")
|
||||
diffStr = lang.Tr("tool.1d")
|
||||
case diff < 1*Week:
|
||||
days := round(float64(diff) / Day)
|
||||
if days > 1 {
|
||||
diffStr = i18n.Tr(lang, "tool.days", days)
|
||||
diffStr = lang.Tr("tool.days", days)
|
||||
} else {
|
||||
diffStr = i18n.Tr(lang, "tool.1d")
|
||||
diffStr = lang.Tr("tool.1d")
|
||||
}
|
||||
diff -= diff / Day * Day
|
||||
|
||||
case diff < Week+Week/2:
|
||||
diff -= 1 * Week
|
||||
diffStr = i18n.Tr(lang, "tool.1w")
|
||||
diffStr = lang.Tr("tool.1w")
|
||||
case diff < 1*Month:
|
||||
weeks := round(float64(diff) / Week)
|
||||
if weeks > 1 {
|
||||
diffStr = i18n.Tr(lang, "tool.weeks", weeks)
|
||||
diffStr = lang.Tr("tool.weeks", weeks)
|
||||
} else {
|
||||
diffStr = i18n.Tr(lang, "tool.1w")
|
||||
diffStr = lang.Tr("tool.1w")
|
||||
}
|
||||
diff -= diff / Week * Week
|
||||
|
||||
case diff < 1*Month+Month/2:
|
||||
diff -= 1 * Month
|
||||
diffStr = i18n.Tr(lang, "tool.1mon")
|
||||
diffStr = lang.Tr("tool.1mon")
|
||||
case diff < 1*Year:
|
||||
months := round(float64(diff) / Month)
|
||||
if months > 1 {
|
||||
diffStr = i18n.Tr(lang, "tool.months", months)
|
||||
diffStr = lang.Tr("tool.months", months)
|
||||
} else {
|
||||
diffStr = i18n.Tr(lang, "tool.1mon")
|
||||
diffStr = lang.Tr("tool.1mon")
|
||||
}
|
||||
diff -= diff / Month * Month
|
||||
|
||||
case diff < Year+Year/2:
|
||||
diff -= 1 * Year
|
||||
diffStr = i18n.Tr(lang, "tool.1y")
|
||||
diffStr = lang.Tr("tool.1y")
|
||||
default:
|
||||
years := round(float64(diff) / Year)
|
||||
if years > 1 {
|
||||
diffStr = i18n.Tr(lang, "tool.years", years)
|
||||
diffStr = lang.Tr("tool.years", years)
|
||||
} else {
|
||||
diffStr = i18n.Tr(lang, "tool.1y")
|
||||
diffStr = lang.Tr("tool.1y")
|
||||
}
|
||||
diff -= (diff / Year) * Year
|
||||
}
|
||||
|
@ -177,24 +177,24 @@ func computeTimeDiff(diff int64, lang string) (int64, string) {
|
|||
|
||||
// MinutesToFriendly returns a user friendly string with number of minutes
|
||||
// converted to hours and minutes.
|
||||
func MinutesToFriendly(minutes int, lang string) string {
|
||||
func MinutesToFriendly(minutes int, lang translation.Locale) string {
|
||||
duration := time.Duration(minutes) * time.Minute
|
||||
return TimeSincePro(time.Now().Add(-duration), lang)
|
||||
}
|
||||
|
||||
// TimeSincePro calculates the time interval and generate full user-friendly string.
|
||||
func TimeSincePro(then time.Time, lang string) string {
|
||||
func TimeSincePro(then time.Time, lang translation.Locale) string {
|
||||
return timeSincePro(then, time.Now(), lang)
|
||||
}
|
||||
|
||||
func timeSincePro(then, now time.Time, lang string) string {
|
||||
func timeSincePro(then, now time.Time, lang translation.Locale) string {
|
||||
diff := now.Unix() - then.Unix()
|
||||
|
||||
if then.After(now) {
|
||||
return i18n.Tr(lang, "tool.future")
|
||||
return lang.Tr("tool.future")
|
||||
}
|
||||
if diff == 0 {
|
||||
return i18n.Tr(lang, "tool.now")
|
||||
return lang.Tr("tool.now")
|
||||
}
|
||||
|
||||
var timeStr, diffStr string
|
||||
|
@ -209,11 +209,11 @@ func timeSincePro(then, now time.Time, lang string) string {
|
|||
return strings.TrimPrefix(timeStr, ", ")
|
||||
}
|
||||
|
||||
func timeSince(then, now time.Time, lang string) string {
|
||||
func timeSince(then, now time.Time, lang translation.Locale) string {
|
||||
return timeSinceUnix(then.Unix(), now.Unix(), lang)
|
||||
}
|
||||
|
||||
func timeSinceUnix(then, now int64, lang string) string {
|
||||
func timeSinceUnix(then, now int64, lang translation.Locale) string {
|
||||
lbl := "tool.ago"
|
||||
diff := now - then
|
||||
if then > now {
|
||||
|
@ -221,36 +221,31 @@ func timeSinceUnix(then, now int64, lang string) string {
|
|||
diff = then - now
|
||||
}
|
||||
if diff <= 0 {
|
||||
return i18n.Tr(lang, "tool.now")
|
||||
return lang.Tr("tool.now")
|
||||
}
|
||||
|
||||
_, diffStr := computeTimeDiff(diff, lang)
|
||||
return i18n.Tr(lang, lbl, diffStr)
|
||||
}
|
||||
|
||||
// RawTimeSince retrieves i18n key of time since t
|
||||
func RawTimeSince(t time.Time, lang string) string {
|
||||
return timeSince(t, time.Now(), lang)
|
||||
return lang.Tr(lbl, diffStr)
|
||||
}
|
||||
|
||||
// TimeSince calculates the time interval and generate user-friendly string.
|
||||
func TimeSince(then time.Time, lang string) template.HTML {
|
||||
func TimeSince(then time.Time, lang translation.Locale) template.HTML {
|
||||
return htmlTimeSince(then, time.Now(), lang)
|
||||
}
|
||||
|
||||
func htmlTimeSince(then, now time.Time, lang string) template.HTML {
|
||||
func htmlTimeSince(then, now time.Time, lang translation.Locale) template.HTML {
|
||||
return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`,
|
||||
then.In(setting.DefaultUILocation).Format(GetTimeFormat(lang)),
|
||||
then.In(setting.DefaultUILocation).Format(GetTimeFormat(lang.Language())),
|
||||
timeSince(then, now, lang)))
|
||||
}
|
||||
|
||||
// TimeSinceUnix calculates the time interval and generate user-friendly string.
|
||||
func TimeSinceUnix(then TimeStamp, lang string) template.HTML {
|
||||
func TimeSinceUnix(then TimeStamp, lang translation.Locale) template.HTML {
|
||||
return htmlTimeSinceUnix(then, TimeStamp(time.Now().Unix()), lang)
|
||||
}
|
||||
|
||||
func htmlTimeSinceUnix(then, now TimeStamp, lang string) template.HTML {
|
||||
func htmlTimeSinceUnix(then, now TimeStamp, lang translation.Locale) template.HTML {
|
||||
return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`,
|
||||
then.FormatInLocation(GetTimeFormat(lang), setting.DefaultUILocation),
|
||||
then.FormatInLocation(GetTimeFormat(lang.Language()), setting.DefaultUILocation),
|
||||
timeSinceUnix(int64(then), int64(now), lang)))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -42,16 +41,16 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
|
||||
func TestTimeSince(t *testing.T) {
|
||||
assert.Equal(t, "now", timeSince(BaseDate, BaseDate, "en"))
|
||||
assert.Equal(t, "now", timeSince(BaseDate, BaseDate, translation.NewLocale("en-US")))
|
||||
|
||||
// test that each diff in `diffs` yields the expected string
|
||||
test := func(expected string, diffs ...time.Duration) {
|
||||
t.Run(expected, func(t *testing.T) {
|
||||
for _, diff := range diffs {
|
||||
actual := timeSince(BaseDate, BaseDate.Add(diff), "en")
|
||||
assert.Equal(t, i18n.Tr("en", "tool.ago", expected), actual)
|
||||
actual = timeSince(BaseDate.Add(diff), BaseDate, "en")
|
||||
assert.Equal(t, i18n.Tr("en", "tool.from_now", expected), actual)
|
||||
actual := timeSince(BaseDate, BaseDate.Add(diff), translation.NewLocale("en-US"))
|
||||
assert.Equal(t, translation.NewLocale("en-US").Tr("tool.ago", expected), actual)
|
||||
actual = timeSince(BaseDate.Add(diff), BaseDate, translation.NewLocale("en-US"))
|
||||
assert.Equal(t, translation.NewLocale("en-US").Tr("tool.from_now", expected), actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -82,13 +81,13 @@ func TestTimeSince(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeSincePro(t *testing.T) {
|
||||
assert.Equal(t, "now", timeSincePro(BaseDate, BaseDate, "en"))
|
||||
assert.Equal(t, "now", timeSincePro(BaseDate, BaseDate, translation.NewLocale("en-US")))
|
||||
|
||||
// test that a difference of `diff` yields the expected string
|
||||
test := func(expected string, diff time.Duration) {
|
||||
actual := timeSincePro(BaseDate, BaseDate.Add(diff), "en")
|
||||
actual := timeSincePro(BaseDate, BaseDate.Add(diff), translation.NewLocale("en-US"))
|
||||
assert.Equal(t, expected, actual)
|
||||
assert.Equal(t, "future", timeSincePro(BaseDate.Add(diff), BaseDate, "en"))
|
||||
assert.Equal(t, "future", timeSincePro(BaseDate.Add(diff), BaseDate, translation.NewLocale("en-US")))
|
||||
}
|
||||
test("1 second", time.Second)
|
||||
test("2 seconds", 2*time.Second)
|
||||
|
@ -119,7 +118,7 @@ func TestHtmlTimeSince(t *testing.T) {
|
|||
setting.DefaultUILocation = time.UTC
|
||||
// test that `diff` yields a result containing `expected`
|
||||
test := func(expected string, diff time.Duration) {
|
||||
actual := htmlTimeSince(BaseDate, BaseDate.Add(diff), "en")
|
||||
actual := htmlTimeSince(BaseDate, BaseDate.Add(diff), translation.NewLocale("en-US"))
|
||||
assert.Contains(t, actual, `title="Sat Jan 1 00:00:00 UTC 2000"`)
|
||||
assert.Contains(t, actual, expected)
|
||||
}
|
||||
|
@ -138,7 +137,7 @@ func TestComputeTimeDiff(t *testing.T) {
|
|||
test := func(base int64, str string, offsets ...int64) {
|
||||
for _, offset := range offsets {
|
||||
t.Run(fmt.Sprintf("%s:%d", str, offset), func(t *testing.T) {
|
||||
diff, diffStr := computeTimeDiff(base+offset, "en")
|
||||
diff, diffStr := computeTimeDiff(base+offset, translation.NewLocale("en-US"))
|
||||
assert.Equal(t, offset, diff)
|
||||
assert.Equal(t, str, diffStr)
|
||||
})
|
||||
|
@ -171,7 +170,7 @@ func TestComputeTimeDiff(t *testing.T) {
|
|||
func TestMinutesToFriendly(t *testing.T) {
|
||||
// test that a number of minutes yields the expected string
|
||||
test := func(expected string, minutes int) {
|
||||
actual := MinutesToFriendly(minutes, "en")
|
||||
actual := MinutesToFriendly(minutes, translation.NewLocale("en-US"))
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
test("1 minute", 1)
|
||||
|
|
|
@ -7,10 +7,13 @@ package i18n
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
@ -18,45 +21,90 @@ import (
|
|||
var (
|
||||
ErrLocaleAlreadyExist = errors.New("lang already exists")
|
||||
|
||||
DefaultLocales = NewLocaleStore()
|
||||
DefaultLocales = NewLocaleStore(true)
|
||||
)
|
||||
|
||||
type locale struct {
|
||||
store *LocaleStore
|
||||
langName string
|
||||
langDesc string
|
||||
messages *ini.File
|
||||
textMap map[int]string // the map key (idx) is generated by store's textIdxMap
|
||||
|
||||
sourceFileName string
|
||||
sourceFileInfo os.FileInfo
|
||||
lastReloadCheckTime time.Time
|
||||
}
|
||||
|
||||
type LocaleStore struct {
|
||||
// at the moment, all these fields are readonly after initialization
|
||||
langNames []string
|
||||
langDescs []string
|
||||
localeMap map[string]*locale
|
||||
reloadMu *sync.Mutex // for non-prod(dev), use a mutex for live-reload. for prod, no mutex, no live-reload.
|
||||
|
||||
langNames []string
|
||||
langDescs []string
|
||||
|
||||
localeMap map[string]*locale
|
||||
textIdxMap map[string]int
|
||||
|
||||
defaultLang string
|
||||
}
|
||||
|
||||
func NewLocaleStore() *LocaleStore {
|
||||
return &LocaleStore{localeMap: make(map[string]*locale)}
|
||||
func NewLocaleStore(isProd bool) *LocaleStore {
|
||||
ls := &LocaleStore{localeMap: make(map[string]*locale), textIdxMap: make(map[string]int)}
|
||||
if !isProd {
|
||||
ls.reloadMu = &sync.Mutex{}
|
||||
}
|
||||
return ls
|
||||
}
|
||||
|
||||
// AddLocaleByIni adds locale by ini into the store
|
||||
func (ls *LocaleStore) AddLocaleByIni(langName, langDesc string, localeFile interface{}, otherLocaleFiles ...interface{}) error {
|
||||
// if source is a string, then the file is loaded. in dev mode, the file can be live-reloaded
|
||||
// if source is a []byte, then the content is used
|
||||
func (ls *LocaleStore) AddLocaleByIni(langName, langDesc string, source interface{}) error {
|
||||
if _, ok := ls.localeMap[langName]; ok {
|
||||
return ErrLocaleAlreadyExist
|
||||
}
|
||||
|
||||
lc := &locale{store: ls, langName: langName}
|
||||
if fileName, ok := source.(string); ok {
|
||||
lc.sourceFileName = fileName
|
||||
lc.sourceFileInfo, _ = os.Stat(fileName) // live-reload only works for regular files. the error can be ignored
|
||||
}
|
||||
|
||||
ls.langNames = append(ls.langNames, langName)
|
||||
ls.langDescs = append(ls.langDescs, langDesc)
|
||||
ls.localeMap[lc.langName] = lc
|
||||
|
||||
return ls.reloadLocaleByIni(langName, source)
|
||||
}
|
||||
|
||||
func (ls *LocaleStore) reloadLocaleByIni(langName string, source interface{}) error {
|
||||
iniFile, err := ini.LoadSources(ini.LoadOptions{
|
||||
IgnoreInlineComment: true,
|
||||
UnescapeValueCommentSymbols: true,
|
||||
}, localeFile, otherLocaleFiles...)
|
||||
if err == nil {
|
||||
iniFile.BlockMode = false
|
||||
lc := &locale{store: ls, langName: langName, langDesc: langDesc, messages: iniFile}
|
||||
ls.langNames = append(ls.langNames, lc.langName)
|
||||
ls.langDescs = append(ls.langDescs, lc.langDesc)
|
||||
ls.localeMap[lc.langName] = lc
|
||||
}, source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load ini: %w", err)
|
||||
}
|
||||
return err
|
||||
iniFile.BlockMode = false
|
||||
|
||||
lc := ls.localeMap[langName]
|
||||
lc.textMap = make(map[int]string)
|
||||
for _, section := range iniFile.Sections() {
|
||||
for _, key := range section.Keys() {
|
||||
var trKey string
|
||||
if section.Name() == "" || section.Name() == "DEFAULT" {
|
||||
trKey = key.Name()
|
||||
} else {
|
||||
trKey = section.Name() + "." + key.Name()
|
||||
}
|
||||
textIdx, ok := ls.textIdxMap[trKey]
|
||||
if !ok {
|
||||
textIdx = len(ls.textIdxMap)
|
||||
ls.textIdxMap[trKey] = textIdx
|
||||
}
|
||||
lc.textMap[textIdx] = key.Value()
|
||||
}
|
||||
}
|
||||
iniFile = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ls *LocaleStore) HasLang(langName string) bool {
|
||||
|
@ -87,25 +135,39 @@ func (ls *LocaleStore) Tr(lang, trKey string, trArgs ...interface{}) string {
|
|||
|
||||
// Tr translates content to locale language. fall back to default language.
|
||||
func (l *locale) Tr(trKey string, trArgs ...interface{}) string {
|
||||
var section string
|
||||
|
||||
idx := strings.IndexByte(trKey, '.')
|
||||
if idx > 0 {
|
||||
section = trKey[:idx]
|
||||
trKey = trKey[idx+1:]
|
||||
}
|
||||
|
||||
trMsg := trKey
|
||||
if trIni, err := l.messages.Section(section).GetKey(trKey); err == nil {
|
||||
trMsg = trIni.Value()
|
||||
} else if l.store.defaultLang != "" && l.langName != l.store.defaultLang {
|
||||
// try to fall back to default
|
||||
if defaultLocale, ok := l.store.localeMap[l.store.defaultLang]; ok {
|
||||
if trIni, err = defaultLocale.messages.Section(section).GetKey(trKey); err == nil {
|
||||
trMsg = trIni.Value()
|
||||
if l.store.reloadMu != nil {
|
||||
l.store.reloadMu.Lock()
|
||||
defer l.store.reloadMu.Unlock()
|
||||
now := time.Now()
|
||||
if now.Sub(l.lastReloadCheckTime) >= time.Second && l.sourceFileInfo != nil && l.sourceFileName != "" {
|
||||
l.lastReloadCheckTime = now
|
||||
if sourceFileInfo, err := os.Stat(l.sourceFileName); err == nil && !sourceFileInfo.ModTime().Equal(l.sourceFileInfo.ModTime()) {
|
||||
if err = l.store.reloadLocaleByIni(l.langName, l.sourceFileName); err == nil {
|
||||
l.sourceFileInfo = sourceFileInfo
|
||||
} else {
|
||||
log.Error("unable to live-reload the locale file %q, err: %v", l.sourceFileName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
msg, _ := l.tryTr(trKey, trArgs...)
|
||||
return msg
|
||||
}
|
||||
|
||||
func (l *locale) tryTr(trKey string, trArgs ...interface{}) (msg string, found bool) {
|
||||
trMsg := trKey
|
||||
textIdx, ok := l.store.textIdxMap[trKey]
|
||||
if ok {
|
||||
if msg, found = l.textMap[textIdx]; found {
|
||||
trMsg = msg // use current translation
|
||||
} else if l.langName != l.store.defaultLang {
|
||||
if def, ok := l.store.localeMap[l.store.defaultLang]; ok {
|
||||
return def.tryTr(trKey, trArgs...)
|
||||
}
|
||||
} else if !setting.IsProd {
|
||||
log.Error("missing i18n translation key: %q", trKey)
|
||||
}
|
||||
}
|
||||
|
||||
if len(trArgs) > 0 {
|
||||
fmtArgs := make([]interface{}, 0, len(trArgs))
|
||||
|
@ -128,13 +190,15 @@ func (l *locale) Tr(trKey string, trArgs ...interface{}) string {
|
|||
fmtArgs = append(fmtArgs, arg)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(trMsg, fmtArgs...)
|
||||
return fmt.Sprintf(trMsg, fmtArgs...), found
|
||||
}
|
||||
return trMsg
|
||||
return trMsg, found
|
||||
}
|
||||
|
||||
func ResetDefaultLocales() {
|
||||
DefaultLocales = NewLocaleStore()
|
||||
// ResetDefaultLocales resets the current default locales
|
||||
// NOTE: this is not synchronized
|
||||
func ResetDefaultLocales(isProd bool) {
|
||||
DefaultLocales = NewLocaleStore(isProd)
|
||||
}
|
||||
|
||||
// Tr use default locales to translate content to target language.
|
||||
|
|
|
@ -27,30 +27,36 @@ fmt = %[2]s %[1]s
|
|||
sub = Changed Sub String
|
||||
`)
|
||||
|
||||
ls := NewLocaleStore()
|
||||
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1))
|
||||
assert.NoError(t, ls.AddLocaleByIni("lang2", "Lang2", testData2))
|
||||
ls.SetDefaultLang("lang1")
|
||||
for _, isProd := range []bool{true, false} {
|
||||
ls := NewLocaleStore(isProd)
|
||||
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1))
|
||||
assert.NoError(t, ls.AddLocaleByIni("lang2", "Lang2", testData2))
|
||||
ls.SetDefaultLang("lang1")
|
||||
|
||||
result := ls.Tr("lang1", "fmt", "a", "b")
|
||||
assert.Equal(t, "a b", result)
|
||||
result := ls.Tr("lang1", "fmt", "a", "b")
|
||||
assert.Equal(t, "a b", result)
|
||||
|
||||
result = ls.Tr("lang2", "fmt", "a", "b")
|
||||
assert.Equal(t, "b a", result)
|
||||
result = ls.Tr("lang2", "fmt", "a", "b")
|
||||
assert.Equal(t, "b a", result)
|
||||
|
||||
result = ls.Tr("lang1", "section.sub")
|
||||
assert.Equal(t, "Sub String", result)
|
||||
result = ls.Tr("lang1", "section.sub")
|
||||
assert.Equal(t, "Sub String", result)
|
||||
|
||||
result = ls.Tr("lang2", "section.sub")
|
||||
assert.Equal(t, "Changed Sub String", result)
|
||||
result = ls.Tr("lang2", "section.sub")
|
||||
assert.Equal(t, "Changed Sub String", result)
|
||||
|
||||
result = ls.Tr("", ".dot.name")
|
||||
assert.Equal(t, "Dot Name", result)
|
||||
result = ls.Tr("", ".dot.name")
|
||||
assert.Equal(t, "Dot Name", result)
|
||||
|
||||
result = ls.Tr("lang2", "section.mixed")
|
||||
assert.Equal(t, `test value; <span style="color: red; background: none;">more text</span>`, result)
|
||||
result = ls.Tr("lang2", "section.mixed")
|
||||
assert.Equal(t, `test value; <span style="color: red; background: none;">more text</span>`, result)
|
||||
|
||||
langs, descs := ls.ListLangNameDesc()
|
||||
assert.Equal(t, []string{"lang1", "lang2"}, langs)
|
||||
assert.Equal(t, []string{"Lang1", "Lang2"}, descs)
|
||||
langs, descs := ls.ListLangNameDesc()
|
||||
assert.Equal(t, []string{"lang1", "lang2"}, langs)
|
||||
assert.Equal(t, []string{"Lang1", "Lang2"}, descs)
|
||||
|
||||
result, found := ls.localeMap["lang1"].tryTr("no-such")
|
||||
assert.Equal(t, "no-such", result)
|
||||
assert.False(t, found)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package translation
|
||||
|
||||
import (
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/options"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
@ -40,31 +42,35 @@ func AllLangs() []*LangType {
|
|||
return allLangs
|
||||
}
|
||||
|
||||
// TryTr tries to do the translation, if no translation, it returns (format, false)
|
||||
func TryTr(lang, format string, args ...interface{}) (string, bool) {
|
||||
s := i18n.Tr(lang, format, args...)
|
||||
// now the i18n library is not good enough and we can only use this hacky method to detect whether the transaction exists
|
||||
idx := strings.IndexByte(format, '.')
|
||||
defaultText := format
|
||||
if idx > 0 {
|
||||
defaultText = format[idx+1:]
|
||||
}
|
||||
return s, s != defaultText
|
||||
}
|
||||
|
||||
// InitLocales loads the locales
|
||||
func InitLocales() {
|
||||
i18n.ResetDefaultLocales()
|
||||
i18n.ResetDefaultLocales(setting.IsProd)
|
||||
localeNames, err := options.Dir("locale")
|
||||
if err != nil {
|
||||
log.Fatal("Failed to list locale files: %v", err)
|
||||
}
|
||||
|
||||
localFiles := make(map[string][]byte, len(localeNames))
|
||||
localFiles := make(map[string]interface{}, len(localeNames))
|
||||
for _, name := range localeNames {
|
||||
localFiles[name], err = options.Locale(name)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to load %s locale file. %v", name, err)
|
||||
if options.IsDynamic() {
|
||||
// Try to check if CustomPath has the file, otherwise fallback to StaticRootPath
|
||||
value := path.Join(setting.CustomPath, "options/locale", name)
|
||||
|
||||
isFile, err := util.IsFile(value)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to load %s locale file. %v", name, err)
|
||||
}
|
||||
|
||||
if isFile {
|
||||
localFiles[name] = value
|
||||
} else {
|
||||
localFiles[name] = path.Join(setting.StaticRootPath, "options/locale", name)
|
||||
}
|
||||
} else {
|
||||
localFiles[name], err = options.Locale(name)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to load %s locale file. %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,6 +82,7 @@ func InitLocales() {
|
|||
matcher = language.NewMatcher(supportedTags)
|
||||
for i := range setting.Names {
|
||||
key := "locale_" + setting.Langs[i] + ".ini"
|
||||
|
||||
if err = i18n.DefaultLocales.AddLocaleByIni(setting.Langs[i], setting.Names[i], localFiles[key]); err != nil {
|
||||
log.Error("Failed to set messages to %s: %v", setting.Langs[i], err)
|
||||
}
|
||||
|
@ -132,16 +139,7 @@ func (l *locale) Language() string {
|
|||
|
||||
// Tr translates content to target language.
|
||||
func (l *locale) Tr(format string, args ...interface{}) string {
|
||||
if setting.IsProd {
|
||||
return i18n.Tr(l.Lang, format, args...)
|
||||
}
|
||||
|
||||
// in development, we should show an error if a translation key is missing
|
||||
s, ok := TryTr(l.Lang, format, args...)
|
||||
if !ok {
|
||||
log.Error("missing i18n translation key: %q", format)
|
||||
}
|
||||
return s
|
||||
return i18n.Tr(l.Lang, format, args...)
|
||||
}
|
||||
|
||||
// Language specific rules for translating plural texts
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/queue"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/modules/updatechecker"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
|
@ -85,7 +86,7 @@ var sysStatus struct {
|
|||
}
|
||||
|
||||
func updateSystemStatus() {
|
||||
sysStatus.Uptime = timeutil.TimeSincePro(setting.AppStartTime, "en")
|
||||
sysStatus.Uptime = timeutil.TimeSincePro(setting.AppStartTime, translation.NewLocale("en-US"))
|
||||
|
||||
m := new(runtime.MemStats)
|
||||
runtime.ReadMemStats(m)
|
||||
|
|
|
@ -629,7 +629,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.
|
|||
|
||||
ctx.Data["IsSendRegisterMail"] = true
|
||||
ctx.Data["Email"] = u.Email
|
||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
|
||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale)
|
||||
ctx.HTML(http.StatusOK, TplActivate)
|
||||
|
||||
if setting.CacheService.Enabled {
|
||||
|
@ -658,7 +658,7 @@ func Activate(ctx *context.Context) {
|
|||
if setting.CacheService.Enabled && ctx.Cache.IsExist("MailResendLimit_"+ctx.Doer.LowerName) {
|
||||
ctx.Data["ResendLimited"] = true
|
||||
} else {
|
||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
|
||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale)
|
||||
mailer.SendActivateAccountMail(ctx.Locale, ctx.Doer)
|
||||
|
||||
if setting.CacheService.Enabled {
|
||||
|
|
|
@ -63,7 +63,7 @@ func ForgotPasswdPost(ctx *context.Context) {
|
|||
u, err := user_model.GetUserByEmail(email)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
|
||||
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale)
|
||||
ctx.Data["IsResetSent"] = true
|
||||
ctx.HTML(http.StatusOK, tplForgotPassword)
|
||||
return
|
||||
|
@ -93,7 +93,7 @@ func ForgotPasswdPost(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
|
||||
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale)
|
||||
ctx.Data["IsResetSent"] = true
|
||||
ctx.HTML(http.StatusOK, tplForgotPassword)
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ func TemplatePreview(ctx *context.Context) {
|
|||
ctx.Data["AppVer"] = setting.AppVer
|
||||
ctx.Data["AppUrl"] = setting.AppURL
|
||||
ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374"
|
||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
|
||||
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
|
||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale)
|
||||
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale)
|
||||
ctx.Data["CurDbValue"] = ""
|
||||
|
||||
ctx.HTML(http.StatusOK, base.TplName(ctx.Params("*")))
|
||||
|
|
|
@ -255,7 +255,7 @@ func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames m
|
|||
commitCnt++
|
||||
|
||||
// User avatar image
|
||||
commitSince := timeutil.TimeSinceUnix(timeutil.TimeStamp(commit.Author.When.Unix()), ctx.Locale.Language())
|
||||
commitSince := timeutil.TimeSinceUnix(timeutil.TimeStamp(commit.Author.When.Unix()), ctx.Locale)
|
||||
|
||||
var avatar string
|
||||
if commit.User != nil {
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
)
|
||||
|
@ -29,14 +28,13 @@ func GetContentHistoryOverview(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
lang := ctx.Locale.Language()
|
||||
editedHistoryCountMap, _ := issues_model.QueryIssueContentHistoryEditedCountMap(ctx, issue.ID)
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"i18n": map[string]interface{}{
|
||||
"textEdited": i18n.Tr(lang, "repo.issues.content_history.edited"),
|
||||
"textDeleteFromHistory": i18n.Tr(lang, "repo.issues.content_history.delete_from_history"),
|
||||
"textDeleteFromHistoryConfirm": i18n.Tr(lang, "repo.issues.content_history.delete_from_history_confirm"),
|
||||
"textOptions": i18n.Tr(lang, "repo.issues.content_history.options"),
|
||||
"textEdited": ctx.Tr("repo.issues.content_history.edited"),
|
||||
"textDeleteFromHistory": ctx.Tr("repo.issues.content_history.delete_from_history"),
|
||||
"textDeleteFromHistoryConfirm": ctx.Tr("repo.issues.content_history.delete_from_history_confirm"),
|
||||
"textOptions": ctx.Tr("repo.issues.content_history.options"),
|
||||
},
|
||||
"editedHistoryCountMap": editedHistoryCountMap,
|
||||
})
|
||||
|
@ -55,7 +53,6 @@ func GetContentHistoryList(ctx *context.Context) {
|
|||
// render history list to HTML for frontend dropdown items: (name, value)
|
||||
// name is HTML of "avatar + userName + userAction + timeSince"
|
||||
// value is historyId
|
||||
lang := ctx.Locale.Language()
|
||||
var results []map[string]interface{}
|
||||
for _, item := range items {
|
||||
var actionText string
|
||||
|
@ -67,7 +64,7 @@ func GetContentHistoryList(ctx *context.Context) {
|
|||
} else {
|
||||
actionText = ctx.Locale.Tr("repo.issues.content_history.edited")
|
||||
}
|
||||
timeSinceText := timeutil.TimeSinceUnix(item.EditedUnix, lang)
|
||||
timeSinceText := timeutil.TimeSinceUnix(item.EditedUnix, ctx.Locale)
|
||||
|
||||
username := item.UserName
|
||||
if setting.UI.DefaultShowFullName && strings.TrimSpace(item.UserFullName) != "" {
|
||||
|
|
|
@ -146,7 +146,7 @@ func EmailPost(ctx *context.Context) {
|
|||
log.Error("Set cache(MailResendLimit) fail: %v", err)
|
||||
}
|
||||
}
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", address, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())))
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", address, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale)))
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/account")
|
||||
return
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ func EmailPost(ctx *context.Context) {
|
|||
log.Error("Set cache(MailResendLimit) fail: %v", err)
|
||||
}
|
||||
}
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())))
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale)))
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/modules/typesniffer"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
|
@ -136,7 +136,7 @@ func ProfilePost(ctx *context.Context) {
|
|||
middleware.SetLocaleCookie(ctx.Resp, ctx.Doer.Language, 0)
|
||||
|
||||
log.Trace("User settings updated: %s", ctx.Doer.Name)
|
||||
ctx.Flash.Success(i18n.Tr(ctx.Doer.Language, "settings.update_profile_success"))
|
||||
ctx.Flash.Success(translation.NewLocale(ctx.Doer.Language).Tr("settings.update_profile_success"))
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings")
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ func UpdateUserLang(ctx *context.Context) {
|
|||
middleware.SetLocaleCookie(ctx.Resp, ctx.Doer.Language, 0)
|
||||
|
||||
log.Trace("User settings updated: %s", ctx.Doer.Name)
|
||||
ctx.Flash.Success(i18n.Tr(ctx.Doer.Language, "settings.update_language_success"))
|
||||
ctx.Flash.Success(translation.NewLocale(ctx.Doer.Language).Tr("settings.update_language_success"))
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/sync"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/gogs/cron"
|
||||
)
|
||||
|
@ -63,7 +64,7 @@ type TaskTableRow struct {
|
|||
task *Task
|
||||
}
|
||||
|
||||
func (t *TaskTableRow) FormatLastMessage(locale string) string {
|
||||
func (t *TaskTableRow) FormatLastMessage(locale translation.Locale) string {
|
||||
if t.Status == "finished" {
|
||||
return t.task.GetConfig().FormatMessage(locale, t.Name, t.Status, t.LastDoer)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ package cron
|
|||
import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/translation/i18n"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
)
|
||||
|
||||
// Config represents a basic configuration interface that cron task
|
||||
|
@ -15,7 +15,7 @@ type Config interface {
|
|||
IsEnabled() bool
|
||||
DoRunAtStart() bool
|
||||
GetSchedule() string
|
||||
FormatMessage(locale, name, status, doer string, args ...interface{}) string
|
||||
FormatMessage(locale translation.Locale, name, status, doer string, args ...interface{}) string
|
||||
DoNoticeOnSuccess() bool
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,9 @@ func (b *BaseConfig) DoNoticeOnSuccess() bool {
|
|||
|
||||
// FormatMessage returns a message for the task
|
||||
// Please note the `status` string will be concatenated with `admin.dashboard.cron.` and `admin.dashboard.task.` to provide locale messages. Similarly `name` will be composed with `admin.dashboard.` to provide the locale name for the task.
|
||||
func (b *BaseConfig) FormatMessage(locale, name, status, doer string, args ...interface{}) string {
|
||||
func (b *BaseConfig) FormatMessage(locale translation.Locale, name, status, doer string, args ...interface{}) string {
|
||||
realArgs := make([]interface{}, 0, len(args)+2)
|
||||
realArgs = append(realArgs, i18n.Tr(locale, "admin.dashboard."+name))
|
||||
realArgs = append(realArgs, locale.Tr("admin.dashboard."+name))
|
||||
if doer == "" {
|
||||
realArgs = append(realArgs, "(Cron)")
|
||||
} else {
|
||||
|
@ -81,7 +81,7 @@ func (b *BaseConfig) FormatMessage(locale, name, status, doer string, args ...in
|
|||
realArgs = append(realArgs, args...)
|
||||
}
|
||||
if doer == "" {
|
||||
return i18n.Tr(locale, "admin.dashboard.cron."+status, realArgs...)
|
||||
return locale.Tr("admin.dashboard.cron."+status, realArgs...)
|
||||
}
|
||||
return i18n.Tr(locale, "admin.dashboard.task."+status, realArgs...)
|
||||
return locale.Tr("admin.dashboard.task."+status, realArgs...)
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ func (t *Task) RunWithUser(doer *user_model.User, config Config) {
|
|||
doerName = doer.Name
|
||||
}
|
||||
|
||||
ctx, _, finished := pm.AddContext(baseCtx, config.FormatMessage("en-US", t.Name, "process", doerName))
|
||||
ctx, _, finished := pm.AddContext(baseCtx, config.FormatMessage(translation.NewLocale("en-US"), t.Name, "process", doerName))
|
||||
defer finished()
|
||||
|
||||
if err := t.fun(ctx, doer, config); err != nil {
|
||||
|
@ -114,7 +114,7 @@ func (t *Task) RunWithUser(doer *user_model.User, config Config) {
|
|||
t.LastDoer = doerName
|
||||
t.lock.Unlock()
|
||||
|
||||
if err := admin_model.CreateNotice(ctx, admin_model.NoticeTask, config.FormatMessage("en-US", t.Name, "cancelled", doerName, message)); err != nil {
|
||||
if err := admin_model.CreateNotice(ctx, admin_model.NoticeTask, config.FormatMessage(translation.NewLocale("en-US"), t.Name, "cancelled", doerName, message)); err != nil {
|
||||
log.Error("CreateNotice: %v", err)
|
||||
}
|
||||
return
|
||||
|
@ -127,7 +127,7 @@ func (t *Task) RunWithUser(doer *user_model.User, config Config) {
|
|||
t.lock.Unlock()
|
||||
|
||||
if config.DoNoticeOnSuccess() {
|
||||
if err := admin_model.CreateNotice(ctx, admin_model.NoticeTask, config.FormatMessage("en-US", t.Name, "finished", doerName)); err != nil {
|
||||
if err := admin_model.CreateNotice(ctx, admin_model.NoticeTask, config.FormatMessage(translation.NewLocale("en-US"), t.Name, "finished", doerName)); err != nil {
|
||||
log.Error("CreateNotice: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func RegisterTask(name string, config Config, fun func(context.Context, *user_mo
|
|||
log.Debug("Registering task: %s", name)
|
||||
|
||||
i18nKey := "admin.dashboard." + name
|
||||
if _, ok := translation.TryTr("en-US", i18nKey); !ok {
|
||||
if value := translation.NewLocale("en-US").Tr(i18nKey); value == i18nKey {
|
||||
return fmt.Errorf("translation is missing for task %q, please add translation for %q", name, i18nKey)
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ func sendUserMail(language string, u *user_model.User, tpl base.TplName, code, s
|
|||
locale := translation.NewLocale(language)
|
||||
data := map[string]interface{}{
|
||||
"DisplayName": u.DisplayName(),
|
||||
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, language),
|
||||
"ResetPwdCodeLives": timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, language),
|
||||
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, locale),
|
||||
"ResetPwdCodeLives": timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, locale),
|
||||
"Code": code,
|
||||
"Language": locale.Language(),
|
||||
// helper
|
||||
|
@ -126,7 +126,7 @@ func SendActivateEmailMail(u *user_model.User, email *user_model.EmailAddress) {
|
|||
locale := translation.NewLocale(u.Language)
|
||||
data := map[string]interface{}{
|
||||
"DisplayName": u.DisplayName(),
|
||||
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, locale.Language()),
|
||||
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, locale),
|
||||
"Code": u.GenerateEmailActivateCode(email.Email),
|
||||
"Email": email.Email,
|
||||
"Language": locale.Language(),
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<td>{{DateFmtLong .Next}}</td>
|
||||
<td>{{if gt .Prev.Year 1 }}{{DateFmtLong .Prev}}{{else}}N/A{{end}}</td>
|
||||
<td>{{.ExecTimes}}</td>
|
||||
<td {{if ne .Status ""}}class="tooltip" data-content="{{.FormatLastMessage $.i18n.Language}}"{{end}} >{{if eq .Status "" }}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}}</td>
|
||||
<td {{if ne .Status ""}}class="tooltip" data-content="{{.FormatLastMessage $.i18n}}"{{end}} >{{if eq .Status "" }}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div class="icon ml-3 mr-3">{{if eq .Process.Type "request"}}{{svg "octicon-globe" 16 }}{{else if eq .Process.Type "system"}}{{svg "octicon-cpu" 16 }}{{else}}{{svg "octicon-terminal" 16 }}{{end}}</div>
|
||||
<div class="content f1">
|
||||
<div class="header">{{.Process.Description}}</div>
|
||||
<div class="description"><span title="{{DateFmtLong .Process.Start}}">{{TimeSince .Process.Start .root.i18n.Lang}}</span></div>
|
||||
<div class="description"><span title="{{DateFmtLong .Process.Start}}">{{TimeSince .Process.Start .root.i18n}}</span></div>
|
||||
</div>
|
||||
<div>
|
||||
{{if ne .Process.Type "system"}}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</div>
|
||||
<div class="content f1">
|
||||
<div class="header">{{.Process.Description}}</div>
|
||||
<div class="description">{{if ne .Process.Type "none"}}<span title="{{DateFmtLong .Process.Start}}">{{TimeSince .Process.Start .root.i18n.Lang}}</span>{{end}}</div>
|
||||
<div class="description">{{if ne .Process.Type "none"}}<span title="{{DateFmtLong .Process.Start}}">{{TimeSince .Process.Start .root.i18n}}</span>{{end}}</div>
|
||||
</div>
|
||||
<div>
|
||||
{{if or (eq .Process.Type "request") (eq .Process.Type "normal") }}
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}</p>
|
||||
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n}}</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<span class="ui label">{{svg .Package.Type.SVGName 16}} {{.Package.Type.Name}}</span>
|
||||
</div>
|
||||
<div class="desc issue-item-bottom-row df ac fw my-1">
|
||||
{{$timeStr := TimeSinceUnix .Version.CreatedUnix $.i18n.Lang}}
|
||||
{{$timeStr := TimeSinceUnix .Version.CreatedUnix $.i18n}}
|
||||
{{$hasRepositoryAccess := false}}
|
||||
{{if .Repository}}
|
||||
{{$hasRepositoryAccess = index $.RepositoryAccessMap .Repository.ID}}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<a class="title" href="{{.FullWebLink}}">{{.Version.LowerVersion}}</a>
|
||||
</div>
|
||||
<div class="desc issue-item-bottom-row df ac fw my-1">
|
||||
{{$.i18n.Tr "packages.published_by" (TimeSinceUnix .Version.CreatedUnix $.i18n.Lang) .Creator.HomeLink (.Creator.GetDisplayName | Escape) | Safe}}
|
||||
{{$.i18n.Tr "packages.published_by" (TimeSinceUnix .Version.CreatedUnix $.i18n) .Creator.HomeLink (.Creator.GetDisplayName | Escape) | Safe}}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<h1>{{.PackageDescriptor.Package.Name}} ({{.PackageDescriptor.Version.Version}})</h1>
|
||||
</div>
|
||||
<div>
|
||||
{{$timeStr := TimeSinceUnix .PackageDescriptor.Version.CreatedUnix $.i18n.Lang}}
|
||||
{{$timeStr := TimeSinceUnix .PackageDescriptor.Version.CreatedUnix $.i18n}}
|
||||
{{if .HasRepositoryAccess}}
|
||||
{{.i18n.Tr "packages.published_by_in" $timeStr .PackageDescriptor.Creator.HomeLink (.PackageDescriptor.Creator.GetDisplayName | Escape) .PackageDescriptor.Repository.HTMLURL (.PackageDescriptor.Repository.FullName | Escape) | Safe}}
|
||||
{{else}}
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
{{if not .IsTag}}
|
||||
<a class="title" href="{{$.RepoLink}}/src/{{.TagName | PathEscapeSegments}}">{{.Title | RenderEmoji}}</a>
|
||||
{{end}}
|
||||
{{TimeSinceUnix .CreatedUnix $.i18n.Lang}}
|
||||
{{TimeSinceUnix .CreatedUnix $.i18n}}
|
||||
</p>
|
||||
{{end}}
|
||||
</div>
|
||||
|
@ -150,7 +150,7 @@
|
|||
<p class="desc">
|
||||
<span class="ui purple label">{{$.i18n.Tr "repo.activity.merged_prs_label"}}</span>
|
||||
#{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji}}</a>
|
||||
{{TimeSinceUnix .MergedUnix $.i18n.Lang}}
|
||||
{{TimeSinceUnix .MergedUnix $.i18n}}
|
||||
</p>
|
||||
{{end}}
|
||||
</div>
|
||||
|
@ -169,7 +169,7 @@
|
|||
<p class="desc">
|
||||
<span class="ui green label">{{$.i18n.Tr "repo.activity.opened_prs_label"}}</span>
|
||||
#{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji}}</a>
|
||||
{{TimeSinceUnix .Issue.CreatedUnix $.i18n.Lang}}
|
||||
{{TimeSinceUnix .Issue.CreatedUnix $.i18n}}
|
||||
</p>
|
||||
{{end}}
|
||||
</div>
|
||||
|
@ -188,7 +188,7 @@
|
|||
<p class="desc">
|
||||
<span class="ui red label">{{$.i18n.Tr "repo.activity.closed_issue_label"}}</span>
|
||||
#{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji}}</a>
|
||||
{{TimeSinceUnix .ClosedUnix $.i18n.Lang}}
|
||||
{{TimeSinceUnix .ClosedUnix $.i18n}}
|
||||
</p>
|
||||
{{end}}
|
||||
</div>
|
||||
|
@ -207,7 +207,7 @@
|
|||
<p class="desc">
|
||||
<span class="ui green label">{{$.i18n.Tr "repo.activity.new_issue_label"}}</span>
|
||||
#{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji}}</a>
|
||||
{{TimeSinceUnix .CreatedUnix $.i18n.Lang}}
|
||||
{{TimeSinceUnix .CreatedUnix $.i18n}}
|
||||
</p>
|
||||
{{end}}
|
||||
</div>
|
||||
|
@ -231,7 +231,7 @@
|
|||
{{else}}
|
||||
<a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji}}</a>
|
||||
{{end}}
|
||||
{{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}
|
||||
{{TimeSinceUnix .UpdatedUnix $.i18n}}
|
||||
</p>
|
||||
{{end}}
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
{{svg "octicon-shield-lock"}}
|
||||
{{end}}
|
||||
<a href="{{.RepoLink}}/src/branch/{{PathEscapeSegments .DefaultBranch}}">{{.DefaultBranch}}</a>
|
||||
<p class="info df ac my-2">{{svg "octicon-git-commit" 16 "mr-2"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.Commit.ID.String}}">{{ShortSha .DefaultBranchBranch.Commit.ID.String}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.Commit.CommitMessage .RepoLink .Repository.ComposeMetas}}</span> · {{.i18n.Tr "org.repo_updated"}} {{TimeSince .DefaultBranchBranch.Commit.Committer.When .i18n.Lang}}</p>
|
||||
<p class="info df ac my-2">{{svg "octicon-git-commit" 16 "mr-2"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.Commit.ID.String}}">{{ShortSha .DefaultBranchBranch.Commit.ID.String}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.Commit.CommitMessage .RepoLink .Repository.ComposeMetas}}</span> · {{.i18n.Tr "org.repo_updated"}} {{TimeSince .DefaultBranchBranch.Commit.Committer.When .i18n}}</p>
|
||||
</td>
|
||||
<td class="right aligned overflow-visible">
|
||||
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}}
|
||||
|
@ -53,13 +53,13 @@
|
|||
<td class="six wide">
|
||||
{{if .IsDeleted}}
|
||||
<s><a href="{{$.RepoLink}}/src/branch/{{PathEscapeSegments .Name}}">{{.Name}}</a></s>
|
||||
<p class="info">{{$.i18n.Tr "repo.branch.deleted_by" .DeletedBranch.DeletedBy.Name}} {{TimeSinceUnix .DeletedBranch.DeletedUnix $.i18n.Lang}}</p>
|
||||
<p class="info">{{$.i18n.Tr "repo.branch.deleted_by" .DeletedBranch.DeletedBy.Name}} {{TimeSinceUnix .DeletedBranch.DeletedUnix $.i18n}}</p>
|
||||
{{else}}
|
||||
{{if .IsProtected}}
|
||||
{{svg "octicon-shield-lock"}}
|
||||
{{end}}
|
||||
<a href="{{$.RepoLink}}/src/branch/{{PathEscapeSegments .Name}}">{{.Name}}</a>
|
||||
<p class="info df ac my-2">{{svg "octicon-git-commit" 16 "mr-2"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}">{{ShortSha .Commit.ID.String}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .Commit.CommitMessage $.RepoLink $.Repository.ComposeMetas}}</span> · {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Commit.Committer.When $.i18n.Lang}}</p>
|
||||
<p class="info df ac my-2">{{svg "octicon-git-commit" 16 "mr-2"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}">{{ShortSha .Commit.ID.String}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .Commit.CommitMessage $.RepoLink $.Repository.ComposeMetas}}</span> · {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Commit.Committer.When $.i18n}}</p>
|
||||
{{end}}
|
||||
</td>
|
||||
<td class="three wide ui">
|
||||
|
|
|
@ -156,7 +156,7 @@
|
|||
{{avatarByEmail .Commit.Author.Email .Commit.Author.Email 28 "mr-3"}}
|
||||
<strong>{{.Commit.Author.Name}}</strong>
|
||||
{{end}}
|
||||
<span class="text grey ml-3" id="authored-time">{{TimeSince .Commit.Author.When $.i18n.Lang}}</span>
|
||||
<span class="text grey ml-3" id="authored-time">{{TimeSince .Commit.Author.When $.i18n}}</span>
|
||||
{{if or (ne .Commit.Committer.Name .Commit.Author.Name) (ne .Commit.Committer.Email .Commit.Author.Email)}}
|
||||
<span class="text grey mx-3">{{.i18n.Tr "repo.diff.committed_by"}}</span>
|
||||
{{if ne .Verification.CommittingUser.ID 0}}
|
||||
|
@ -277,7 +277,7 @@
|
|||
{{else}}
|
||||
<strong>{{.NoteCommit.Author.Name}}</strong>
|
||||
{{end}}
|
||||
<span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When $.i18n.Lang}}</span>
|
||||
<span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When $.i18n}}</span>
|
||||
</div>
|
||||
<div class="ui bottom attached info segment git-notes">
|
||||
<pre class="commit-body">{{RenderNote $.Context .Note $.RepoLink $.Repository.ComposeMetas}}</pre>
|
||||
|
|
|
@ -76,9 +76,9 @@
|
|||
{{end}}
|
||||
</td>
|
||||
{{if .Committer}}
|
||||
<td class="text right aligned">{{TimeSince .Committer.When $.i18n.Lang}}</td>
|
||||
<td class="text right aligned">{{TimeSince .Committer.When $.i18n}}</td>
|
||||
{{else}}
|
||||
<td class="text right aligned">{{TimeSince .Author.When $.i18n.Lang}}</td>
|
||||
<td class="text right aligned">{{TimeSince .Author.When $.i18n}}</td>
|
||||
{{end}}
|
||||
</tr>
|
||||
{{end}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{range .comments}}
|
||||
|
||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.root.i18n.Lang }}
|
||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.root.i18n }}
|
||||
<div class="comment" id="{{.HashTag}}">
|
||||
{{if .OriginalAuthor }}
|
||||
<span class="avatar"><img src="{{AppSubUrl}}/assets/img/avatar_default.png"></span>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
</div>
|
||||
<div class="ui one column stackable grid">
|
||||
<div class="column">
|
||||
{{ $closedDate:= TimeSinceUnix .Milestone.ClosedDateUnix $.i18n.Lang }}
|
||||
{{ $closedDate:= TimeSinceUnix .Milestone.ClosedDateUnix $.i18n }}
|
||||
{{if .IsClosed}}
|
||||
{{svg "octicon-clock"}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}}
|
||||
{{else}}
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="meta">
|
||||
{{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n.Lang }}
|
||||
{{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n }}
|
||||
{{if .IsClosed}}
|
||||
{{svg "octicon-clock"}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}}
|
||||
{{else}}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<input type="hidden" id="issueIndex" value="{{.Issue.Index}}"/>
|
||||
<input type="hidden" id="type" value="{{.IssueType}}">
|
||||
|
||||
{{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.i18n.Lang }}
|
||||
{{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.i18n }}
|
||||
<div class="twelve wide column comment-list prevent-before-timeline">
|
||||
<ui class="ui timeline">
|
||||
<div id="{{.Issue.HashTag}}" class="timeline-item comment first">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{ template "base/alert" }}
|
||||
{{range .Issue.Comments}}
|
||||
{{if call $.ShouldShowCommentType .Type}}
|
||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.i18n.Lang }}
|
||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.i18n }}
|
||||
|
||||
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF,
|
||||
5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING,
|
||||
|
@ -152,7 +152,7 @@
|
|||
{{else if eq .RefAction 2 }}
|
||||
{{ $refTr = "repo.issues.ref_reopening_from" }}
|
||||
{{end}}
|
||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.i18n.Lang }}
|
||||
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.i18n }}
|
||||
<div class="timeline-item event" id="{{.HashTag}}">
|
||||
<span class="badge">{{svg "octicon-bookmark"}}</span>
|
||||
<a href="{{.Poster.HomeLink}}">
|
||||
|
@ -563,7 +563,7 @@
|
|||
<div id="code-comments-{{(index $comms 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} hide{{end}}">
|
||||
<div class="ui comments mb-0">
|
||||
{{range $comms}}
|
||||
{{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.i18n.Lang }}
|
||||
{{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.i18n }}
|
||||
<div class="comment code-comment pb-4" id="{{.HashTag}}">
|
||||
<div class="content">
|
||||
<div class="header comment-header">
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div class="ui segment">
|
||||
<h4>{{$.i18n.Tr "repo.issues.review.reviewers"}}</h4>
|
||||
{{range .PullReviewers}}
|
||||
{{ $createdStr:= TimeSinceUnix .Review.UpdatedUnix $.i18n.Lang }}
|
||||
{{ $createdStr:= TimeSinceUnix .Review.UpdatedUnix $.i18n }}
|
||||
<div class="ui divider"></div>
|
||||
<div class="review-item">
|
||||
<div class="review-item-left">
|
||||
|
@ -82,7 +82,7 @@
|
|||
</div>
|
||||
{{end}}
|
||||
{{range .OriginalReviews}}
|
||||
{{ $createdStr:= TimeSinceUnix .UpdatedUnix $.i18n.Lang }}
|
||||
{{ $createdStr:= TimeSinceUnix .UpdatedUnix $.i18n }}
|
||||
<div class="ui divider"></div>
|
||||
<div class="review-item">
|
||||
<div class="review-item-left">
|
||||
|
@ -328,7 +328,7 @@
|
|||
{{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash}}
|
||||
{{$hasPendingPullRequestMergeTip := ""}}
|
||||
{{if .HasPendingPullRequestMerge}}
|
||||
{{$createdPRMergeStr := TimeSinceUnix .PendingPullRequestMerge.CreatedUnix $.i18n.Lang}}
|
||||
{{$createdPRMergeStr := TimeSinceUnix .PendingPullRequestMerge.CreatedUnix $.i18n}}
|
||||
{{$hasPendingPullRequestMergeTip = $.i18n.Tr "repo.pulls.auto_merge_has_pending_schedule" .PendingPullRequestMerge.Doer.Name $createdPRMergeStr}}
|
||||
{{end}}
|
||||
<div class="ui divider"></div>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
{{$baseHref = printf "<a href=\"%s\">%s</a>" (.BaseBranchHTMLURL | Escape) $baseHref}}
|
||||
{{end}}
|
||||
{{if .Issue.PullRequest.HasMerged}}
|
||||
{{ $mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix $.i18n.Lang }}
|
||||
{{ $mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix $.i18n }}
|
||||
{{if .Issue.OriginalAuthor }}
|
||||
{{.Issue.OriginalAuthor}}
|
||||
<span class="pull-desc">{{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits $headHref $baseHref $mergedStr | Safe}}</span>
|
||||
|
@ -88,7 +88,7 @@
|
|||
</span>
|
||||
{{end}}
|
||||
{{else}}
|
||||
{{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.i18n.Lang }}
|
||||
{{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.i18n }}
|
||||
<span class="time-desc">
|
||||
{{if .Issue.OriginalAuthor }}
|
||||
{{$.i18n.Tr "repo.issues.opened_by_fake" $createdStr (.Issue.OriginalAuthor|Escape) | Safe}}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<li class="item">
|
||||
{{svg "octicon-project"}} <a href="{{$.RepoLink}}/projects/{{.ID}}">{{.Title}}</a>
|
||||
<div class="meta">
|
||||
{{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n.Lang }}
|
||||
{{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n }}
|
||||
{{if .IsClosed }}
|
||||
{{svg "octicon-clock"}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}}
|
||||
{{end}}
|
||||
|
|
|
@ -207,7 +207,7 @@
|
|||
<div class="meta my-2">
|
||||
<span class="text light grey">
|
||||
#{{.Index}}
|
||||
{{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.i18n.Lang }}
|
||||
{{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.i18n }}
|
||||
{{if .OriginalAuthor }}
|
||||
{{$.i18n.Tr .GetLastEventLabelFake $timeStr (.OriginalAuthor|Escape) | Safe}}
|
||||
{{else if gt .Poster.ID 0}}
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
<li class="ui grid">
|
||||
<div class="ui four wide column meta mt-2">
|
||||
{{if .IsTag}}
|
||||
{{if .CreatedUnix}}<span class="time">{{TimeSinceUnix .CreatedUnix $.i18n.Lang}}</span>{{end}}
|
||||
{{if .CreatedUnix}}<span class="time">{{TimeSinceUnix .CreatedUnix $.i18n}}</span>{{end}}
|
||||
{{else}}
|
||||
{{if .IsDraft}}
|
||||
<span class="ui yellow label">{{$.i18n.Tr "repo.release.draft"}}</span>
|
||||
|
@ -132,7 +132,7 @@
|
|||
{{$.i18n.Tr "repo.released_this"}}
|
||||
</span>
|
||||
{{if .CreatedUnix}}
|
||||
<span class="time">{{TimeSinceUnix .CreatedUnix $.i18n.Lang}}</span>
|
||||
<span class="time">{{TimeSinceUnix .CreatedUnix $.i18n}}</span>
|
||||
{{end}}
|
||||
{{if not .IsDraft}}
|
||||
| <span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | PathEscapeSegments}}...{{.Target | PathEscapeSegments}}">{{$.i18n.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{$.i18n.Tr "repo.release.ahead.target" .Target}}</span>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
</span>
|
||||
</td>
|
||||
<td>{{FileSize .Size}}</td>
|
||||
<td>{{TimeSince .CreatedUnix.AsTime $.i18n.Lang}}</td>
|
||||
<td>{{TimeSince .CreatedUnix.AsTime $.i18n}}</td>
|
||||
<td class="right aligned">
|
||||
<a class="ui primary show-panel button" href="{{$.Link}}/find?oid={{.Oid}}&size={{.Size}}">{{$.i18n.Tr "repo.settings.lfs_findcommits"}}</a>
|
||||
<button class="ui basic show-modal icon button" data-modal="#delete-{{.Oid}}">
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
{{$.i18n.Tr "repo.diff.commit"}}
|
||||
<a class="ui primary sha label" href="{{$.RepoLink}}/commit/{{.SHA}}">{{ShortSha .SHA}}</a>
|
||||
</td>
|
||||
<td>{{TimeSince .When $.i18n.Lang}}</td>
|
||||
<td>{{TimeSince .When $.i18n}}</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
{{$.Owner.DisplayName}}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{TimeSince .Created $.i18n.Lang}}</td>
|
||||
<td>{{TimeSince .Created $.i18n}}</td>
|
||||
<td class="right aligned">
|
||||
<form action="{{$.LFSFilesLink}}/locks/{{$lock.ID}}/unlock" method="POST">
|
||||
{{$.CsrfTokenHtml}}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
</span>
|
||||
{{end}}
|
||||
</th>
|
||||
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When $.i18n.Lang}}{{end}}{{end}}</th>
|
||||
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When $.i18n}}{{end}}{{end}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -87,7 +87,7 @@
|
|||
{{end}}
|
||||
</span>
|
||||
</td>
|
||||
<td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When $.i18n.Lang}}{{end}}</td>
|
||||
<td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When $.i18n}}{{end}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
{{svg "octicon-file"}}
|
||||
<a href="{{$.RepoLink}}/wiki/{{.SubURL}}">{{.Name}}</a>
|
||||
</td>
|
||||
{{$timeSince := TimeSinceUnix .UpdatedUnix $.i18n.Lang}}
|
||||
{{$timeSince := TimeSinceUnix .UpdatedUnix $.i18n}}
|
||||
<td class="text right grey">{{$.i18n.Tr "repo.wiki.last_updated" $timeSince | Safe}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.back_to_wiki"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}" ><span>{{.revision}}</span> {{svg "octicon-home"}}</a>
|
||||
{{$title}}
|
||||
<div class="ui sub header word-break">
|
||||
{{$timeSince := TimeSince .Author.When $.i18n.Lang}}
|
||||
{{$timeSince := TimeSince .Author.When $.i18n}}
|
||||
{{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.file_revision"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}?action=_revision" ><span>{{.CommitCount}}</span> {{svg "octicon-history"}}</a>
|
||||
{{$title}}
|
||||
<div class="ui sub header">
|
||||
{{$timeSince := TimeSince .Author.When $.i18n.Lang}}
|
||||
{{$timeSince := TimeSince .Author.When $.i18n}}
|
||||
{{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#{{.Index}}
|
||||
{{end}}
|
||||
</a>
|
||||
{{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.i18n.Lang }}
|
||||
{{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.i18n }}
|
||||
{{if .OriginalAuthor }}
|
||||
{{$.i18n.Tr .GetLastEventLabelFake $timeStr (.OriginalAuthor|Escape) | Safe}}
|
||||
{{else if gt .Poster.ID 0}}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
</div>
|
||||
<div class="mr-4">
|
||||
{{if not .result.UpdatedUnix.IsZero}}
|
||||
<span class="ui grey text">{{.root.i18n.Tr "explore.code_last_indexed_at" (TimeSinceUnix .result.UpdatedUnix .root.i18n.Lang) | Safe}}</span>
|
||||
<span class="ui grey text">{{.root.i18n.Tr "explore.code_last_indexed_at" (TimeSinceUnix .result.UpdatedUnix .root.i18n) | Safe}}</span>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -114,7 +114,7 @@
|
|||
<p class="text light grey">{{$.i18n.Tr "action.review_dismissed_reason"}}</p>
|
||||
<p class="text light grey">{{index .GetIssueInfos 2 | RenderEmoji}}</p>
|
||||
{{end}}
|
||||
<p class="text italic light grey">{{TimeSince .GetCreate $.i18n.Lang}}</p>
|
||||
<p class="text italic light grey">{{TimeSince .GetCreate $.i18n}}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui two wide right aligned column">
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="meta">
|
||||
{{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n.Lang }}
|
||||
{{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n }}
|
||||
{{if .IsClosed}}
|
||||
{{svg "octicon-clock"}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}}
|
||||
{{else}}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<div class="content">
|
||||
<strong>{{.Name}}</strong>
|
||||
</div>
|
||||
<span class="time">{{TimeSinceUnix .CreatedUnix $.i18n.Lang}}</span>
|
||||
<span class="time">{{TimeSinceUnix .CreatedUnix $.i18n}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue