Skip to content

Commit

Permalink
Add i18n content, issue stream, contribution (#3958)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuofan authored Jan 26, 2022
1 parent aff8d2a commit 5a4ecb0
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 25 deletions.
33 changes: 33 additions & 0 deletions apistructs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ func (i IssuePriority) GetZhName() string {
}
}

func IssueStreamPriorityName(priority, locale string) string {
if len(priority) == 0 {
return ""
}
c := IssuePriorityUrgent.GetEnName(priority)
if strings.Contains(locale, "en") {
return strings.ToLower(string(c))
}
return c.GetZhName()
}

// IssueComplexity 事件复杂度
type IssueComplexity string

Expand Down Expand Up @@ -405,6 +416,17 @@ func (is IssueComplexity) GetZhName() string {
}
}

func IssueStreamComplexityName(complexity, locale string) string {
if len(complexity) == 0 {
return ""
}
c := IssueComplexityHard.GetEnName(complexity)
if strings.Contains(locale, "en") {
return strings.ToLower(string(c))
}
return c.GetZhName()
}

// IssueSeverity 事件严重程度
type IssueSeverity string

Expand Down Expand Up @@ -457,6 +479,17 @@ func (is IssueSeverity) GetI18nKeyAlias() string {
return strings.ToLower(string(is))
}

func IssueStreamSeverityName(severity, locale string) string {
if len(severity) == 0 {
return ""
}
c := IssueSeverityFatal.GetEnName(severity)
if strings.Contains(locale, "en") {
return strings.ToLower(string(c))
}
return c.GetZhName()
}

var IssueSeveritys = []IssueSeverity{IssueSeverityFatal, IssueSeveritySerious, IssueSeverityNormal, IssueSeveritySlight, IssueSeverityLow}

// IssueButton 状态流转按钮
Expand Down
10 changes: 8 additions & 2 deletions apistructs/issue_stream_locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ func (p *ISTParam) Localize(locale string) *ISTParam {
//p.CurrentState = IssueState(p.CurrentState).Desc(locale)
//
//// NewStatue
//p.NewState = IssueState(p.NewState).Desc(locale)

// p.NewState = IssueState(p.NewState).Desc(locale)

p.CurrentComplexity = IssueStreamComplexityName(p.CurrentComplexity, locale)
p.NewComplexity = IssueStreamComplexityName(p.NewComplexity, locale)
p.CurrentSeverity = IssueStreamSeverityName(p.CurrentSeverity, locale)
p.NewSeverity = IssueStreamSeverityName(p.NewSeverity, locale)
p.CurrentPriority = IssueStreamPriorityName(p.CurrentPriority, locale)
p.NewPriority = IssueStreamPriorityName(p.NewPriority, locale)
return p
}
1 change: 1 addition & 0 deletions conf/dop/dop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ i18n:
- conf/dop/i18n/issue-manage.yaml
- conf/dop/i18n/project-pipeline.yaml
- conf/dop/i18n/api-management-trans.yaml
- conf/dop/i18n/contribution.yaml
mysql:
host: "${MYSQL_HOST}"
port: "${MYSQL_PORT}"
Expand Down
8 changes: 8 additions & 0 deletions conf/dop/i18n/contribution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
zh:
coordination: 协同
code: 代码
quality: 质量
en:
coordination: Coordination
code: Code
quality: Quality
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (a *ComponentFileFormModal) GetScene(inParams fileTree.InParams) error {
Rules: []Rule{
{
Pattern: `/^[a-z\u4e00-\u9fa5A-Z0-9_-]*$/`,
Msg: "可输入中文、英文、数字、中划线或下划线",
Msg: a.sdk.I18n("sceneSetRuleMessage"),
},
},
ComponentProps: ComponentProps{
Expand All @@ -402,15 +402,15 @@ func (a *ComponentFileFormModal) GetScene(inParams fileTree.InParams) error {
Placeholder: a.sdk.I18n("referPolicyPlace"),
Options: []interface{}{
PolicyOption{
apistructs.NewRunPolicyType.GetZhName(),
a.sdk.I18n("new-run"),
apistructs.NewRunPolicyType,
},
PolicyOption{
apistructs.TryLatestSuccessResultPolicyType.GetZhName(),
a.sdk.I18n("try-latest-success-result"),
apistructs.TryLatestSuccessResultPolicyType,
},
PolicyOption{
apistructs.TryLatestResultPolicyType.GetZhName(),
a.sdk.I18n("try-latest-result"),
apistructs.TryLatestResultPolicyType,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/providers/component-protocol/cpregister/base"
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda-infra/providers/component-protocol/utils/cputil"
)

type ComponentAction struct {
Expand Down Expand Up @@ -68,17 +69,17 @@ func (ca *ComponentAction) Render(ctx context.Context, c *cptype.Component, scen
}
ca.State.Conditions = []interface{}{
map[string]interface{}{
"emptyText": "全部",
"emptyText": cputil.I18n(ctx, "all"),
"fixed": true,
"key": "type",
"label": "类型",
"label": cputil.I18n(ctx, "type"),
"options": []interface{}{
map[string]interface{}{
"label": "导入",
"label": cputil.I18n(ctx, "import"),
"value": "import",
},
map[string]interface{}{
"label": "导出",
"label": cputil.I18n(ctx, "export"),
"value": "export",
},
},
Expand Down
3 changes: 3 additions & 0 deletions modules/dop/providers/contribution/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/erda-project/erda-infra/base/logs"
"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/pkg/transport"
"github.com/erda-project/erda-infra/providers/i18n"
"github.com/erda-project/erda-proto-go/dop/contribution/pb"
"github.com/erda-project/erda/modules/dop/dao"
"github.com/erda-project/erda/pkg/common/apis"
Expand All @@ -34,6 +35,7 @@ type provider struct {
Log logs.Logger
Register transport.Register `autowired:"service-register" required:"true"`
DB *gorm.DB `autowired:"mysql-client"`
I18n i18n.Translator `autowired:"i18n" translator:"contribution"`

contributionService pb.ContributionServiceServer
}
Expand All @@ -46,6 +48,7 @@ func (p *provider) Init(ctx servicehub.Context) error {
},
},
logger: p.Log,
i18n: p.I18n,
}

if p.Register != nil {
Expand Down
8 changes: 5 additions & 3 deletions modules/dop/providers/contribution/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/erda-project/erda-infra/base/logs"
"github.com/erda-project/erda-infra/providers/i18n"
"github.com/erda-project/erda-proto-go/dop/contribution/pb"
"github.com/erda-project/erda/modules/dop/dao"
"github.com/erda-project/erda/pkg/common/apis"
Expand All @@ -27,6 +28,7 @@ import (
type contributionService struct {
logger logs.Logger
db *dao.DBClient
i18n i18n.Translator
}

func (s *contributionService) GetPersonalContribution(ctx context.Context, req *pb.GetPersonalContributionRequest) (*pb.GetPersonalContributionResponse, error) {
Expand All @@ -53,13 +55,13 @@ func (s *contributionService) GetPersonalContribution(ctx context.Context, req *
if pivot == 0 {
pivot = 1
}
lang := apis.Language(ctx)
indicator := &pb.Indicator{
Data: []*pb.IndicatorData{
{Data: []uint64{data.Data.Events, data.Data.Commits, data.Data.Cases}},
},
Max: []uint64{pivot, pivot, pivot},
// TODO i18n
Title: []string{"协同", "代码", "质量"},
Max: []uint64{pivot, pivot, pivot},
Title: []string{s.i18n.Text(lang, "coordination"), s.i18n.Text(lang, "code"), s.i18n.Text(lang, "quality")},
}
data.Indicators = indicator
return &pb.GetPersonalContributionResponse{Data: data}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/erda-project/erda/apistructs"
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
"github.com/erda-project/erda/pkg/i18n"
)

// SetCtxBundle 设置bundle
Expand Down Expand Up @@ -56,7 +57,7 @@ func (i *ComponentFilter) GenComponentState(c *apistructs.Component) error {
return nil
}

func (i *ComponentFilter) SetComponentValue() {
func (i *ComponentFilter) SetComponentValue(locale *i18n.LocaleResource) {
i.Props = Props{
Delay: 1000,
}
Expand All @@ -69,11 +70,9 @@ func (i *ComponentFilter) SetComponentValue() {
i.State.Conditions = []StateConditions{
{
Key: "title",
Label: "标题",
EmptyText: "全部",
Fixed: true,
ShowIndex: 2,
Placeholder: "搜索",
Placeholder: locale.Get("search"),
Type: "input",
},
}
Expand Down Expand Up @@ -102,6 +101,7 @@ func (i *ComponentFilter) Render(ctx context.Context, c *apistructs.Component, _
if err = i.SetCtxBundle(bdl); err != nil {
return
}
i18nLocale := i.ctxBdl.Bdl.GetLocale(i.ctxBdl.Locale)
if err = i.GenComponentState(c); err != nil {
return
}
Expand All @@ -111,7 +111,7 @@ func (i *ComponentFilter) Render(ctx context.Context, c *apistructs.Component, _
i.State.IsFirstFilter = true
}

i.SetComponentValue()
i.SetComponentValue(i18nLocale)

if err := i.RenderProtocol(c, gs); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/erda-project/erda/apistructs"
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
"github.com/erda-project/erda/pkg/i18n"
)

// SetCtxBundle 设置bundle
Expand Down Expand Up @@ -56,7 +57,7 @@ func (i *ComponentFilter) GenComponentState(c *apistructs.Component) error {
return nil
}

func (i *ComponentFilter) SetComponentValue() {
func (i *ComponentFilter) SetComponentValue(locale *i18n.LocaleResource) {
i.Props = Props{
Delay: 1000,
Visible: true,
Expand All @@ -73,11 +74,9 @@ func (i *ComponentFilter) SetComponentValue() {
i.State.Conditions = []StateConditions{
{
Key: "title",
Label: "标题",
EmptyText: "全部",
Fixed: true,
ShowIndex: 2,
Placeholder: "搜索",
Placeholder: locale.Get("search"),
Type: "input",
},
}
Expand Down Expand Up @@ -106,6 +105,7 @@ func (i *ComponentFilter) Render(ctx context.Context, c *apistructs.Component, _
if err = i.SetCtxBundle(bdl); err != nil {
return
}
i18nLocale := i.ctxBdl.Bdl.GetLocale(i.ctxBdl.Locale)
if err = i.GenComponentState(c); err != nil {
return
}
Expand All @@ -115,7 +115,7 @@ func (i *ComponentFilter) Render(ctx context.Context, c *apistructs.Component, _
i.State.IsFirstFilter = true
}

i.SetComponentValue()
i.SetComponentValue(i18nLocale)

if err := i.RenderProtocol(c, gs); err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions pkg/erda-configs/i18n/project_list_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"exitProject": "退出",
"exitProjectConfirm": "退出当前项目后,将不再有项目协作权限,如要再次加入需要项目管理员邀请,请确认是否退出?",
"applyDeploy": "申请部署",
"blockMessage": "企业处于封网期间,生产环境禁止部署!"
"blockMessage": "企业处于封网期间,生产环境禁止部署!",
"search": "搜索"
},
"en-US": {
"project.list.all.project.public": "Public project",
Expand All @@ -33,6 +34,7 @@
"exitProject": "Exit",
"exitProjectConfirm": "After exiting the current project, you will no longer have project collaboration permission. If you want to join again, you need to be invited by the project administrator. Are you sure you want to exit?",
"applyDeploy": "Apply for deployment",
"blockMessage": "The production environment is prohibited from deployment when the enterprise is blocked!"
"blockMessage": "The production environment is prohibited from deployment when the enterprise is blocked!",
"search": "Search"
}
}

0 comments on commit 5a4ecb0

Please sign in to comment.