Make use of printer.Print when possible

This commit is contained in:
jvoisin 2024-02-27 17:19:38 +01:00 committed by Frédéric Guillot
parent b4ed17fbac
commit 5a7d6f8997
8 changed files with 22 additions and 22 deletions

View file

@ -180,13 +180,13 @@ func durationImpl(t time.Time, now time.Time) string {
func elapsedTime(printer *locale.Printer, tz string, t time.Time) string { func elapsedTime(printer *locale.Printer, tz string, t time.Time) string {
if t.IsZero() { if t.IsZero() {
return printer.Printf("time_elapsed.not_yet") return printer.Print("time_elapsed.not_yet")
} }
now := timezone.Now(tz) now := timezone.Now(tz)
t = timezone.Convert(tz, t) t = timezone.Convert(tz, t)
if now.Before(t) { if now.Before(t) {
return printer.Printf("time_elapsed.not_yet") return printer.Print("time_elapsed.not_yet")
} }
diff := now.Sub(t) diff := now.Sub(t)
@ -196,7 +196,7 @@ func elapsedTime(printer *locale.Printer, tz string, t time.Time) string {
d := int(s / 86400) d := int(s / 86400)
switch { switch {
case s < 60: case s < 60:
return printer.Printf("time_elapsed.now") return printer.Print("time_elapsed.now")
case s < 3600: case s < 3600:
minutes := int(diff.Minutes()) minutes := int(diff.Minutes())
return printer.Plural("time_elapsed.minutes", minutes, minutes) return printer.Plural("time_elapsed.minutes", minutes, minutes)
@ -204,7 +204,7 @@ func elapsedTime(printer *locale.Printer, tz string, t time.Time) string {
hours := int(diff.Hours()) hours := int(diff.Hours())
return printer.Plural("time_elapsed.hours", hours, hours) return printer.Plural("time_elapsed.hours", hours, hours)
case d == 1: case d == 1:
return printer.Printf("time_elapsed.yesterday") return printer.Print("time_elapsed.yesterday")
case d < 21: case d < 21:
return printer.Plural("time_elapsed.days", d, d) return printer.Plural("time_elapsed.days", d, d)
case d < 31: case d < 31:

View file

@ -127,14 +127,14 @@ func TestElapsedTime(t *testing.T) {
in time.Time in time.Time
out string out string
}{ }{
{time.Time{}, printer.Printf("time_elapsed.not_yet")}, {time.Time{}, printer.Print("time_elapsed.not_yet")},
{time.Now().Add(time.Hour), printer.Printf("time_elapsed.not_yet")}, {time.Now().Add(time.Hour), printer.Print("time_elapsed.not_yet")},
{time.Now(), printer.Printf("time_elapsed.now")}, {time.Now(), printer.Print("time_elapsed.now")},
{time.Now().Add(-time.Minute), printer.Plural("time_elapsed.minutes", 1, 1)}, {time.Now().Add(-time.Minute), printer.Plural("time_elapsed.minutes", 1, 1)},
{time.Now().Add(-time.Minute * 40), printer.Plural("time_elapsed.minutes", 40, 40)}, {time.Now().Add(-time.Minute * 40), printer.Plural("time_elapsed.minutes", 40, 40)},
{time.Now().Add(-time.Hour), printer.Plural("time_elapsed.hours", 1, 1)}, {time.Now().Add(-time.Hour), printer.Plural("time_elapsed.hours", 1, 1)},
{time.Now().Add(-time.Hour * 3), printer.Plural("time_elapsed.hours", 3, 3)}, {time.Now().Add(-time.Hour * 3), printer.Plural("time_elapsed.hours", 3, 3)},
{time.Now().Add(-time.Hour * 32), printer.Printf("time_elapsed.yesterday")}, {time.Now().Add(-time.Hour * 32), printer.Print("time_elapsed.yesterday")},
{time.Now().Add(-time.Hour * 24 * 3), printer.Plural("time_elapsed.days", 3, 3)}, {time.Now().Add(-time.Hour * 24 * 3), printer.Plural("time_elapsed.days", 3, 3)},
{time.Now().Add(-time.Hour * 24 * 14), printer.Plural("time_elapsed.days", 14, 14)}, {time.Now().Add(-time.Hour * 24 * 14), printer.Plural("time_elapsed.days", 14, 14)},
{time.Now().Add(-time.Hour * 24 * 15), printer.Plural("time_elapsed.days", 15, 15)}, {time.Now().Add(-time.Hour * 24 * 15), printer.Plural("time_elapsed.days", 15, 15)},

View file

@ -33,7 +33,7 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64
// Avoid accidental and excessive refreshes. // Avoid accidental and excessive refreshes.
if time.Now().UTC().Unix()-request.LastForceRefresh(r) < 1800 { if time.Now().UTC().Unix()-request.LastForceRefresh(r) < 1800 {
sess.NewFlashErrorMessage(printer.Printf("alert.too_many_feeds_refresh")) sess.NewFlashErrorMessage(printer.Print("alert.too_many_feeds_refresh"))
} else { } else {
// We allow the end-user to force refresh all its feeds in this category // We allow the end-user to force refresh all its feeds in this category
// without taking into consideration the number of errors. // without taking into consideration the number of errors.
@ -58,7 +58,7 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64
go h.pool.Push(jobs) go h.pool.Push(jobs)
sess.SetLastForceRefresh() sess.SetLastForceRefresh()
sess.NewFlashMessage(printer.Printf("alert.background_feed_refresh")) sess.NewFlashMessage(printer.Print("alert.background_feed_refresh"))
} }
return categoryID return categoryID

View file

@ -63,7 +63,7 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
go h.pool.Push(jobs) go h.pool.Push(jobs)
sess.SetLastForceRefresh() sess.SetLastForceRefresh()
sess.NewFlashMessage(printer.Printf("alert.background_feed_refresh")) sess.NewFlashMessage(printer.Print("alert.background_feed_refresh"))
} }
html.Redirect(w, r, route.Path(h.router, "feeds")) html.Redirect(w, r, route.Path(h.router, "feeds"))

View file

@ -39,7 +39,7 @@ func (h *handler) pocketAuthorize(w http.ResponseWriter, r *http.Request) {
slog.Any("user_id", user.ID), slog.Any("user_id", user.ID),
slog.Any("error", err), slog.Any("error", err),
) )
sess.NewFlashErrorMessage(printer.Printf("error.pocket_request_token")) sess.NewFlashErrorMessage(printer.Print("error.pocket_request_token"))
html.Redirect(w, r, route.Path(h.router, "integrations")) html.Redirect(w, r, route.Path(h.router, "integrations"))
return return
} }
@ -71,7 +71,7 @@ func (h *handler) pocketCallback(w http.ResponseWriter, r *http.Request) {
slog.Any("user_id", user.ID), slog.Any("user_id", user.ID),
slog.Any("error", err), slog.Any("error", err),
) )
sess.NewFlashErrorMessage(printer.Printf("error.pocket_access_token")) sess.NewFlashErrorMessage(printer.Print("error.pocket_access_token"))
html.Redirect(w, r, route.Path(h.router, "integrations")) html.Redirect(w, r, route.Path(h.router, "integrations"))
return return
} }
@ -85,6 +85,6 @@ func (h *handler) pocketCallback(w http.ResponseWriter, r *http.Request) {
return return
} }
sess.NewFlashMessage(printer.Printf("alert.pocket_linked")) sess.NewFlashMessage(printer.Print("alert.pocket_linked"))
html.Redirect(w, r, route.Path(h.router, "integrations")) html.Redirect(w, r, route.Path(h.router, "integrations"))
} }

View file

@ -36,7 +36,7 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) {
integrationForm.Merge(integration) integrationForm.Merge(integration)
if integration.FeverUsername != "" && h.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) { if integration.FeverUsername != "" && h.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) {
sess.NewFlashErrorMessage(printer.Printf("error.duplicate_fever_username")) sess.NewFlashErrorMessage(printer.Print("error.duplicate_fever_username"))
html.Redirect(w, r, route.Path(h.router, "integrations")) html.Redirect(w, r, route.Path(h.router, "integrations"))
return return
} }
@ -50,7 +50,7 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) {
} }
if integration.GoogleReaderUsername != "" && h.store.HasDuplicateGoogleReaderUsername(user.ID, integration.GoogleReaderUsername) { if integration.GoogleReaderUsername != "" && h.store.HasDuplicateGoogleReaderUsername(user.ID, integration.GoogleReaderUsername) {
sess.NewFlashErrorMessage(printer.Printf("error.duplicate_googlereader_username")) sess.NewFlashErrorMessage(printer.Print("error.duplicate_googlereader_username"))
html.Redirect(w, r, route.Path(h.router, "integrations")) html.Redirect(w, r, route.Path(h.router, "integrations"))
return return
} }
@ -85,6 +85,6 @@ func (h *handler) updateIntegration(w http.ResponseWriter, r *http.Request) {
return return
} }
sess.NewFlashMessage(printer.Printf("alert.prefs_saved")) sess.NewFlashMessage(printer.Print("alert.prefs_saved"))
html.Redirect(w, r, route.Path(h.router, "integrations")) html.Redirect(w, r, route.Path(h.router, "integrations"))
} }

View file

@ -81,7 +81,7 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) {
slog.String("oauth2_provider", provider), slog.String("oauth2_provider", provider),
slog.String("oauth2_profile_id", profile.ID), slog.String("oauth2_profile_id", profile.ID),
) )
sess.NewFlashErrorMessage(printer.Printf("error.duplicate_linked_account")) sess.NewFlashErrorMessage(printer.Print("error.duplicate_linked_account"))
html.Redirect(w, r, route.Path(h.router, "settings")) html.Redirect(w, r, route.Path(h.router, "settings"))
return return
} }
@ -92,7 +92,7 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) {
return return
} }
sess.NewFlashMessage(printer.Printf("alert.account_linked")) sess.NewFlashMessage(printer.Print("alert.account_linked"))
html.Redirect(w, r, route.Path(h.router, "settings")) html.Redirect(w, r, route.Path(h.router, "settings"))
return return
} }
@ -110,7 +110,7 @@ func (h *handler) oauth2Callback(w http.ResponseWriter, r *http.Request) {
} }
if h.store.UserExists(profile.Username) { if h.store.UserExists(profile.Username) {
html.BadRequest(w, r, errors.New(printer.Printf("error.user_already_exists"))) html.BadRequest(w, r, errors.New(printer.Print("error.user_already_exists")))
return return
} }

View file

@ -47,7 +47,7 @@ func (h *handler) oauth2Unlink(w http.ResponseWriter, r *http.Request) {
} }
if !hasPassword { if !hasPassword {
sess.NewFlashErrorMessage(printer.Printf("error.unlink_account_without_password")) sess.NewFlashErrorMessage(printer.Print("error.unlink_account_without_password"))
html.Redirect(w, r, route.Path(h.router, "settings")) html.Redirect(w, r, route.Path(h.router, "settings"))
return return
} }
@ -58,6 +58,6 @@ func (h *handler) oauth2Unlink(w http.ResponseWriter, r *http.Request) {
return return
} }
sess.NewFlashMessage(printer.Printf("alert.account_unlinked")) sess.NewFlashMessage(printer.Print("alert.account_unlinked"))
html.Redirect(w, r, route.Path(h.router, "settings")) html.Redirect(w, r, route.Path(h.router, "settings"))
} }