Skip to content

Commit d242511

Browse files
authored
Remove legacy unmaintained packages, refactor to support change default locale (#19308)
Remove two unmaintained vendor packages `i18n` and `paginater`. Changes: * Rewrite `i18n` package with a more clear fallback mechanism. Fix an unstable `Tr` behavior, add more tests. * Refactor the legacy `Paginater` to `Paginator`, test cases are kept unchanged. Trivial enhancement (no breaking for end users): * Use the first locale in LANGS setting option as the default, add a log to prevent from surprising users.
1 parent 27c34dd commit d242511

26 files changed

+758
-42
lines changed

custom/conf/app.example.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,7 @@ PATH =
21172117
;[i18n]
21182118
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21192119
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2120+
;; The first locale will be used as the default if user browser's language doesn't match any locale in the list.
21202121
;LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,uk-UA,ja-JP,es-ES,pt-BR,pt-PT,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR,el-GR,fa-IR,hu-HU,id-ID,ml-IN
21212122
;NAMES = English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,Українська,日本語,español,português do Brasil,Português de Portugal,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어,ελληνικά,فارسی,magyar nyelv,bahasa Indonesia,മലയാളം
21222123

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,8 @@ Default templates for project boards:
997997

998998
## i18n (`i18n`)
999999

1000-
- `LANGS`: **en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pt-PT,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR,el-GR,fa-IR,hu-HU,id-ID,ml-IN**: List of locales shown in language selector
1000+
- `LANGS`: **en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pt-PT,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR,el-GR,fa-IR,hu-HU,id-ID,ml-IN**:
1001+
List of locales shown in language selector. The first locale will be used as the default if user browser's language doesn't match any locale in the list.
10011002
- `NAMES`: **English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,日本語,español,português do Brasil,Português de Portugal,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어,ελληνικά,فارسی,magyar nyelv,bahasa Indonesia,മലയാളം**: Visible names corresponding to the locales
10021003

10031004
## U2F (`U2F`) **DEPRECATED**

docs/content/doc/advanced/customizing-gitea.en-us.md

+2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ LANGS = en-US,foo-BAR
299299
NAMES = English,FooBar
300300
```
301301

302+
The first locale will be used as the default if user browser's language doesn't match any locale in the list.
303+
302304
Locales may change between versions, so keeping track of your customized locales is highly encouraged.
303305

304306
### Readmes

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ require (
7878
github.com/stretchr/testify v1.7.0
7979
github.com/syndtr/goleveldb v1.0.0
8080
github.com/tstranex/u2f v1.0.0
81-
github.com/unknwon/i18n v0.0.0-20210904045753-ff3a8617e361
82-
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae
8381
github.com/unrolled/render v1.4.1
8482
github.com/urfave/cli v1.22.5
8583
github.com/xanzy/go-gitlab v0.58.0

go.sum

-5
Original file line numberDiff line numberDiff line change
@@ -1503,10 +1503,6 @@ github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0o
15031503
github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM=
15041504
github.com/unknwon/com v1.0.1 h1:3d1LTxD+Lnf3soQiD4Cp/0BRB+Rsa/+RTvz8GMMzIXs=
15051505
github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM=
1506-
github.com/unknwon/i18n v0.0.0-20210904045753-ff3a8617e361 h1:4Ij5sX4JEzCCY/CCl8trJHey1tPsIDomYTZf145GKk0=
1507-
github.com/unknwon/i18n v0.0.0-20210904045753-ff3a8617e361/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
1508-
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae h1:ihaXiJkaca54IaCSnEXtE/uSZOmPxKZhDfVLrzZLFDs=
1509-
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae/go.mod h1:1fdkY6xxl6ExVs2QFv7R0F5IRZHKA8RahhB9fMC9RvM=
15101506
github.com/unrolled/render v1.4.1 h1:VdpMc2YkAOWzbmC/P2yoHhRDXgsaCQHcTJ1KK6SNCA4=
15111507
github.com/unrolled/render v1.4.1/go.mod h1:cK4RSTTVdND5j9EYEc0LAMOvdG11JeiKjyjfyZRvV2w=
15121508
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
@@ -2272,7 +2268,6 @@ gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AW
22722268
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
22732269
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
22742270
gopkg.in/ini.v1 v1.44.2/go.mod h1:M3Cogqpuv0QCi3ExAY5V4uOt4qb/R3xZubo9m8lK5wg=
2275-
gopkg.in/ini.v1 v1.46.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
22762271
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
22772272
gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
22782273
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

integrations/auth_ldap_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
"code.gitea.io/gitea/models/organization"
1717
"code.gitea.io/gitea/models/unittest"
1818
user_model "code.gitea.io/gitea/models/user"
19+
"code.gitea.io/gitea/modules/translation/i18n"
1920
"code.gitea.io/gitea/services/auth"
2021

2122
"github.com/stretchr/testify/assert"
22-
"github.com/unknwon/i18n"
2323
)
2424

2525
type ldapUser struct {

integrations/branches_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"net/url"
1010
"testing"
1111

12+
"code.gitea.io/gitea/modules/translation/i18n"
13+
1214
"github.com/stretchr/testify/assert"
13-
"github.com/unknwon/i18n"
1415
)
1516

1617
func TestViewBranches(t *testing.T) {

integrations/pull_merge_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
"code.gitea.io/gitea/modules/git"
2525
api "code.gitea.io/gitea/modules/structs"
2626
"code.gitea.io/gitea/modules/test"
27+
"code.gitea.io/gitea/modules/translation/i18n"
2728
"code.gitea.io/gitea/services/pull"
2829

2930
"github.com/stretchr/testify/assert"
30-
"github.com/unknwon/i18n"
3131
)
3232

3333
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string, mergeStyle repo_model.MergeStyle) *httptest.ResponseRecorder {

integrations/release_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"code.gitea.io/gitea/models/unittest"
1515
"code.gitea.io/gitea/modules/setting"
1616
"code.gitea.io/gitea/modules/test"
17+
"code.gitea.io/gitea/modules/translation/i18n"
1718

1819
"github.com/PuerkitoBio/goquery"
1920
"github.com/stretchr/testify/assert"
20-
"github.com/unknwon/i18n"
2121
)
2222

2323
func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {

integrations/repo_branch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313

1414
"code.gitea.io/gitea/modules/setting"
1515
"code.gitea.io/gitea/modules/test"
16+
"code.gitea.io/gitea/modules/translation/i18n"
1617

1718
"github.com/stretchr/testify/assert"
18-
"github.com/unknwon/i18n"
1919
)
2020

2121
func testCreateBranch(t testing.TB, session *TestSession, user, repo, oldRefSubURL, newBranchName string, expectedStatus int) string {

integrations/signin_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111

1212
"code.gitea.io/gitea/models/unittest"
1313
user_model "code.gitea.io/gitea/models/user"
14+
"code.gitea.io/gitea/modules/translation/i18n"
1415

1516
"github.com/stretchr/testify/assert"
16-
"github.com/unknwon/i18n"
1717
)
1818

1919
func testLoginFailed(t *testing.T, username, password, message string) {

integrations/signup_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"code.gitea.io/gitea/models/unittest"
1414
user_model "code.gitea.io/gitea/models/user"
1515
"code.gitea.io/gitea/modules/setting"
16+
"code.gitea.io/gitea/modules/translation/i18n"
1617

1718
"github.com/stretchr/testify/assert"
18-
"github.com/unknwon/i18n"
1919
)
2020

2121
func TestSignup(t *testing.T) {
@@ -68,9 +68,9 @@ func TestSignupEmail(t *testing.T) {
6868
wantStatus int
6969
wantMsg string
7070
}{
71-
{"[email protected]\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
72-
{"[email protected]\r", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
73-
{"[email protected]\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
71+
{"[email protected]\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
72+
{"[email protected]\r", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
73+
{"[email protected]\n", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
7474
{"[email protected]", http.StatusSeeOther, ""},
7575
}
7676

integrations/user_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"code.gitea.io/gitea/models/unittest"
1212
user_model "code.gitea.io/gitea/models/user"
1313
"code.gitea.io/gitea/modules/test"
14+
"code.gitea.io/gitea/modules/translation/i18n"
1415

1516
"github.com/stretchr/testify/assert"
16-
"github.com/unknwon/i18n"
1717
)
1818

1919
func TestViewUser(t *testing.T) {

modules/context/pagination.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import (
1010
"net/url"
1111
"strings"
1212

13-
"github.com/unknwon/paginater"
13+
"code.gitea.io/gitea/modules/paginator"
1414
)
1515

16-
// Pagination provides a pagination via Paginater and additional configurations for the link params used in rendering
16+
// Pagination provides a pagination via paginator.Paginator and additional configurations for the link params used in rendering
1717
type Pagination struct {
18-
Paginater *paginater.Paginater
18+
Paginater *paginator.Paginator
1919
urlParams []string
2020
}
2121

2222
// NewPagination creates a new instance of the Pagination struct
2323
func NewPagination(total, page, issueNum, numPages int) *Pagination {
2424
p := &Pagination{}
25-
p.Paginater = paginater.New(total, page, issueNum, numPages)
25+
p.Paginater = paginator.New(total, page, issueNum, numPages)
2626
return p
2727
}
2828

@@ -53,5 +53,6 @@ func (p *Pagination) SetDefaultParams(ctx *Context) {
5353
p.AddParam(ctx, "sort", "SortType")
5454
p.AddParam(ctx, "q", "Keyword")
5555
p.AddParam(ctx, "tab", "TabName")
56+
// do not add any more uncommon params here!
5657
p.AddParam(ctx, "t", "queryType")
5758
}

modules/markup/markdown/toc.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
"fmt"
99
"net/url"
1010

11-
"github.com/unknwon/i18n"
11+
"code.gitea.io/gitea/modules/translation/i18n"
12+
1213
"github.com/yuin/goldmark/ast"
1314
)
1415

0 commit comments

Comments
 (0)