Skip to content

Commit

Permalink
feat: Add a route to get translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Dec 28, 2024
1 parent ae8dae9 commit 7c072e1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/api/get-translations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package api

func GetTranslations() (map[string]interface{}, error) {
var translations map[string]interface{}

return translations, nil
}
1 change: 1 addition & 0 deletions cmd/server/handle-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func HandleRoutes(mux *http.ServeMux, apiPath string) {
apiRoute(mux, apiPath, "/content-type", "GET", v1.GetContentType)
apiRoute(mux, apiPath, "/global-fields", "GET", v1.GetGlobalFields)
apiRoute(mux, apiPath, "/locales", "GET", v1.GetLocales)
apiRoute(mux, apiPath, "/translations", "GET", v1.GetTranslations)
apiRoute(mux, apiPath, "/sitemap-data", "GET", v1.GetSitemapData)
apiRoute(mux, apiPath, "/sync", "POST", v1.Sync)
}
Expand Down
31 changes: 31 additions & 0 deletions cmd/server/routes/v1/get-translations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package v1

import (
"encoding/json"
"fmt"
"net/http"

"github.com/Dobefu/csb/cmd/api"
"github.com/Dobefu/csb/cmd/server/utils"
)

func GetTranslations(w http.ResponseWriter, r *http.Request) {
locales, err := api.GetTranslations()

if err != nil {
utils.PrintError(w, err, false)
return
}

output := utils.ConstructOutput()
output["data"] = locales

json, err := json.Marshal(output)

if err != nil {
utils.PrintError(w, err, true)
return
}

fmt.Fprint(w, string(json))
}

0 comments on commit 7c072e1

Please sign in to comment.