refactor: support i18n
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
"cs-agent/internal/pkg/dto/response"
|
||||
"cs-agent/internal/pkg/httpx"
|
||||
"cs-agent/internal/pkg/i18nx"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
@@ -39,7 +40,7 @@ func ConversationGetBy(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
detail := response.ConversationDetailResponse{
|
||||
ConversationResponse: builders.BuildConversation(item),
|
||||
ConversationResponse: builders.BuildConversationWithLocale(item, i18nx.Locale(ctx)),
|
||||
Participants: builders.BuildParticipantResponses(id),
|
||||
}
|
||||
httpx.WriteJSON(ctx, detail)
|
||||
@@ -62,7 +63,7 @@ func ConversationPostCreate_or_match(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(ctx, builders.BuildConversation(item))
|
||||
httpx.WriteJSON(ctx, builders.BuildConversationWithLocale(item, i18nx.Locale(ctx)))
|
||||
}
|
||||
|
||||
func ConversationPostClose(ctx *gin.Context) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
"cs-agent/internal/pkg/enums"
|
||||
"cs-agent/internal/pkg/httpx"
|
||||
"cs-agent/internal/pkg/i18nx"
|
||||
"cs-agent/internal/services"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -51,7 +52,7 @@ func MessageAnyList(ctx *gin.Context) {
|
||||
list, nextCursor, hasMore := services.MessageService.FindByConversationIDCursor(
|
||||
conversationID, cursor, limit, senderType, messageType,
|
||||
)
|
||||
results := builders.BuildMessages(list)
|
||||
results := builders.BuildMessagesWithLocale(list, i18nx.Locale(ctx))
|
||||
httpx.WriteJSON(ctx, httpx.CursorData(results, cast.ToString(nextCursor), hasMore))
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ func MessagePostSend(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(ctx, builders.BuildMessage(item))
|
||||
httpx.WriteJSON(ctx, builders.BuildMessageWithLocale(item, i18nx.Locale(ctx)))
|
||||
}
|
||||
|
||||
func MessagePostRead(ctx *gin.Context) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
"cs-agent/internal/pkg/dto/response"
|
||||
"cs-agent/internal/pkg/enums"
|
||||
"cs-agent/internal/pkg/i18nx"
|
||||
"cs-agent/internal/pkg/toolx"
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/services"
|
||||
@@ -34,7 +35,7 @@ func AIAgentAnyList(ctx *gin.Context) {
|
||||
list, paging := services.AIAgentService.FindPageByCnd(cnd)
|
||||
results := make([]response.AIAgentResponse, 0, len(list))
|
||||
for _, item := range list {
|
||||
results = append(results, buildAIAgentResponse(&item))
|
||||
results = append(results, buildAIAgentResponseWithLocale(&item, i18nx.Locale(ctx)))
|
||||
}
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
@@ -47,7 +48,7 @@ func AIAgentGetList_all(ctx *gin.Context) {
|
||||
list := services.AIAgentService.Find(sqls.NewCnd().Where("status = ?", enums.StatusOk).Desc("sort_no").Desc("id"))
|
||||
results := make([]response.AIAgentResponse, 0, len(list))
|
||||
for _, item := range list {
|
||||
results = append(results, buildAIAgentResponse(&item))
|
||||
results = append(results, buildAIAgentResponseWithLocale(&item, i18nx.Locale(ctx)))
|
||||
}
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
@@ -66,7 +67,7 @@ func AIAgentGetBy(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, web.JsonErrorMsg("AI Agent 不存在"))
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(ctx, buildAIAgentResponse(item))
|
||||
httpx.WriteJSON(ctx, buildAIAgentResponseWithLocale(item, i18nx.Locale(ctx)))
|
||||
}
|
||||
|
||||
func AIAgentPostCreate(ctx *gin.Context) {
|
||||
@@ -85,7 +86,7 @@ func AIAgentPostCreate(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(ctx, buildAIAgentResponse(item))
|
||||
httpx.WriteJSON(ctx, buildAIAgentResponseWithLocale(item, i18nx.Locale(ctx)))
|
||||
}
|
||||
|
||||
func AIAgentPostUpdate(ctx *gin.Context) {
|
||||
@@ -160,6 +161,10 @@ func AIAgentPostUpdate_status(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func buildAIAgentResponse(item *models.AIAgent) response.AIAgentResponse {
|
||||
return buildAIAgentResponseWithLocale(item, i18nx.LocaleZhCN)
|
||||
}
|
||||
|
||||
func buildAIAgentResponseWithLocale(item *models.AIAgent, locale string) response.AIAgentResponse {
|
||||
ret := response.AIAgentResponse{
|
||||
ID: item.ID,
|
||||
Name: item.Name,
|
||||
@@ -242,13 +247,13 @@ func buildAIAgentResponse(item *models.AIAgent) response.AIAgentResponse {
|
||||
}
|
||||
title := strings.TrimSpace(tool.Title)
|
||||
if title == "" {
|
||||
if registeredTitle := toolx.GetRegisteredToolTitle(toolCode); registeredTitle != "" {
|
||||
if registeredTitle := toolx.GetRegisteredToolTitleLocale(toolCode, locale); registeredTitle != "" {
|
||||
title = registeredTitle
|
||||
}
|
||||
}
|
||||
description := strings.TrimSpace(tool.Description)
|
||||
if description == "" {
|
||||
if registeredDescription := toolx.GetRegisteredToolDescription(toolCode); registeredDescription != "" {
|
||||
if registeredDescription := toolx.GetRegisteredToolDescriptionLocale(toolCode, locale); registeredDescription != "" {
|
||||
description = registeredDescription
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"cs-agent/internal/pkg/dto/response"
|
||||
"cs-agent/internal/pkg/enums"
|
||||
"cs-agent/internal/pkg/httpx"
|
||||
"cs-agent/internal/pkg/i18nx"
|
||||
"cs-agent/internal/services"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -65,7 +66,7 @@ func ConversationAnyList(ctx *gin.Context) {
|
||||
list, paging := services.ConversationService.FindPageByCnd(cnd)
|
||||
results := make([]response.ConversationResponse, 0, len(list))
|
||||
for _, item := range list {
|
||||
results = append(results, builders.BuildConversation(&item))
|
||||
results = append(results, builders.BuildConversationWithLocale(&item, i18nx.Locale(ctx)))
|
||||
}
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
@@ -94,7 +95,7 @@ func ConversationAnyConversations(ctx *gin.Context) {
|
||||
|
||||
results := make([]response.ConversationResponse, 0, len(list))
|
||||
for _, item := range list {
|
||||
results = append(results, builders.BuildConversation(&item))
|
||||
results = append(results, builders.BuildConversationWithLocale(&item, i18nx.Locale(ctx)))
|
||||
}
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
@@ -116,7 +117,7 @@ func ConversationGetBy(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
detail := response.ConversationDetailResponse{
|
||||
ConversationResponse: builders.BuildConversation(item),
|
||||
ConversationResponse: builders.BuildConversationWithLocale(item, i18nx.Locale(ctx)),
|
||||
Participants: builders.BuildParticipantResponses(id),
|
||||
}
|
||||
httpx.WriteJSON(ctx, detail)
|
||||
@@ -143,7 +144,7 @@ func ConversationAnyMessage_list(ctx *gin.Context) {
|
||||
list, nextCursor, hasMore := services.MessageService.FindByConversationIDCursor(
|
||||
conversationID, cursor, limit, senderType, messageType,
|
||||
)
|
||||
results := builders.BuildMessages(list)
|
||||
results := builders.BuildMessagesWithLocale(list, i18nx.Locale(ctx))
|
||||
|
||||
httpx.WriteJSON(ctx, httpx.CursorData(results, cast.ToString(nextCursor), hasMore))
|
||||
}
|
||||
@@ -259,7 +260,7 @@ func ConversationPostSend_message(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(ctx, builders.BuildMessage(item))
|
||||
httpx.WriteJSON(ctx, builders.BuildMessageWithLocale(item, i18nx.Locale(ctx)))
|
||||
}
|
||||
|
||||
func ConversationPostRecall_message(ctx *gin.Context) {
|
||||
@@ -279,7 +280,7 @@ func ConversationPostRecall_message(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(ctx, builders.BuildMessage(item))
|
||||
httpx.WriteJSON(ctx, builders.BuildMessageWithLocale(item, i18nx.Locale(ctx)))
|
||||
}
|
||||
|
||||
func ConversationPostRead(ctx *gin.Context) {
|
||||
|
||||
@@ -5,11 +5,12 @@ import (
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"cs-agent/internal/pkg/i18nx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func DashboardGetOverview(ctx *gin.Context) {
|
||||
rangeValue, _ := params.Get(ctx, "range")
|
||||
httpx.WriteJSON(ctx, services.DashboardService.GetOverview(rangeValue))
|
||||
httpx.WriteJSON(ctx, services.DashboardService.GetOverview(rangeValue, i18nx.Locale(ctx)))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"cs-agent/internal/pkg/constants"
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
"cs-agent/internal/pkg/dto/response"
|
||||
"cs-agent/internal/pkg/i18nx"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
@@ -27,7 +28,7 @@ func MCPAnyCatalog(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
}
|
||||
items, err := services.ToolCatalogService.ListMCPTools(context.Background())
|
||||
items, err := services.ToolCatalogService.ListMCPToolsWithLocale(context.Background(), i18nx.Locale(ctx))
|
||||
if err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"cs-agent/internal/pkg/i18nx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
@@ -39,7 +40,7 @@ func NotificationAnyList(ctx *gin.Context) {
|
||||
|
||||
list, paging := services.NotificationService.FindPageByCnd(cnd)
|
||||
httpx.WriteJSON(ctx, &web.PageResult{
|
||||
Results: builders.BuildNotificationList(list),
|
||||
Results: builders.BuildNotificationListWithLocale(list, i18nx.Locale(ctx)),
|
||||
Page: paging,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user