Skip to content

Commit

Permalink
fix(badge): fixed badge description translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kumfo committed Sep 4, 2024
1 parent 2dd4cc4 commit 3c8aa03
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion i18n/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions internal/schema/badge_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
38 changes: 28 additions & 10 deletions internal/service/badge/badge_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -47,23 +48,26 @@ 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(
badgeRepo BadgeRepo,
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,
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3c8aa03

Please sign in to comment.