loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(ui): localize theme names (#7168)

Allow translating theme names. Not even for i18n reasons but because this way the menu is clearer and cleaner.

The number of translated entries is kept minimal for now. It is easy to pollute locales with these names otherwise.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7168
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

0ko 584c504e f015c00e

+35 -9
+1
.deadcode-out
··· 189 189 MockLocale.TrN 190 190 MockLocale.TrPluralString 191 191 MockLocale.TrSize 192 + MockLocale.HasKey 192 193 MockLocale.PrettyNumber 193 194 194 195 code.gitea.io/gitea/modules/util
+4
modules/translation/mock.go
··· 39 39 return ReadableSize{fmt.Sprint(s), ""} 40 40 } 41 41 42 + func (l MockLocale) HasKey(key string) bool { 43 + return true 44 + } 45 + 42 46 func (l MockLocale) PrettyNumber(v any) string { 43 47 return fmt.Sprint(v) 44 48 }
+2
modules/translation/translation.go
··· 39 39 40 40 TrSize(size int64) ReadableSize 41 41 42 + HasKey(trKey string) bool 43 + 42 44 PrettyNumber(v any) string 43 45 } 44 46
+4 -1
options/locale_next/locale_en-US.json
··· 13 13 "other": "wants to merge %[1]d commits from <code>%[2]s</code> into <code id=\"%[4]s\">%[3]s</code>" 14 14 }, 15 15 "search.milestone_kind": "Search milestones…", 16 - "incorrect_root_url": "This Forgejo instance is configured to be served on \"%s\". You are currently viewing Forgejo through a different URL, which may cause parts of the application to break. The canonical URL is controlled by Forgejo admins via the ROOT_URL setting in the app.ini." 16 + "incorrect_root_url": "This Forgejo instance is configured to be served on \"%s\". You are currently viewing Forgejo through a different URL, which may cause parts of the application to break. The canonical URL is controlled by Forgejo admins via the ROOT_URL setting in the app.ini.", 17 + "themes.names.forgejo-auto": "Forgejo (follow system theme)", 18 + "themes.names.forgejo-light": "Forgejo light", 19 + "themes.names.forgejo-dark": "Forgejo dark" 17 20 }
+7
routers/web/user/setting/profile.go
··· 330 330 ctx.Data["Title"] = ctx.Tr("settings.appearance") 331 331 ctx.Data["PageIsSettingsAppearance"] = true 332 332 ctx.Data["AllThemes"] = setting.UI.Themes 333 + ctx.Data["ThemeName"] = func(themeName string) string { 334 + fullThemeName := "themes.names." + themeName 335 + if ctx.Locale.HasKey(fullThemeName) { 336 + return ctx.Locale.TrString(fullThemeName) 337 + } 338 + return themeName 339 + } 333 340 334 341 var hiddenCommentTypes *big.Int 335 342 val, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
+4 -4
templates/user/settings/appearance.tmpl
··· 19 19 <input name="theme" type="hidden" value="{{.SignedUser.Theme}}"> 20 20 {{svg "octicon-triangle-down" 14 "dropdown icon"}} 21 21 <div class="text"> 22 - {{range $i,$a := .AllThemes}} 23 - {{if eq $.SignedUser.Theme $a}}{{$a}}{{end}} 24 - {{end}} 22 + {{- range $i,$a := .AllThemes -}} 23 + {{if eq $.SignedUser.Theme $a}}{{call $.ThemeName $a}}{{end}} 24 + {{- end -}} 25 25 </div> 26 26 27 27 <div class="menu"> 28 28 {{range $i,$a := .AllThemes}} 29 29 <div class="item{{if eq $.SignedUser.Theme $a}} active selected{{end}}" data-value="{{$a}}"> 30 - {{$a}} 30 + {{call $.ThemeName $a}} 31 31 </div> 32 32 {{end}} 33 33 </div>
+13 -4
tests/integration/appearance_settings_test.go
··· 5 5 6 6 import ( 7 7 "net/http" 8 + "strings" 8 9 "testing" 9 10 10 11 "code.gitea.io/gitea/tests" ··· 16 17 defer tests.PrepareTestEnv(t)() 17 18 user := loginUser(t, "user2") 18 19 19 - testSelectedTheme(t, user, "forgejo-auto") 20 + // Verify default theme 21 + testSelectedTheme(t, user, "forgejo-auto", "Forgejo (follow system theme)") 20 22 23 + // Change theme to forgejo-dark and verify it works fine 21 24 testChangeTheme(t, user, "forgejo-dark") 22 - testSelectedTheme(t, user, "forgejo-dark") 25 + testSelectedTheme(t, user, "forgejo-dark", "Forgejo dark") 26 + 27 + // Change theme to gitea-dark and also verify that it's name is not translated 28 + testChangeTheme(t, user, "gitea-dark") 29 + testSelectedTheme(t, user, "gitea-dark", "gitea-dark") 23 30 } 24 31 25 32 // testSelectedTheme checks that the expected theme is used in html[data-theme] 26 33 // and is default on appearance page 27 - func testSelectedTheme(t *testing.T, session *TestSession, expectedTheme string) { 34 + func testSelectedTheme(t *testing.T, session *TestSession, expectedTheme, expectedName string) { 28 35 t.Helper() 29 36 response := session.MakeRequest(t, NewRequest(t, "GET", "/user/settings/appearance"), http.StatusOK) 30 37 page := NewHTMLParser(t, response.Body) ··· 33 40 assert.True(t, dataThemeExists) 34 41 assert.EqualValues(t, expectedTheme, dataTheme) 35 42 36 - selectorTheme, selectorThemeExists := page.Find("form[action='/user/settings/appearance/theme'] input[name='theme']").Attr("value") 43 + selectedTheme := page.Find("form[action='/user/settings/appearance/theme'] .menu .item.selected") 44 + selectorTheme, selectorThemeExists := selectedTheme.Attr("data-value") 37 45 assert.True(t, selectorThemeExists) 38 46 assert.EqualValues(t, expectedTheme, selectorTheme) 47 + assert.EqualValues(t, expectedName, strings.TrimSpace(selectedTheme.Text())) 39 48 } 40 49 41 50 // testSelectedTheme changes user's theme