Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(badge): fixed badge description translation

kumfobd7a8c0368b6
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index d18355e3..537ece84 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -265,7 +265,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
eventRuleRepo := badge.NewEventRuleRepo(dataData)
badgeAwardService := badge2.NewBadgeAwardService(badgeAwardRepo, badgeRepo, userCommon, objService, notificationQueueService)
badgeEventService := badge2.NewBadgeEventService(dataData, eventQueueService, badgeRepo, eventRuleRepo, badgeAwardService)
- badgeService := badge2.NewBadgeService(badgeRepo, badgeGroupRepo, badgeAwardRepo, badgeEventService)
+ badgeService := badge2.NewBadgeService(badgeRepo, badgeGroupRepo, badgeAwardRepo, badgeEventService, siteInfoCommonService)
badgeController := controller.NewBadgeController(badgeService, badgeAwardService)
controller_adminBadgeController := controller_admin.NewBadgeController(badgeService)
answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, userAdminController, reasonController, themeController, siteInfoController, controllerSiteInfoController, notificationController, dashboardController, uploadController, activityController, roleController, pluginController, permissionController, userPluginController, reviewController, metaController, badgeController, controller_adminBadgeController)
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 1a526b1a..96950369 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -539,7 +539,7 @@ backend:
name:
other: Autobiographer
desc:
- other: Filled out <a href="/users/settings/profile" target="_blank">profile</a> information.
+ other: Filled out <a href="{{ .ProfileURL }}" target="_blank">profile</a> information.
certified:
name:
other: Certified
diff --git a/internal/schema/badge_schema.go b/internal/schema/badge_schema.go
index a33fb480..8c934ee2 100644
--- a/internal/schema/badge_schema.go
+++ b/internal/schema/badge_schema.go
@@ -172,20 +172,6 @@ type GetUserBadgeAwardListResp struct {
Level entity.BadgeLevel `json:"level" `
}
-// GetBadgeByIDResp get badge by id response
-type GetBadgeByIDResp struct {
- // badge id
- ID string `json:"id" `
- // badge name
- Name string `json:"name" `
- // badge description
- Description string `json:"description" `
- // badge icon
- Icon string `json:"icon" `
- // badge award count
- AwardCount int `json:"award_count" `
- // badge is single or multiple
- IsSingle bool `json:"is_single" `
- // badge level
- Level entity.BadgeLevel `json:"level" `
+type BadgeTplData struct {
+ ProfileURL string
}
diff --git a/internal/service/badge/badge_service.go b/internal/service/badge/badge_service.go
index faf9b628..029130ad 100644
--- a/internal/service/badge/badge_service.go
+++ b/internal/service/badge/badge_service.go
@@ -26,6 +26,7 @@ import (
"github.com/apache/incubator-answer/internal/base/translator"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
+ "github.com/apache/incubator-answer/internal/service/siteinfo_common"
"github.com/apache/incubator-answer/pkg/converter"
"github.com/apache/incubator-answer/pkg/uid"
"github.com/gin-gonic/gin"
@@ -47,10 +48,11 @@ type BadgeRepo interface {
}
type BadgeService struct {
- badgeRepo BadgeRepo
- badgeGroupRepo BadgeGroupRepo
- badgeAwardRepo BadgeAwardRepo
- badgeEventService *BadgeEventService
+ badgeRepo BadgeRepo
+ badgeGroupRepo BadgeGroupRepo
+ badgeAwardRepo BadgeAwardRepo
+ badgeEventService *BadgeEventService
+ siteInfoCommonService siteinfo_common.SiteInfoCommonService
}
func NewBadgeService(
@@ -58,12 +60,14 @@ func NewBadgeService(
badgeGroupRepo BadgeGroupRepo,
badgeAwardRepo BadgeAwardRepo,
badgeEventService *BadgeEventService,
+ siteInfoCommonService siteinfo_common.SiteInfoCommonService,
) *BadgeService {
return &BadgeService{
- badgeRepo: badgeRepo,
- badgeGroupRepo: badgeGroupRepo,
- badgeAwardRepo: badgeAwardRepo,
- badgeEventService: badgeEventService,
+ badgeRepo: badgeRepo,
+ badgeGroupRepo: badgeGroupRepo,
+ badgeAwardRepo: badgeAwardRepo,
+ badgeEventService: badgeEventService,
+ siteInfoCommonService: siteInfoCommonService,
}
}
@@ -200,11 +204,18 @@ func (b *BadgeService) ListPaged(ctx context.Context, req *schema.GetBadgeListPa
resp = make([]*schema.GetBadgeListPagedResp, len(badges))
+ general, siteErr := b.siteInfoCommonService.GetSiteGeneral(ctx)
+ var baseURL = ""
+ if siteErr != nil {
+ baseURL = ""
+ }
+ baseURL = general.SiteUrl
+
for i, badge := range badges {
resp[i] = &schema.GetBadgeListPagedResp{
ID: uid.EnShortID(badge.ID),
Name: translator.Tr(handler.GetLangByCtx(ctx), badge.Name),
- Description: translator.Tr(handler.GetLangByCtx(ctx), badge.Description),
+ Description: translator.TrWithData(handler.GetLangByCtx(ctx), badge.Description, &schema.BadgeTplData{ProfileURL: baseURL + "/users/settings/profile"}),
Icon: badge.Icon,
AwardCount: badge.AwardCount,
Level: badge.Level,
@@ -253,10 +264,17 @@ func (b *BadgeService) GetBadgeInfo(ctx *gin.Context, id string, userID string)
earnedTotal = b.badgeAwardRepo.CountByUserIdAndBadgeId(ctx, userID, badge.ID)
}
+ general, siteErr := b.siteInfoCommonService.GetSiteGeneral(ctx)
+ var baseURL = ""
+ if siteErr != nil {
+ baseURL = ""
+ }
+ baseURL = general.SiteUrl
+
info = &schema.GetBadgeInfoResp{
ID: uid.EnShortID(badge.ID),
Name: translator.Tr(handler.GetLangByCtx(ctx), badge.Name),
- Description: translator.Tr(handler.GetLangByCtx(ctx), badge.Description),
+ Description: translator.TrWithData(handler.GetLangByCtx(ctx), badge.Description, &schema.BadgeTplData{ProfileURL: baseURL + "/users/settings/profile"}),
Icon: badge.Icon,
AwardCount: badge.AwardCount,
EarnedCount: earnedTotal,