Localize client API responses by lang query param.

Client endpoints now return a single-language string (default tm) so the frontend can pass ?lang= and skip picking from nested tm/ru/en objects.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-06 12:27:10 +05:00
parent 76848f4982
commit ddd898078c
5 changed files with 202 additions and 110 deletions

View File

@@ -48,6 +48,10 @@ func (h *handler) Register(router *gin.RouterGroup) {
router.GET(getSettingURL, h.GetSetting)
}
func queryLang(c *gin.Context) string {
return NormalizeLang(c.Query("lang"))
}
// =================================================================================
// GetNews godoc
@@ -55,8 +59,9 @@ func (h *handler) Register(router *gin.RouterGroup) {
// @Tags news
// @Accept json
// @Produce json
// @Param limit query int false "limit"
// @Param page query int false "page"
// @Param limit query int false "limit"
// @Param page query int false "page"
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {object} DataNewsDTO
// @Router /client/users/news [get]
func (h *handler) GetNews(c *gin.Context) {
@@ -66,7 +71,7 @@ func (h *handler) GetNews(c *gin.Context) {
limit, _ := strconv.Atoi(limitS)
page, _ := strconv.Atoi(pageS)
result, err := h.repository.GetNews(c.Request.Context(), limit, page)
result, err := h.repository.GetNews(c.Request.Context(), limit, page, queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
@@ -83,6 +88,7 @@ func (h *handler) GetNews(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id path int true "news ID"
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {object} NewsDTO
// @Router /client/users/news/{id} [get]
func (h *handler) GetOneNews(c *gin.Context) {
@@ -92,7 +98,7 @@ func (h *handler) GetOneNews(c *gin.Context) {
return
}
result, err := h.repository.GetNewsById(c.Request.Context(), id)
result, err := h.repository.GetNewsById(c.Request.Context(), id, queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
@@ -109,6 +115,7 @@ func (h *handler) GetOneNews(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id path int true "sub-category ID"
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {object} SubCategoryDTO
// @Router /client/users/sub-categories/{id} [get]
func (h *handler) GetSubCategory(c *gin.Context) {
@@ -118,7 +125,7 @@ func (h *handler) GetSubCategory(c *gin.Context) {
return
}
result, err := h.repository.GetSubCategoryById(c.Request.Context(), id)
result, err := h.repository.GetSubCategoryById(c.Request.Context(), id, queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
@@ -162,6 +169,7 @@ func (h *handler) GetBanners(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id path int true "banner ID"
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {object} BannerDTO
// @Router /client/users/banners/{id} [get]
func (h *handler) GetOneBanner(c *gin.Context) {
@@ -171,7 +179,7 @@ func (h *handler) GetOneBanner(c *gin.Context) {
return
}
result, err := h.repository.GetBannerById(c.Request.Context(), id)
result, err := h.repository.GetBannerById(c.Request.Context(), id, queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
@@ -187,8 +195,9 @@ func (h *handler) GetOneBanner(c *gin.Context) {
// @Tags statics
// @Accept json
// @Produce json
// @Param limit query int false "limit"
// @Param page query int false "page"
// @Param limit query int false "limit"
// @Param page query int false "page"
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {object} DataStaticDTO
// @Router /client/users/static [get]
func (h *handler) GetStatics(c *gin.Context) {
@@ -198,7 +207,7 @@ func (h *handler) GetStatics(c *gin.Context) {
limit, _ := strconv.Atoi(limitS)
page, _ := strconv.Atoi(pageS)
result, err := h.repository.GetStatics(c.Request.Context(), limit, page)
result, err := h.repository.GetStatics(c.Request.Context(), limit, page, queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
@@ -215,6 +224,7 @@ func (h *handler) GetStatics(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id path int true "static ID"
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {object} StaticDTO
// @Router /client/users/static/{id} [get]
func (h *handler) GetOneStatic(c *gin.Context) {
@@ -224,7 +234,7 @@ func (h *handler) GetOneStatic(c *gin.Context) {
return
}
result, err := h.repository.GetStaticById(c.Request.Context(), id)
result, err := h.repository.GetStaticById(c.Request.Context(), id, queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
@@ -236,14 +246,15 @@ func (h *handler) GetOneStatic(c *gin.Context) {
}
// GetCurrency godoc
// @Description latest currency content (title + HTML table per language)
// @Description latest currency content (title + HTML table for requested language)
// @Tags currency
// @Accept json
// @Produce json
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {object} CurrencyDTO
// @Router /client/users/currency [get]
func (h *handler) GetCurrency(c *gin.Context) {
result, err := h.repository.GetCurrency(c.Request.Context())
result, err := h.repository.GetCurrency(c.Request.Context(), queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
@@ -278,10 +289,11 @@ func (h *handler) GetSetting(c *gin.Context) {
// @Tags categories
// @Accept json
// @Produce json
// @Param lang query string false "tm|ru|en (default tm)"
// @Success 200 {array} CategoryDTO
// @Router /client/users/categories [get]
func (h *handler) GetCategories(c *gin.Context) {
result, err := h.repository.GetCategories(c.Request.Context())
result, err := h.repository.GetCategories(c.Request.Context(), queryLang(c))
if err != nil {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return