mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Backend: Add translations for API messages
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
@@ -32,7 +32,11 @@ https://docs.photoprism.org/developer-guide/
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/i18n"
|
||||
"github.com/photoprism/photoprism/internal/service"
|
||||
)
|
||||
|
||||
@@ -49,3 +53,33 @@ func UpdateClientConfig() {
|
||||
|
||||
event.Publish("config.updated", event.Data{"config": conf.UserConfig()})
|
||||
}
|
||||
|
||||
func Abort(c *gin.Context, code int, id i18n.Message, params ...interface{}) {
|
||||
resp := i18n.NewResponse(code, id, params...)
|
||||
log.Errorf("api: %s", resp.LowerString())
|
||||
c.AbortWithStatusJSON(code, resp)
|
||||
}
|
||||
|
||||
func AbortUnauthorized(c *gin.Context) {
|
||||
Abort(c, http.StatusUnauthorized, i18n.ErrUnauthorized)
|
||||
}
|
||||
|
||||
func AbortEntityNotFound(c *gin.Context) {
|
||||
Abort(c, http.StatusNotFound, i18n.ErrEntityNotFound)
|
||||
}
|
||||
|
||||
func AbortSaveFailed(c *gin.Context) {
|
||||
Abort(c, http.StatusInternalServerError, i18n.ErrSaveFailed)
|
||||
}
|
||||
|
||||
func AbortUnexpected(c *gin.Context) {
|
||||
Abort(c, http.StatusInternalServerError, i18n.ErrUnexpected)
|
||||
}
|
||||
|
||||
func AbortBadRequest(c *gin.Context) {
|
||||
Abort(c, http.StatusBadRequest, i18n.ErrBadRequest)
|
||||
}
|
||||
|
||||
func AbortAlreadyExists(c *gin.Context, s string) {
|
||||
Abort(c, http.StatusConflict, i18n.ErrAlreadyExists, s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user