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

@@ -1,6 +1,9 @@
package users
import "time"
import (
"strings"
"time"
)
type DataNewsDTO struct {
News []NewsDTO `json:"news"`
@@ -9,31 +12,81 @@ type DataNewsDTO struct {
type NewsDTO struct {
Id int `json:"id"`
Title Language `json:"title"`
Content Language `json:"content"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
Image string `json:"imagePath"`
DataRelease time.Time `json:"dateRelease"`
DataRelease time.Time `json:"dateRelease,omitzero"`
}
// Language is used when scanning multilingual JSON from the database.
type Language struct {
En string `json:"en"`
Ru string `json:"ru"`
Tm string `json:"tm"`
En string `json:"en,omitempty"`
Ru string `json:"ru,omitempty"`
Tm string `json:"tm,omitempty"`
}
func NormalizeLang(lang string) string {
switch strings.ToLower(strings.TrimSpace(lang)) {
case "ru", "en", "tm":
return strings.ToLower(strings.TrimSpace(lang))
default:
return "tm"
}
}
func (l Language) Pick(lang string) string {
switch NormalizeLang(lang) {
case "ru":
if l.Ru != "" {
return l.Ru
}
case "en":
if l.En != "" {
return l.En
}
}
if l.Tm != "" {
return l.Tm
}
if l.Ru != "" {
return l.Ru
}
return l.En
}
func PickContent(lang, tm, ru, en string) string {
switch NormalizeLang(lang) {
case "ru":
if ru != "" {
return ru
}
case "en":
if en != "" {
return en
}
}
if tm != "" {
return tm
}
if ru != "" {
return ru
}
return en
}
type CategoryDTO struct {
Id int `json:"id"`
Name Language `json:"name"`
Image string `json:"imagePath"`
Name string `json:"name"`
Image string `json:"imagePath,omitempty"`
SubCategories []SubCategoryDTO `json:"subCategories"`
}
type SubCategoryDTO struct {
Id int `json:"id"`
CategoryId int `json:"categoryId"`
Name Language `json:"name"`
Content Language `json:"content"`
Count int `json:"count"`
Id int `json:"id"`
CategoryId int `json:"categoryId"`
Name string `json:"name"`
Content string `json:"content,omitempty"`
Count int `json:"count,omitempty"`
}
type DataBannerDTO struct {
@@ -48,12 +101,10 @@ type BannerListItemDTO struct {
type BannerDTO struct {
Id int `json:"id"`
Title Language `json:"title"`
ContentTm string `json:"contentTm"`
ContentRu string `json:"contentRu"`
ContentEn string `json:"contentEn"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
Image string `json:"imagePath"`
CreatedAt time.Time `json:"createdAt"`
CreatedAt time.Time `json:"createdAt,omitzero"`
}
type DataStaticDTO struct {
@@ -64,26 +115,24 @@ type DataStaticDTO struct {
type StaticDTO struct {
Id int `json:"id"`
Logo string `json:"logo"`
Title Language `json:"title"`
ContentTm string `json:"contentTm"`
ContentRu string `json:"contentRu"`
ContentEn string `json:"contentEn"`
CreatedAt time.Time `json:"createdAt"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
CreatedAt time.Time `json:"createdAt,omitzero"`
}
type CurrencyDTO struct {
Id int `json:"id"`
Title Language `json:"title"`
Content Language `json:"content"`
Path string `json:"path"`
CreatedAt time.Time `json:"createdAt"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
Path string `json:"path,omitempty"`
CreatedAt time.Time `json:"createdAt,omitzero"`
}
type SettingDTO struct {
UUID string `json:"UUID"`
UUID string `json:"UUID,omitempty"`
LogoR string `json:"logoR"`
PhoneNumber string `json:"phoneNumber"`
FaxNumber string `json:"faxNumber"`
HelpNumber string `json:"helpNumber"`
CreatedAt time.Time `json:"createdAt"`
CreatedAt time.Time `json:"createdAt,omitzero"`
}