Skip to content

Commit

Permalink
Fixed missing language links and translation
Browse files Browse the repository at this point in the history
  • Loading branch information
svera authored Oct 26, 2023
1 parent 14e6ac9 commit d0f1c6e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 49 deletions.
36 changes: 14 additions & 22 deletions internal/controller/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ func (a *Auth) Login(c *fiber.Ctx) error {
}

return c.Render("auth/login", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Login",
"Version": c.App().Config().AppName,
"Message": msg,
"EmailSendingConfigured": emailSendingConfigured,
}, "layout")
Expand All @@ -105,9 +103,8 @@ func (a *Auth) SignIn(c *fiber.Ctx) error {

if user.Password != model.Hash(c.FormValue("password")) {
return c.Status(fiber.StatusUnauthorized).Render("auth/login", fiber.Map{
"Title": "Login",
"Error": "Wrong email or password",
"Version": c.App().Config().AppName,
"Title": "Login",
"Error": "Wrong email or password",
}, "layout")
}

Expand Down Expand Up @@ -164,9 +161,8 @@ func (a *Auth) Recover(c *fiber.Ctx) error {
}

return c.Render("auth/recover", fiber.Map{
"Title": "Recover password",
"Version": c.App().Config().AppName,
"Errors": map[string]string{},
"Title": "Recover password",
"Errors": map[string]string{},
}, "layout")
}

Expand All @@ -177,9 +173,8 @@ func (a *Auth) Request(c *fiber.Ctx) error {

if _, err := mail.ParseAddress(c.FormValue("email")); err != nil {
return c.Render("auth/recover", fiber.Map{
"Title": "Recover password",
"Version": c.App().Config().AppName,
"Errors": map[string]string{"email": "Incorrect email address"},
"Title": "Recover password",
"Errors": map[string]string{"email": "Incorrect email address"},
}, "layout")
}

Expand Down Expand Up @@ -211,9 +206,8 @@ func (a *Auth) Request(c *fiber.Ctx) error {
}

return c.Render("auth/request", fiber.Map{
"Title": "Recover password",
"Version": c.App().Config().AppName,
"Errors": map[string]string{},
"Title": "Recover password",
"Errors": map[string]string{},
}, "layout")
}

Expand All @@ -223,10 +217,9 @@ func (a *Auth) EditPassword(c *fiber.Ctx) error {
}

return c.Render("auth/edit-password", fiber.Map{
"Title": "Reset password",
"Version": c.App().Config().AppName,
"Uuid": c.Query("id"),
"Errors": map[string]string{},
"Title": "Reset password",
"Uuid": c.Query("id"),
"Errors": map[string]string{},
}, "layout")
}

Expand All @@ -243,10 +236,9 @@ func (a *Auth) UpdatePassword(c *fiber.Ctx) error {

if errs = user.ConfirmPassword(c.FormValue("confirm-password"), a.minPasswordLength, errs); len(errs) > 0 {
return c.Render("auth/edit-password", fiber.Map{
"Title": "Reset password",
"Version": c.App().Config().AppName,
"Uuid": c.FormValue("id"),
"Errors": errs,
"Title": "Reset password",
"Uuid": c.FormValue("id"),
"Errors": errs,
}, "layout")
}

Expand Down
3 changes: 0 additions & 3 deletions internal/controller/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func Document(c *fiber.Ctx, libraryPath string, sender Sender, idx IdxReader, wo
emailSendingConfigured = false
}

lang := c.Params("lang")
session := jwtclaimsreader.SessionData(c)
if session.WordsPerMinute > 0 {
wordsPerMinute = session.WordsPerMinute
Expand Down Expand Up @@ -63,7 +62,6 @@ func Document(c *fiber.Ctx, libraryPath string, sender Sender, idx IdxReader, wo
}

return c.Render("document", fiber.Map{
"Lang": lang,
"Title": title,
"Document": document,
"EmailSendingConfigured": emailSendingConfigured,
Expand All @@ -73,7 +71,6 @@ func Document(c *fiber.Ctx, libraryPath string, sender Sender, idx IdxReader, wo
"SameAuthors": sameAuthors,
"SameSubjects": sameSubjects,
"WordsPerMinute": wordsPerMinute,
"Version": c.App().Config().AppName,
}, "layout")

}
1 change: 0 additions & 1 deletion internal/controller/highlights.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (h *Highlights) Highlights(c *fiber.Ctx) error {
"Total": highlights.TotalHits,
"Paginator": pagination(model.MaxPagesNavigator, highlights.TotalPages, page, nil),
"Title": "Highlights",
"Version": c.App().Config().AppName,
"EmailSendingConfigured": emailSendingConfigured,
"EmailFrom": h.sender.From(),
"Session": session,
Expand Down
3 changes: 0 additions & 3 deletions internal/controller/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
)

func DocReader(c *fiber.Ctx, libraryPath string, idx IdxReader) error {
lang := c.Params("lang")

document, err := idx.Document(c.Params("slug"))
if err != nil {
fmt.Println(err)
Expand All @@ -33,7 +31,6 @@ func DocReader(c *fiber.Ctx, libraryPath string, idx IdxReader) error {
title = fmt.Sprintf("%s - %s | Coreander", authors, document.Title)
}
return c.Render(template, fiber.Map{
"Lang": lang,
"Title": title,
"Author": strings.Join(document.Authors, ", "),
"Description": document.Description,
Expand Down
2 changes: 0 additions & 2 deletions internal/controller/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func Search(c *fiber.Ctx, idx IdxReader, sender Sender, wordsPerMinute float64,
"Total": searchResults.TotalHits,
"Paginator": pagination(model.MaxPagesNavigator, searchResults.TotalPages, searchResults.Page, map[string]string{"search": keywords}),
"Title": "Search results",
"Version": c.App().Config().AppName,
"EmailSendingConfigured": emailSendingConfigured,
"EmailFrom": sender.From(),
"Session": session,
Expand All @@ -75,7 +74,6 @@ func Search(c *fiber.Ctx, idx IdxReader, sender Sender, wordsPerMinute float64,
return c.Render("index", fiber.Map{
"Count": count,
"Title": "Coreander",
"Version": c.App().Config().AppName,
"Session": session,
}, "layout")
}
15 changes: 0 additions & 15 deletions internal/controller/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ func (u *Users) List(c *fiber.Ctx) error {

users, _ := u.repository.List(page, model.ResultsPerPage)
return c.Render("users/index", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Users",
"Users": users,
"Paginator": pagination(model.MaxPagesNavigator, totalPages, page, map[string]string{}),
"Session": session,
"Version": c.App().Config().AppName,
"Admins": u.repository.Admins(),
}, "layout")
}
Expand All @@ -81,10 +79,8 @@ func (u *Users) New(c *fiber.Ctx) error {
WordsPerMinute: u.wordsPerMinute,
}
return c.Render("users/new", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Add user",
"Session": session,
"Version": c.App().Config().AppName,
"MinPasswordLength": u.minPasswordLength,
"User": user,
"Errors": map[string]string{},
Expand Down Expand Up @@ -118,7 +114,6 @@ func (u *Users) Create(c *fiber.Ctx) error {
return c.Render("users/new", fiber.Map{
"Title": "Add user",
"Session": session,
"Version": c.App().Config().AppName,
"Errors": errs,
"User": user,
}, "layout")
Expand Down Expand Up @@ -146,11 +141,9 @@ func (u *Users) Edit(c *fiber.Ctx) error {
}

return c.Render("users/edit", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Edit user",
"User": user,
"Session": session,
"Version": c.App().Config().AppName,
"MinPasswordLength": u.minPasswordLength,
"Errors": map[string]string{},
}, "layout")
Expand Down Expand Up @@ -180,11 +173,9 @@ func (u *Users) Update(c *fiber.Ctx) error {
errs := user.Validate(u.minPasswordLength)
if len(errs) > 0 {
return c.Render("users/edit", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Edit user",
"User": user,
"Session": session,
"Version": c.App().Config().AppName,
"MinPasswordLength": u.minPasswordLength,
"Errors": errs,
}, "layout")
Expand All @@ -195,11 +186,9 @@ func (u *Users) Update(c *fiber.Ctx) error {
}

return c.Render("users/edit", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Edit user",
"User": user,
"Session": session,
"Version": c.App().Config().AppName,
"MinPasswordLength": u.minPasswordLength,
"Errors": errs,
"Message": "Profile updated",
Expand All @@ -226,11 +215,9 @@ func (u *Users) updatePassword(c *fiber.Ctx, session, user model.User) error {

if errs = user.ConfirmPassword(c.FormValue("confirm-password"), u.minPasswordLength, errs); len(errs) > 0 {
return c.Render("users/edit", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Edit user",
"User": user,
"Session": session,
"Version": c.App().Config().AppName,
"MinPasswordLength": u.minPasswordLength,
"ActiveTab": "password",
"Errors": errs,
Expand All @@ -243,11 +230,9 @@ func (u *Users) updatePassword(c *fiber.Ctx, session, user model.User) error {
}

return c.Render("users/edit", fiber.Map{
"Lang": c.Params("lang"),
"Title": "Edit user",
"User": user,
"Session": session,
"Version": c.App().Config().AppName,
"MinPasswordLength": u.minPasswordLength,
"ActiveTab": "password",
"Errors": errs,
Expand Down
10 changes: 7 additions & 3 deletions internal/webserver/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func SetupControllers(cfg Config, db *gorm.DB, metadataReaders map[string]metada
emailSendingConfigured = false
}

supportedLanguages := getSupportedLanguages()

return Controllers{
Auth: authController,
Users: usersController,
Expand Down Expand Up @@ -101,10 +103,11 @@ func SetupControllers(cfg Config, db *gorm.DB, metadataReaders map[string]metada
TokenLookup: "cookie:coreander",
ErrorHandler: func(c *fiber.Ctx, err error) error {
return c.Status(fiber.StatusForbidden).Render("auth/login", fiber.Map{
"Lang": chooseBestLanguage(c, getSupportedLanguages()),
"Lang": chooseBestLanguage(c, supportedLanguages),
"Title": "Login",
"Version": c.App().Config().AppName,
"EmailSendingConfigured": emailSendingConfigured,
"SupportedLanguages": supportedLanguages,
}, "layout")
},
}),
Expand All @@ -116,10 +119,11 @@ func SetupControllers(cfg Config, db *gorm.DB, metadataReaders map[string]metada
err = c.Next()
if cfg.RequireAuth {
return c.Status(fiber.StatusForbidden).Render("auth/login", fiber.Map{
"Lang": chooseBestLanguage(c, getSupportedLanguages()),
"Lang": chooseBestLanguage(c, supportedLanguages),
"Title": "Login",
"Version": c.App().Config().AppName,
"EmailSendingConfigured": emailSendingConfigured,
"SupportedLanguages": supportedLanguages,
}, "layout")
}
return err
Expand All @@ -139,7 +143,7 @@ func SetupControllers(cfg Config, db *gorm.DB, metadataReaders map[string]metada
err = c.Status(code).Render(
fmt.Sprintf("errors/%d", code),
fiber.Map{
"Lang": chooseBestLanguage(c, getSupportedLanguages()),
"Lang": chooseBestLanguage(c, supportedLanguages),
"Title": "Coreander",
"Session": jwtclaimsreader.SessionData(c),
"Version": c.App().Config().AppName,
Expand Down
1 change: 1 addition & 0 deletions internal/webserver/embedded/translations/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"Dark": "Oscuro"
"Auto": "Auto"
"Highlight": "Destacar"
"Highlights": "Destacados"
"%s highlights": "Destacados de %s"
"Remove from highlights": "Quitar de destacados"
"%d highlighted documents": "%d documentos destacados"
1 change: 1 addition & 0 deletions internal/webserver/embedded/translations/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"Dark": "Noir"
"Auto": "Auto"
"Highlight": "Ajouter aux favoris"
"Highlights": "Favoris"
"%s highlights": "Favoris du %s"
"Remove from highlights": "Retirer des favoris"
"%d highlighted documents": "%d documents favoris"
1 change: 1 addition & 0 deletions internal/webserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func routes(app *fiber.App, controllers Controllers, supportedLanguages []string
c.Locals("Lang", c.Params("lang"))
c.Locals("SupportedLanguages", supportedLanguages)
c.Locals("PathMinusLang", pathMinusLang)
c.Locals("Version", c.App().Config().AppName)
return c.Next()
})

Expand Down

0 comments on commit d0f1c6e

Please sign in to comment.