From b80df42a45731dc7ee70aafa499ddb1d72daca04 Mon Sep 17 00:00:00 2001 From: BugsGuru Date: Wed, 11 Sep 2024 17:44:14 +0800 Subject: [PATCH 1/4] chore change var name --- sqle/model/task.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sqle/model/task.go b/sqle/model/task.go index 9d8c477c6..17adaa4fb 100644 --- a/sqle/model/task.go +++ b/sqle/model/task.go @@ -179,12 +179,12 @@ func (i *I18nAuditResultInfo) GetAuditResultInfoByLangTag(lang language.Tag) *Au return &AuditResultInfo{} } - if ruleInfo, ok := (*i)[lang]; ok { - return &ruleInfo + if info, ok := (*i)[lang]; ok { + return &info } - ruleInfo := (*i)[locale.DefaultLang] - return &ruleInfo + info := (*i)[locale.DefaultLang] + return &info } func (i I18nAuditResultInfo) Value() (driver.Value, error) { From 485ab442d2a7bce13c5f9b6c0536a4cef83261ee Mon Sep 17 00:00:00 2001 From: BugsGuru Date: Wed, 11 Sep 2024 17:45:43 +0800 Subject: [PATCH 2/4] api resp AuditResult with i18n info --- sqle/api/controller/v2/audit_plan.go | 9 +++++---- sqle/api/controller/v2/sql_audit.go | 16 +++++++++------- sqle/api/controller/v2/task.go | 18 ++++++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/sqle/api/controller/v2/audit_plan.go b/sqle/api/controller/v2/audit_plan.go index f4f3aaa15..1322f6b36 100644 --- a/sqle/api/controller/v2/audit_plan.go +++ b/sqle/api/controller/v2/audit_plan.go @@ -226,10 +226,11 @@ func GetAuditPlanReportSQLs(c echo.Context) error { for j := range auditPlanReportSQL.AuditResults { ar := auditPlanReportSQL.AuditResults[j] auditPlanReportSQLsRes[i].AuditResult = append(auditPlanReportSQLsRes[i].AuditResult, &AuditResult{ - Level: ar.Level, - Message: ar.GetAuditMsgByLangTag(lang), - RuleName: ar.RuleName, - DbType: ap.DBType, + Level: ar.Level, + Message: ar.GetAuditMsgByLangTag(lang), + RuleName: ar.RuleName, + DbType: ap.DBType, + I18nAuditResultInfo: ar.I18nAuditResultInfo, }) } } diff --git a/sqle/api/controller/v2/sql_audit.go b/sqle/api/controller/v2/sql_audit.go index f42a32713..dfdd1cb2d 100644 --- a/sqle/api/controller/v2/sql_audit.go +++ b/sqle/api/controller/v2/sql_audit.go @@ -91,10 +91,11 @@ func convertTaskResultToAuditResV2(ctx context.Context, task *model.Task) *Audit ar := make([]*AuditResult, len(sql.AuditResults)) for j := range sql.AuditResults { ar[j] = &AuditResult{ - Level: sql.AuditResults[j].Level, - Message: sql.AuditResults[j].GetAuditMsgByLangTag(lang), - RuleName: sql.AuditResults[j].RuleName, - DbType: task.DBType, + Level: sql.AuditResults[j].Level, + Message: sql.AuditResults[j].GetAuditMsgByLangTag(lang), + RuleName: sql.AuditResults[j].RuleName, + DbType: task.DBType, + I18nAuditResultInfo: sql.AuditResults[j].I18nAuditResultInfo, } } @@ -240,9 +241,10 @@ func convertAuditResultToAuditResV2(ctx context.Context, auditResults model.Audi ar := make([]AuditResult, len(auditResults)) for i := range auditResults { ar[i] = AuditResult{ - Level: auditResults[i].Level, - Message: auditResults[i].GetAuditMsgByLangTag(lang), - RuleName: auditResults[i].RuleName, + Level: auditResults[i].Level, + Message: auditResults[i].GetAuditMsgByLangTag(lang), + RuleName: auditResults[i].RuleName, + I18nAuditResultInfo: auditResults[i].I18nAuditResultInfo, } } return ar diff --git a/sqle/api/controller/v2/task.go b/sqle/api/controller/v2/task.go index 0387eccf4..168e3eb89 100644 --- a/sqle/api/controller/v2/task.go +++ b/sqle/api/controller/v2/task.go @@ -43,10 +43,11 @@ type AuditTaskSQLResV2 struct { } type AuditResult struct { - Level string `json:"level" example:"warn"` - Message string `json:"message" example:"避免使用不必要的内置函数md5()"` - RuleName string `json:"rule_name"` - DbType string `json:"db_type"` + Level string `json:"level" example:"warn"` + Message string `json:"message" example:"避免使用不必要的内置函数md5()"` + RuleName string `json:"rule_name"` + DbType string `json:"db_type"` + I18nAuditResultInfo model.I18nAuditResultInfo `json:"i18n_audit_result_info"` } // @Summary 获取指定扫描任务的SQLs信息 @@ -116,10 +117,11 @@ func GetTaskSQLs(c echo.Context) error { for i := range taskSQL.AuditResults { ar := taskSQL.AuditResults[i] taskSQLRes.AuditResult = append(taskSQLRes.AuditResult, &AuditResult{ - Level: ar.Level, - Message: ar.GetAuditMsgByLangTag(locale.GetLangTagFromCtx(c.Request().Context())), - RuleName: ar.RuleName, - DbType: task.DBType, + Level: ar.Level, + Message: ar.GetAuditMsgByLangTag(locale.GetLangTagFromCtx(c.Request().Context())), + RuleName: ar.RuleName, + DbType: task.DBType, + I18nAuditResultInfo: ar.I18nAuditResultInfo, }) } From abfa54981eaf3df84b7719ce4c4cd3fb60760f1a Mon Sep 17 00:00:00 2001 From: BugsGuru Date: Fri, 13 Sep 2024 14:49:10 +0800 Subject: [PATCH 3/4] i18n analysis TabularDataHead ce --- sqle/api/controller/v1/instance_audit_plan.go | 2 +- sqle/api/controller/v1/sql_manage.go | 11 +- sqle/api/controller/v2/audit_plan.go | 2 +- sqle/api/controller/v2/sql_anaysis_task.go | 12 +- sqle/driver/mysql/analysis.go | 68 ++--- sqle/driver/plugin_adapter_v1.go | 12 +- sqle/driver/plugin_adapter_v2.go | 8 +- sqle/driver/v2/driver_interface.go | 4 +- sqle/driver/v2/proto/driver_v2.pb.go | 281 +++++++++--------- sqle/driver/v2/proto/driver_v2.proto | 1 + sqle/driver/v2/util.go | 60 +++- 11 files changed, 254 insertions(+), 207 deletions(-) diff --git a/sqle/api/controller/v1/instance_audit_plan.go b/sqle/api/controller/v1/instance_audit_plan.go index fc38dd076..97a872b10 100644 --- a/sqle/api/controller/v1/instance_audit_plan.go +++ b/sqle/api/controller/v1/instance_audit_plan.go @@ -1358,7 +1358,7 @@ func GetAuditPlanSqlAnalysisData(c echo.Context) error { return c.JSON(http.StatusOK, &GetSqlManageSqlAnalysisResp{ BaseRes: controller.NewBaseReq(nil), - Data: convertSQLAnalysisResultToRes(res, originSQL.SqlText), + Data: convertSQLAnalysisResultToRes(c.Request().Context(), res, originSQL.SqlText), }) } diff --git a/sqle/api/controller/v1/sql_manage.go b/sqle/api/controller/v1/sql_manage.go index b789dded8..98fc19df2 100644 --- a/sqle/api/controller/v1/sql_manage.go +++ b/sqle/api/controller/v1/sql_manage.go @@ -1,7 +1,10 @@ package v1 import ( + "context" + "github.com/actiontech/sqle/sqle/api/controller" + "github.com/actiontech/sqle/sqle/locale" "github.com/labstack/echo/v4" ) @@ -233,7 +236,7 @@ func GetSqlManageSqlAnalysisV1(c echo.Context) error { return getSqlManageSqlAnalysisV1(c) } -func convertSQLAnalysisResultToRes(res *AnalysisResult, rawSQL string) *SqlAnalysis { +func convertSQLAnalysisResultToRes(ctx context.Context, res *AnalysisResult, rawSQL string) *SqlAnalysis { data := &SqlAnalysis{} // explain @@ -251,7 +254,7 @@ func convertSQLAnalysisResultToRes(res *AnalysisResult, rawSQL string) *SqlAnaly for i := range res.ExplainResult.ClassicResult.Columns { col := res.ExplainResult.ClassicResult.Columns[i] classicResult.Head[i].FieldName = col.Name - classicResult.Head[i].Desc = col.Desc + classicResult.Head[i].Desc = col.I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)) } // rows @@ -293,7 +296,7 @@ func convertSQLAnalysisResultToRes(res *AnalysisResult, rawSQL string) *SqlAnaly for j := range tableMetaColumnsInfo.Columns { col := tableMetaColumnsInfo.Columns[j] tableMetaColumnData.Head[j].FieldName = col.Name - tableMetaColumnData.Head[j].Desc = col.Desc + tableMetaColumnData.Head[j].Desc = col.I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)) } for j := range tableMetaColumnsInfo.Rows { @@ -307,7 +310,7 @@ func convertSQLAnalysisResultToRes(res *AnalysisResult, rawSQL string) *SqlAnaly tableMetaIndexData := tableMetaItemsData[i].Indexes for j := range tableMetaIndexInfo.Columns { tableMetaIndexData.Head[j].FieldName = tableMetaIndexInfo.Columns[j].Name - tableMetaIndexData.Head[j].Desc = tableMetaIndexInfo.Columns[j].Desc + tableMetaIndexData.Head[j].Desc = tableMetaIndexInfo.Columns[j].I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)) } for j := range tableMetaIndexInfo.Rows { diff --git a/sqle/api/controller/v2/audit_plan.go b/sqle/api/controller/v2/audit_plan.go index 1322f6b36..94dca87e1 100644 --- a/sqle/api/controller/v2/audit_plan.go +++ b/sqle/api/controller/v2/audit_plan.go @@ -297,7 +297,7 @@ func GetAuditPlanAnalysisData(c echo.Context) error { return c.JSON(http.StatusOK, &GetAuditPlanAnalysisDataResV2{ BaseRes: controller.NewBaseReq(nil), - Data: convertSQLAnalysisResultToRes(res, auditPlanReportSQLV2.SQL), + Data: convertSQLAnalysisResultToRes(c.Request().Context(), res, auditPlanReportSQLV2.SQL), }) } diff --git a/sqle/api/controller/v2/sql_anaysis_task.go b/sqle/api/controller/v2/sql_anaysis_task.go index 6229df540..33429cbbf 100644 --- a/sqle/api/controller/v2/sql_anaysis_task.go +++ b/sqle/api/controller/v2/sql_anaysis_task.go @@ -1,6 +1,7 @@ package v2 import ( + "context" "fmt" "net/http" "strings" @@ -14,6 +15,7 @@ import ( "github.com/actiontech/sqle/sqle/driver/mysql/session" "github.com/actiontech/sqle/sqle/driver/mysql/util" "github.com/actiontech/sqle/sqle/errors" + "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/log" "github.com/actiontech/sqle/sqle/model" "github.com/pingcap/parser/format" @@ -67,11 +69,11 @@ func getTaskAnalysisData(c echo.Context) error { return c.JSON(http.StatusOK, &GetTaskAnalysisDataResV2{ BaseRes: controller.NewBaseReq(nil), - Data: convertSQLAnalysisResultToRes(res, taskSql.Content), + Data: convertSQLAnalysisResultToRes(c.Request().Context(), res, taskSql.Content), }) } -func convertSQLAnalysisResultToRes(res *v1.AnalysisResult, rawSQL string) *TaskAnalysisDataV2 { +func convertSQLAnalysisResultToRes(ctx context.Context, res *v1.AnalysisResult, rawSQL string) *TaskAnalysisDataV2 { data := &TaskAnalysisDataV2{} @@ -90,7 +92,7 @@ func convertSQLAnalysisResultToRes(res *v1.AnalysisResult, rawSQL string) *TaskA for i := range res.ExplainResult.ClassicResult.Columns { col := res.ExplainResult.ClassicResult.Columns[i] classicResult.Head[i].FieldName = col.Name - classicResult.Head[i].Desc = col.Desc + classicResult.Head[i].Desc = col.I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)) } // rows @@ -132,7 +134,7 @@ func convertSQLAnalysisResultToRes(res *v1.AnalysisResult, rawSQL string) *TaskA for j := range tableMetaColumnsInfo.Columns { col := tableMetaColumnsInfo.Columns[j] tableMetaColumnData.Head[j].FieldName = col.Name - tableMetaColumnData.Head[j].Desc = col.Desc + tableMetaColumnData.Head[j].Desc = col.I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)) } for j := range tableMetaColumnsInfo.Rows { @@ -146,7 +148,7 @@ func convertSQLAnalysisResultToRes(res *v1.AnalysisResult, rawSQL string) *TaskA tableMetaIndexData := tableMetaItemsData[i].Indexes for j := range tableMetaIndexInfo.Columns { tableMetaIndexData.Head[j].FieldName = tableMetaIndexInfo.Columns[j].Name - tableMetaIndexData.Head[j].Desc = tableMetaIndexInfo.Columns[j].Desc + tableMetaIndexData.Head[j].Desc = tableMetaIndexInfo.Columns[j].I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)) } for j := range tableMetaIndexInfo.Rows { diff --git a/sqle/driver/mysql/analysis.go b/sqle/driver/mysql/analysis.go index e6c8fd0fb..bf7da0add 100644 --- a/sqle/driver/mysql/analysis.go +++ b/sqle/driver/mysql/analysis.go @@ -5,11 +5,9 @@ import ( "fmt" "strings" - "github.com/actiontech/sqle/sqle/driver/mysql/plocale" - "golang.org/x/text/language" - "github.com/actiontech/sqle/sqle/driver" "github.com/actiontech/sqle/sqle/driver/mysql/executor" + "github.com/actiontech/sqle/sqle/driver/mysql/plocale" "github.com/actiontech/sqle/sqle/driver/mysql/util" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" "github.com/actiontech/sqle/sqle/utils" @@ -88,29 +86,29 @@ func (i *MysqlDriverImpl) getTableMetaByTableName(ctx context.Context, schema, t func (i *MysqlDriverImpl) getTableColumnsInfo(conn *executor.Executor, schema, tableName string) (driverV2.ColumnsInfo, error) { columns := []driverV2.TabularDataHead{ { - Name: "COLUMN_NAME", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescColumnName), + Name: "COLUMN_NAME", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnName), }, { - Name: "COLUMN_TYPE", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescColumnType), + Name: "COLUMN_TYPE", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnType), }, { - Name: "CHARACTER_SET_NAME", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescCharacterSetName), + Name: "CHARACTER_SET_NAME", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescCharacterSetName), }, { - Name: "IS_NULLABLE", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescIsNullable), + Name: "IS_NULLABLE", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescIsNullable), }, { - Name: "COLUMN_KEY", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescColumnKey), + Name: "COLUMN_KEY", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnKey), }, { - Name: "COLUMN_DEFAULT", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescColumnDefault), + Name: "COLUMN_DEFAULT", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnDefault), }, { - Name: "EXTRA", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescExtra), + Name: "EXTRA", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescExtra), }, { - Name: "COLUMN_COMMENT", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescColumnComment), + Name: "COLUMN_COMMENT", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnComment), }, } @@ -147,31 +145,31 @@ func (i *MysqlDriverImpl) getTableColumnsInfo(conn *executor.Executor, schema, t func (i *MysqlDriverImpl) getTableIndexesInfo(conn *executor.Executor, schema, tableName string) (driverV2.IndexesInfo, error) { columns := []driverV2.TabularDataHead{ { - Name: "Column_name", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescColumnName), + Name: "Column_name", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnName), }, { - Name: "Key_name", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescKeyName), + Name: "Key_name", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescKeyName), }, { // set the row's value as Yes if Non_unique is 0 and No if Non_unique is 1 - Name: "Unique", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescUnique), + Name: "Unique", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescUnique), }, { - Name: "Seq_in_index", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescSeqInIndex), + Name: "Seq_in_index", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescSeqInIndex), }, { - Name: "Cardinality", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescCardinality), + Name: "Cardinality", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescCardinality), }, { // set the row's value as Yes if the column may contain NULL values and No if not - Name: "Null", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescIsNullable), + Name: "Null", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescIsNullable), }, { - Name: "Index_type", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescIndexType), + Name: "Index_type", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescIndexType), }, { - Name: "Comment", - Desc: plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnalysisDescComment), + Name: "Comment", + I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescComment), }, } diff --git a/sqle/driver/plugin_adapter_v1.go b/sqle/driver/plugin_adapter_v1.go index 5489a8a7a..7fe1f9953 100644 --- a/sqle/driver/plugin_adapter_v1.go +++ b/sqle/driver/plugin_adapter_v1.go @@ -263,8 +263,8 @@ func (p *PluginImplV1) Explain(ctx context.Context, conf *driverV2.ExplainConf) columnsV2 := []driverV2.TabularDataHead{} for _, column := range resultV1.ClassicResult.Columns { columnsV2 = append(columnsV2, driverV2.TabularDataHead{ - Name: column.Name, - Desc: column.Desc, + Name: column.Name, + I18nDesc: i18nPkg.ConvertStr2I18nAsDefaultLang(column.Desc), }) } @@ -306,8 +306,8 @@ func (p *PluginImplV1) GetTableMetaBySQL(ctx context.Context, conf *GetTableMeta columnV2 := []driverV2.TabularDataHead{} for _, column := range tm.ColumnsInfo.Columns { columnV2 = append(columnV2, driverV2.TabularDataHead{ - Name: column.Name, - Desc: column.Desc, + Name: column.Name, + I18nDesc: i18nPkg.ConvertStr2I18nAsDefaultLang(column.Desc), }) } tmV2.ColumnsInfo.Columns = columnV2 @@ -316,8 +316,8 @@ func (p *PluginImplV1) GetTableMetaBySQL(ctx context.Context, conf *GetTableMeta indexesColV2 := []driverV2.TabularDataHead{} for _, column := range tm.IndexesInfo.Columns { indexesColV2 = append(indexesColV2, driverV2.TabularDataHead{ - Name: column.Name, - Desc: column.Desc, + Name: column.Name, + I18nDesc: i18nPkg.ConvertStr2I18nAsDefaultLang(column.Desc), }) } diff --git a/sqle/driver/plugin_adapter_v2.go b/sqle/driver/plugin_adapter_v2.go index 102552c4f..4cd06b156 100644 --- a/sqle/driver/plugin_adapter_v2.go +++ b/sqle/driver/plugin_adapter_v2.go @@ -444,9 +444,13 @@ func (s *PluginImplV2) Explain(ctx context.Context, conf *driverV2.ExplainConf) return nil, err } + td, err := driverV2.ConvertProtoTabularDataToDriver(res.ClassicResult.Data) + if err != nil { + return nil, fmt.Errorf("ClassicResult: %w", err) + } return &driverV2.ExplainResult{ ClassicResult: driverV2.ExplainClassicResult{ - TabularData: driverV2.ConvertProtoTabularDataToDriver(res.ClassicResult.Data), + TabularData: td, }, }, nil } @@ -484,7 +488,7 @@ func (s *PluginImplV2) getTableMeta(ctx context.Context, table *driverV2.Table) if err != nil { return nil, err } - return driverV2.ConvertProtoTableMetaToDriver(result.TableMeta), nil + return driverV2.ConvertProtoTableMetaToDriver(result.TableMeta) } func (s *PluginImplV2) extractTableFromSQL(ctx context.Context, sql string) ([]*driverV2.Table, error) { diff --git a/sqle/driver/v2/driver_interface.go b/sqle/driver/v2/driver_interface.go index d66be0360..eefcae103 100644 --- a/sqle/driver/v2/driver_interface.go +++ b/sqle/driver/v2/driver_interface.go @@ -289,8 +289,8 @@ type QueryResultValue struct { | Rows[1][0] | Rows[1][1] | Rows[1][2] | */ type TabularDataHead struct { - Name string - Desc string + Name string + I18nDesc i18nPkg.I18nStr } type TabularData struct { diff --git a/sqle/driver/v2/proto/driver_v2.pb.go b/sqle/driver/v2/proto/driver_v2.pb.go index c40c012eb..922126b43 100644 --- a/sqle/driver/v2/proto/driver_v2.pb.go +++ b/sqle/driver/v2/proto/driver_v2.pb.go @@ -1442,8 +1442,9 @@ func (m *IndexesInfo) GetData() *TabularData { } type TabularDataHead struct { - Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` - Desc string `protobuf:"bytes,2,opt,name=desc" json:"desc,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + Desc string `protobuf:"bytes,2,opt,name=desc" json:"desc,omitempty"` + I18NDesc map[string]string `protobuf:"bytes,3,rep,name=i18nDesc" json:"i18nDesc,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` } func (m *TabularDataHead) Reset() { *m = TabularDataHead{} } @@ -1465,6 +1466,13 @@ func (m *TabularDataHead) GetDesc() string { return "" } +func (m *TabularDataHead) GetI18NDesc() map[string]string { + if m != nil { + return m.I18NDesc + } + return nil +} + type TabularDataRows struct { Items []string `protobuf:"bytes,1,rep,name=items" json:"items,omitempty"` } @@ -2331,139 +2339,140 @@ var _Driver_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("driver_v2.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 2142 bytes of a gzipped FileDescriptorProto + // 2155 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x59, 0x4b, 0x73, 0x13, 0xcb, - 0x15, 0x8e, 0xde, 0xd6, 0x91, 0x64, 0x44, 0xdb, 0x06, 0x21, 0x8c, 0x71, 0x1a, 0xf0, 0x75, 0x01, - 0x57, 0x80, 0x48, 0xb8, 0x3c, 0x52, 0x29, 0x73, 0x6d, 0x07, 0x7c, 0x01, 0xc7, 0xb4, 0x09, 0x8b, - 0x54, 0xdd, 0xe2, 0x8e, 0x35, 0x6d, 0x33, 0xc5, 0x68, 0x46, 0x9e, 0x6e, 0x61, 0x7b, 0x9f, 0xaa, - 0x64, 0x99, 0xbf, 0x90, 0xfc, 0x82, 0x6c, 0xee, 0x32, 0x7f, 0x21, 0xfb, 0xfc, 0x92, 0x6c, 0x53, - 0xfd, 0x98, 0x99, 0xee, 0xd1, 0x88, 0x87, 0x2a, 0x59, 0x69, 0xfa, 0xbc, 0xfa, 0x9c, 0xd3, 0x5f, - 0x9f, 0x3e, 0xdd, 0x82, 0x73, 0x6e, 0xe4, 0x7d, 0xa4, 0xd1, 0xbb, 0x8f, 0xfd, 0xde, 0x28, 0x0a, - 0x79, 0x88, 0x6a, 0xf2, 0xe7, 0x6d, 0x1f, 0xd7, 0xa0, 0xb2, 0x3d, 0x1c, 0xf1, 0x33, 0x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, 0xd3, 0x41, 0x7b, 0x0f, 0xea, 0x52, 0x62, 0x33, - 0x0c, 0x0e, 0xd1, 0x75, 0x68, 0x71, 0x6f, 0x48, 0xc3, 0x31, 0xdf, 0xa7, 0x83, 0x30, 0x50, 0xa0, - 0x6a, 0x11, 0x9b, 0x88, 0xff, 0x5c, 0x80, 0xa6, 0xd4, 0x99, 0x25, 0xe8, 0x6b, 0x26, 0xd2, 0xd3, - 0xb3, 0x39, 0xf6, 0x52, 0x42, 0x1d, 0xad, 0x41, 0x79, 0x10, 0x06, 0x87, 0x12, 0x81, 0x66, 0x1f, - 0x94, 0x78, 0x4a, 0x24, 0x1f, 0xbb, 0xd0, 0xd2, 0x8e, 0x24, 0x65, 0xa0, 0x3a, 0x08, 0xfd, 0xf1, - 0x30, 0xd0, 0xd9, 0x99, 0xb8, 0xb5, 0x29, 0x2e, 0xba, 0x05, 0x65, 0x81, 0x56, 0x9d, 0xfa, 0x8b, - 0xf6, 0x04, 0x3a, 0x89, 0xe1, 0x09, 0x91, 0x42, 0x78, 0x13, 0xe6, 0x6d, 0x3a, 0xba, 0x07, 0x55, - 0x59, 0x94, 0xe2, 0x45, 0xb8, 0x94, 0x67, 0xe0, 0xad, 0x90, 0x20, 0x5a, 0x10, 0xaf, 0x43, 0x3b, - 0xcb, 0x4b, 0x2f, 0xe6, 0x05, 0xe3, 0x62, 0x8e, 0xb1, 0xd8, 0xe6, 0x23, 0xdf, 0xf1, 0x82, 0xe9, - 0xab, 0x36, 0x80, 0x79, 0x2d, 0x33, 0x5b, 0x83, 0x64, 0xac, 0x81, 0x09, 0xa0, 0x78, 0x56, 0x55, - 0x70, 0xde, 0x8a, 0x7d, 0xa5, 0x27, 0xd1, 0xf9, 0xdd, 0x84, 0xd6, 0xc0, 0x77, 0x18, 0xf3, 0x34, - 0xd2, 0xf4, 0x5c, 0x57, 0xb2, 0x36, 0x36, 0x4d, 0x21, 0x62, 0xeb, 0xe0, 0x0d, 0x58, 0xcc, 0x13, - 0x43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0x88, 0x00, 0x3b, 0x55, 0x69, 0xc5, 0xa0, 0xa0, + 0xbb, 0x50, 0xff, 0x10, 0x84, 0x27, 0x3e, 0x75, 0x8f, 0x68, 0xa7, 0xb6, 0x52, 0x58, 0x6b, 0xf4, + 0x50, 0x62, 0xea, 0x45, 0xcc, 0x21, 0xa9, 0x10, 0xda, 0x84, 0xa6, 0x98, 0x5d, 0x91, 0xdf, 0x4e, + 0x70, 0x18, 0x76, 0x66, 0xa4, 0xff, 0x2b, 0x89, 0x92, 0x60, 0x48, 0x38, 0xc4, 0x12, 0x0a, 0x12, + 0x96, 0x52, 0xf7, 0x2d, 0x9c, 0x1b, 0x13, 0xc9, 0x81, 0xc6, 0x2d, 0x13, 0x1a, 0x8d, 0xde, 0x62, + 0xe2, 0xc4, 0x54, 0x36, 0x11, 0xf3, 0xd7, 0x02, 0x34, 0x4d, 0x5e, 0x6e, 0xb5, 0x3f, 0x55, 0xd7, + 0xff, 0x7b, 0xbd, 0xf0, 0x75, 0xa8, 0x27, 0x74, 0xd4, 0x81, 0x5a, 0x3f, 0x0c, 0x38, 0x0d, 0x62, + 0x30, 0xc7, 0x43, 0xfc, 0x53, 0x11, 0x5a, 0xaf, 0x28, 0x77, 0x18, 0xa1, 0x6c, 0x18, 0x06, 0x8c, + 0x8a, 0x50, 0x86, 0xfe, 0xe8, 0xc8, 0x0b, 0x76, 0x53, 0x08, 0x19, 0x14, 0x74, 0x17, 0xe6, 0x63, + 0xb4, 0x6e, 0xd1, 0x43, 0x67, 0xe4, 0xf3, 0xbd, 0x78, 0x41, 0x94, 0x48, 0x1e, 0x0b, 0x7d, 0x0f, + 0x9d, 0x98, 0xfc, 0x24, 0x8b, 0xed, 0x52, 0x2e, 0x8c, 0x26, 0xca, 0xa3, 0xab, 0x50, 0x89, 0x46, + 0x3e, 0x65, 0x9d, 0xb2, 0x54, 0x6c, 0x59, 0xf3, 0x4f, 0x14, 0x0f, 0xbd, 0x82, 0x45, 0x1a, 0x38, + 0x07, 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fe, 0x68, 0x10, + 0xe8, 0xea, 0x8c, 0xdd, 0xda, 0x14, 0x17, 0xdd, 0x82, 0xb2, 0x40, 0xab, 0x2e, 0xfd, 0x05, 0xdb, + 0x81, 0x2e, 0x62, 0x78, 0x42, 0xa4, 0x10, 0xde, 0x84, 0x59, 0x9b, 0x8e, 0xee, 0x41, 0x55, 0x36, + 0xa5, 0x78, 0x12, 0x2e, 0xe6, 0x19, 0x78, 0x2b, 0x24, 0x88, 0x16, 0xc4, 0x6b, 0xd0, 0xce, 0xf2, + 0xd2, 0x8b, 0x79, 0xc1, 0xb8, 0x98, 0x63, 0x2c, 0x96, 0xf9, 0xd0, 0x77, 0xbc, 0x60, 0xf2, 0xac, + 0xf5, 0x61, 0x56, 0xcb, 0x4c, 0x77, 0x40, 0x32, 0xe6, 0xc0, 0x04, 0x50, 0xec, 0x55, 0x35, 0x9c, + 0xb7, 0x62, 0x5d, 0x69, 0x27, 0xba, 0xbe, 0x9b, 0xd0, 0xea, 0xfb, 0x0e, 0x63, 0x9e, 0x46, 0x9a, + 0xf6, 0x75, 0x39, 0x6b, 0x63, 0xd3, 0x14, 0x22, 0xb6, 0x0e, 0xde, 0x80, 0x85, 0x3c, 0x31, 0xb4, + 0x06, 0x65, 0x71, 0x1b, 0x1a, 0x6b, 0xe2, 0x6f, 0x9c, 0x83, 0x91, 0xef, 0x44, 0x5b, 0x0e, 0x77, + 0x88, 0x94, 0xc0, 0x4f, 0x60, 0xfe, 0x19, 0xe5, 0x5b, 0xfa, 0xea, 0x34, 0xd5, 0x41, 0x7e, 0x19, + 0x66, 0x62, 0xfd, 0xbc, 0x57, 0x04, 0xfc, 0x0c, 0x16, 0x6c, 0x17, 0xba, 0x02, 0x77, 0xa0, 0x1e, + 0x5f, 0xd9, 0xe2, 0xd9, 0x4f, 0x51, 0x1c, 0x8b, 0x93, 0x54, 0x06, 0xdf, 0x87, 0xca, 0x1b, 0x71, + 0xd7, 0xca, 0x7d, 0xab, 0x38, 0x0f, 0x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af, 0x3f, 0xc5, 0x37, 0xa7, 0xc8, 0xd8, 0xb0, 0xe3, + 0xfb, 0x49, 0x77, 0xde, 0xa2, 0xa5, 0xe5, 0x95, 0xf8, 0x37, 0xca, 0x6b, 0x9e, 0xef, 0x8d, 0xf2, + 0xda, 0xa7, 0xed, 0xdf, 0x24, 0x8b, 0x05, 0x5d, 0xc8, 0x9e, 0x00, 0xf3, 0x82, 0xb4, 0xcf, 0x92, + 0x2f, 0xe4, 0xea, 0x4a, 0x4e, 0x58, 0x68, 0xc9, 0x28, 0xfd, 0xd8, 0xd9, 0xae, 0x7b, 0x79, 0x02, + 0xd7, 0x32, 0x96, 0x9e, 0x3f, 0x2c, 0x63, 0xd9, 0x73, 0x94, 0x6d, 0x6c, 0xfc, 0xf0, 0xf3, 0x63, + 0xee, 0x2a, 0x47, 0x57, 0xb3, 0xbd, 0x3d, 0x67, 0xe7, 0xe8, 0x5e, 0xfb, 0xb4, 0x90, 0xf6, 0x70, + 0x38, 0xa1, 0x5d, 0xa0, 0xeb, 0xa9, 0xfa, 0x27, 0x9a, 0x77, 0x77, 0xf5, 0x73, 0x62, 0xca, 0xcf, + 0xd3, 0xe6, 0x1f, 0x61, 0xfd, 0xce, 0x63, 0x2d, 0x7b, 0x50, 0x95, 0x1f, 0xf7, 0xff, 0x17, 0x00, + 0x00, 0xff, 0xff, 0x41, 0x6e, 0x4d, 0x7e, 0x06, 0x1d, 0x00, 0x00, } diff --git a/sqle/driver/v2/proto/driver_v2.proto b/sqle/driver/v2/proto/driver_v2.proto index 9acb4554b..b4610d765 100644 --- a/sqle/driver/v2/proto/driver_v2.proto +++ b/sqle/driver/v2/proto/driver_v2.proto @@ -334,6 +334,7 @@ message IndexesInfo { message TabularDataHead { string name = 1; string desc = 2; + map i18nDesc = 3; } message TabularDataRows { diff --git a/sqle/driver/v2/util.go b/sqle/driver/v2/util.go index e6c7992fe..57adafdc0 100644 --- a/sqle/driver/v2/util.go +++ b/sqle/driver/v2/util.go @@ -112,9 +112,9 @@ func ConvertI18nAuditResultFromProtoToDriver(par *protoV2.AuditResult) (*AuditRe locale.DefaultLang: {Message: par.Message}, } } else { - if _, exist := par.I18NAuditResultInfo[locale.DefaultLang.String()]; !exist { - // 多语言的插件 审核结果需包含 locale.DefaultLang - return nil, fmt.Errorf("client audit results must support language: %s", locale.DefaultLang) + if _, exist := par.I18NAuditResultInfo[i18nPkg.DefaultLang.String()]; !exist { + // 多语言的插件 需包含 locale.DefaultLang + return nil, fmt.Errorf("client audit results must support language: %s", i18nPkg.DefaultLang.String()) } } for langTag, ruleInfo := range par.I18NAuditResultInfo { @@ -163,6 +163,7 @@ func ConvertI18nRuleFromProtoToDriver(rule *protoV2.Rule) (*Rule, error) { dRule.I18nRuleInfo[tag] = ConvertI18nRuleInfoFromProtoToDriver(ruleInfo) } if len(rule.I18NRuleInfo) == 0 { + // 对非多语言的插件支持 ruleInfo := &RuleInfo{ Desc: rule.Desc, Annotation: rule.Annotation, @@ -174,6 +175,11 @@ func ConvertI18nRuleFromProtoToDriver(rule *protoV2.Rule) (*Rule, error) { dRule.I18nRuleInfo = I18nRuleInfo{ locale.DefaultLang: ruleInfo, } + } else { + if _, exist := rule.I18NRuleInfo[i18nPkg.DefaultLang.String()]; !exist { + // 多语言的插件 需包含 locale.DefaultLang + return nil, fmt.Errorf("client rule: %s does not support language: %s", rule.Name, i18nPkg.DefaultLang.String()) + } } return dRule, nil } @@ -329,8 +335,9 @@ func ConvertTabularDataToProto(td TabularData) *protoV2.TabularData { columns := make([]*protoV2.TabularDataHead, 0, len(td.Columns)) for _, c := range td.Columns { columns = append(columns, &protoV2.TabularDataHead{ - Name: c.Name, - Desc: c.Desc, + Name: c.Name, + I18NDesc: c.I18nDesc.StrMap(), + Desc: c.I18nDesc.GetStrInLang(i18nPkg.DefaultLang), }) } @@ -347,13 +354,28 @@ func ConvertTabularDataToProto(td TabularData) *protoV2.TabularData { } } -func ConvertProtoTabularDataToDriver(pTd *protoV2.TabularData) TabularData { +func ConvertProtoTabularDataToDriver(pTd *protoV2.TabularData) (TabularData, error) { columns := make([]TabularDataHead, 0, len(pTd.Columns)) for _, c := range pTd.Columns { - columns = append(columns, TabularDataHead{ - Name: c.Name, - Desc: c.Desc, - }) + h := TabularDataHead{ + Name: c.Name, + I18nDesc: nil, + } + if len(c.I18NDesc) > 0 { + if _, exist := c.I18NDesc[i18nPkg.DefaultLang.String()]; !exist { + // 多语言的插件 需包含 locale.DefaultLang + return TabularData{}, fmt.Errorf("client TabularDataHead: %s does not support language: %s", c.Name, i18nPkg.DefaultLang.String()) + } + i18nDesc, err := i18nPkg.ConvertStrMap2I18nStr(c.I18NDesc) + if err != nil { + return TabularData{}, fmt.Errorf("TabularData: %w", err) + } + h.I18nDesc = i18nDesc + } else { + // 对非多语言的插件支持 + h.I18nDesc.SetStrInLang(i18nPkg.DefaultLang, c.Desc) + } + columns = append(columns, h) } rows := make([][]string, 0, len(pTd.Rows)) @@ -364,7 +386,7 @@ func ConvertProtoTabularDataToDriver(pTd *protoV2.TabularData) TabularData { return TabularData{ Columns: columns, Rows: rows, - } + }, nil } func ConvertTableMetaToProto(meta *TableMeta) *protoV2.TableMeta { @@ -375,12 +397,20 @@ func ConvertTableMetaToProto(meta *TableMeta) *protoV2.TableMeta { } } -func ConvertProtoTableMetaToDriver(meta *protoV2.TableMeta) *TableMeta { +func ConvertProtoTableMetaToDriver(meta *protoV2.TableMeta) (*TableMeta, error) { + columnsInfo, err := ConvertProtoTabularDataToDriver(meta.ColumnsInfo.Data) + if err != nil { + return nil, fmt.Errorf("ColumnsInfo: %w", err) + } + indexesInfo, err := ConvertProtoTabularDataToDriver(meta.IndexesInfo.Data) + if err != nil { + return nil, fmt.Errorf("IndexesInfo: %w", err) + } return &TableMeta{ - ColumnsInfo: ColumnsInfo{TabularData: ConvertProtoTabularDataToDriver(meta.ColumnsInfo.Data)}, - IndexesInfo: IndexesInfo{TabularData: ConvertProtoTabularDataToDriver(meta.IndexesInfo.Data)}, + ColumnsInfo: ColumnsInfo{TabularData: columnsInfo}, + IndexesInfo: IndexesInfo{TabularData: indexesInfo}, CreateTableSQL: meta.CreateTableSQL, - } + }, nil } func RandStr(length int) string { From cdd770ab193cd3f366ade96e706a703856a9cc70 Mon Sep 17 00:00:00 2001 From: BugsGuru Date: Fri, 13 Sep 2024 14:53:17 +0800 Subject: [PATCH 4/4] use dms-common/i18nPkg ce --- go.mod | 4 +- go.sum | 4 +- sqle/api/app.go | 4 +- sqle/api/controller/v1/audit_plan.go | 43 ++-- sqle/api/controller/v1/instance_audit_plan.go | 16 +- sqle/api/controller/v1/rule.go | 10 +- sqle/api/controller/v1/sql_audit_record.go | 4 +- sqle/api/controller/v1/statistic.go | 4 +- sqle/api/controller/v1/task.go | 16 +- sqle/api/controller/v1/workflow_ce.go | 2 +- sqle/api/controller/v2/audit_plan.go | 2 +- sqle/api/controller/v2/instance.go | 2 +- sqle/api/controller/v2/sql_audit.go | 4 +- sqle/api/controller/v2/task.go | 2 +- sqle/api/middleware/verify_user.go | 3 +- sqle/dms/common.go | 4 +- sqle/driver/mysql/advisor.go | 21 +- sqle/driver/mysql/advisor_test.go | 20 +- sqle/driver/mysql/analysis.go | 32 +-- sqle/driver/mysql/audit.go | 126 +++++------ sqle/driver/mysql/audit_test.go | 211 +++++++++--------- sqle/driver/mysql/context_test.go | 18 +- sqle/driver/mysql/invalid_offline_test.go | 36 +-- sqle/driver/mysql/mysql.go | 12 +- sqle/driver/mysql/mysql_test.go | 8 +- sqle/driver/mysql/plocale/locale.go | 27 +-- sqle/driver/mysql/pt_osc.go | 10 +- sqle/driver/mysql/pt_osc_test.go | 12 +- sqle/driver/mysql/rollback.go | 40 ++-- sqle/driver/mysql/rollback_test.go | 4 +- sqle/driver/mysql/rule/rule.go | 16 +- sqle/driver/mysql/rule/rule_test.go | 21 +- sqle/driver/plugin_adapter_v1.go | 13 +- sqle/driver/plugin_adapter_v2.go | 9 +- sqle/driver/plugin_interface.go | 2 +- sqle/driver/v1/driver_audit.go | 4 +- sqle/driver/v1/plugin_query.go | 5 +- sqle/driver/v1/proto/util.go | 4 +- sqle/driver/v2/driver_grpc_server.go | 6 +- sqle/driver/v2/driver_interface.go | 11 +- sqle/driver/v2/util.go | 25 +-- sqle/locale/locale.go | 30 +-- sqle/model/operation.go | 14 +- sqle/model/operation_ce.go | 2 +- sqle/model/operation_record.go | 5 +- sqle/model/rule.go | 4 +- sqle/model/task.go | 28 +-- sqle/model/utils.go | 2 +- sqle/pkg/driver/builder.go | 2 +- sqle/pkg/params/params.go | 7 +- sqle/server/audit.go | 2 +- sqle/server/auditplan/task_filter_tips.go | 4 +- sqle/server/auditplan/task_type_default.go | 10 +- .../task_type_mysql_audit_log_ali.go | 10 +- .../auditplan/task_type_mysql_processlist.go | 4 +- .../auditplan/task_type_mysql_schema_meta.go | 6 +- .../auditplan/task_type_mysql_slowlog_ali.go | 10 +- .../task_type_mysql_slowlog_baidu.go | 10 +- .../task_type_mysql_slowlog_huawei.go | 12 +- .../auditplan/task_type_oracle_topsql.go | 6 +- sqle/server/optimization/rule/rule.go | 4 +- sqle/server/pipeline/pipeline.go | 2 +- sqle/server/sqled_test.go | 2 +- .../dms/pkg/dms-common/api/dms/v1/user.go | 6 - .../dms/pkg/dms-common}/i18nPkg/bundle.go | 50 +++-- .../dms/pkg/dms-common}/i18nPkg/i18nStr.go | 4 +- .../dms/pkg/dms-common}/i18nPkg/log.go | 1 - vendor/modules.txt | 3 +- 68 files changed, 499 insertions(+), 558 deletions(-) rename {sqle/pkg => vendor/github.com/actiontech/dms/pkg/dms-common}/i18nPkg/bundle.go (72%) rename {sqle/pkg => vendor/github.com/actiontech/dms/pkg/dms-common}/i18nPkg/i18nStr.go (98%) rename {sqle/pkg => vendor/github.com/actiontech/dms/pkg/dms-common}/i18nPkg/log.go (89%) diff --git a/go.mod b/go.mod index e0e9fe8f8..839916f80 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/Masterminds/semver/v3 v3.1.1 - github.com/actiontech/dms v0.0.0-20240830025931-20d313b918e8 + github.com/actiontech/dms v0.0.0-20240912110939-20f9825907f5 github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62 github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20240806065717-29cde7000ef5 github.com/agiledragon/gomonkey v2.0.2+incompatible @@ -65,7 +65,6 @@ require ( ) require ( - github.com/BurntSushi/toml v1.3.2 github.com/aliyun/credentials-go v1.1.2 github.com/hashicorp/go-version v1.7.0 github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.69 @@ -77,6 +76,7 @@ require ( require ( dario.cat/mergo v1.0.0 // indirect + github.com/BurntSushi/toml v1.3.2 // indirect github.com/KyleBanks/depth v1.2.1 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect diff --git a/go.sum b/go.sum index 5b29c9692..2fbe29c33 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdc github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= -github.com/actiontech/dms v0.0.0-20240830025931-20d313b918e8 h1:l5arXsG/J+z6k72JMy3J2eOXG/S9oJ/saoEpnT5K5Vg= -github.com/actiontech/dms v0.0.0-20240830025931-20d313b918e8/go.mod h1:6puFXgN9RWM/28xTntH++kiNgmCOQbjiYt5K58qmSo0= +github.com/actiontech/dms v0.0.0-20240912110939-20f9825907f5 h1:OyCu5gBcM8G9Pp5kTGXACOO6Tr6Nfp1vFhE6ULQUZKc= +github.com/actiontech/dms v0.0.0-20240912110939-20f9825907f5/go.mod h1:Jm+tDoBYmX8R8zqgPJRq1NwZXdxO/F+HxVRJVF65WXA= github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62 h1:JM7WnLzlvXOGE90KKd+aigi+qUDS+U5dLwQMNpTKZxE= github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62/go.mod h1:adDZHhAf2LRMx2h0JzofPXn12x2XlyQjVE116KXquwo= github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20240806065717-29cde7000ef5 h1:vyQVrkYPzUV9d7gSvOWoezwWMTiC4jc3f3Hpianefq0= diff --git a/sqle/api/app.go b/sqle/api/app.go index 109ee48b1..2f764567c 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -108,9 +108,9 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti }) v1Router := e.Group(apiV1) - v1Router.Use(sqleMiddleware.JWTTokenAdapter(), sqleMiddleware.JWTWithConfig(dmsV1.JwtSigningKey), sqleMiddleware.VerifyUserIsDisabled(), locale.EchoMiddlewareI18nByAcceptLanguage(), sqleMiddleware.OperationLogRecord(), accesstoken.CheckLatestAccessToken(controller.GetDMSServerAddress(), jwtPkg.GetTokenDetailFromContextWithOldJwt)) + v1Router.Use(sqleMiddleware.JWTTokenAdapter(), sqleMiddleware.JWTWithConfig(dmsV1.JwtSigningKey), sqleMiddleware.VerifyUserIsDisabled(), locale.Bundle.EchoMiddlewareByAcceptLanguage(), sqleMiddleware.OperationLogRecord(), accesstoken.CheckLatestAccessToken(controller.GetDMSServerAddress(), jwtPkg.GetTokenDetailFromContextWithOldJwt)) v2Router := e.Group(apiV2) - v2Router.Use(sqleMiddleware.JWTTokenAdapter(), sqleMiddleware.JWTWithConfig(dmsV1.JwtSigningKey), sqleMiddleware.VerifyUserIsDisabled(), locale.EchoMiddlewareI18nByAcceptLanguage(), sqleMiddleware.OperationLogRecord(), accesstoken.CheckLatestAccessToken(controller.GetDMSServerAddress(), jwtPkg.GetTokenDetailFromContextWithOldJwt)) + v2Router.Use(sqleMiddleware.JWTTokenAdapter(), sqleMiddleware.JWTWithConfig(dmsV1.JwtSigningKey), sqleMiddleware.VerifyUserIsDisabled(), locale.Bundle.EchoMiddlewareByAcceptLanguage(), sqleMiddleware.OperationLogRecord(), accesstoken.CheckLatestAccessToken(controller.GetDMSServerAddress(), jwtPkg.GetTokenDetailFromContextWithOldJwt)) // v1 admin api, just admin user can access. { diff --git a/sqle/api/controller/v1/audit_plan.go b/sqle/api/controller/v1/audit_plan.go index 4a5eabd70..66cd24244 100644 --- a/sqle/api/controller/v1/audit_plan.go +++ b/sqle/api/controller/v1/audit_plan.go @@ -13,6 +13,7 @@ import ( v1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" dmsCommonJwt "github.com/actiontech/dms/pkg/dms-common/api/jwt" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/api/controller" "github.com/actiontech/sqle/sqle/common" dms "github.com/actiontech/sqle/sqle/dms" @@ -101,7 +102,7 @@ type Operator struct { func ConvertAuditPlanMetaWithInstanceIdToRes(ctx context.Context, meta auditplan.Meta, instanceId string) AuditPlanMetaV1 { res := AuditPlanMetaV1{ Type: meta.Type, - Desc: locale.ShouldLocalizeMsg(ctx, meta.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc), InstanceType: meta.InstanceType, } if meta.Params != nil && len(meta.Params()) > 0 { @@ -113,7 +114,7 @@ func ConvertAuditPlanMetaWithInstanceIdToRes(ctx context.Context, meta auditplan } paramsRes = append(paramsRes, AuditPlanParamResV1{ Key: p.Key, - Desc: p.GetDesc(locale.GetLangTagFromCtx(ctx)), + Desc: p.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), Type: string(p.Type), Value: val, EnumsValues: ConvertEnumsValuesToRes(ctx, p.Enums), @@ -127,7 +128,7 @@ func ConvertAuditPlanMetaWithInstanceIdToRes(ctx context.Context, meta auditplan for _, hpc := range meta.HighPriorityParams { highPriorityparamsRes = append(highPriorityparamsRes, HighPriorityConditionResV1{ Key: hpc.Key, - Desc: hpc.GetDesc(locale.GetLangTagFromCtx(ctx)), + Desc: hpc.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), Type: string(hpc.Type), Value: hpc.Value, EnumsValues: ConvertEnumsValuesToRes(ctx, hpc.Enums), @@ -145,7 +146,7 @@ func ConvertAuditPlanMetaWithInstanceIdToRes(ctx context.Context, meta auditplan func ConvertAuditPlanMetaToRes(ctx context.Context, meta auditplan.Meta) AuditPlanMetaV1 { res := AuditPlanMetaV1{ Type: meta.Type, - Desc: locale.ShouldLocalizeMsg(ctx, meta.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc), InstanceType: meta.InstanceType, } if meta.Params != nil && len(meta.Params()) > 0 { @@ -157,7 +158,7 @@ func ConvertAuditPlanMetaToRes(ctx context.Context, meta auditplan.Meta) AuditPl } paramRes := AuditPlanParamResV1{ Key: p.Key, - Desc: p.GetDesc(locale.GetLangTagFromCtx(ctx)), + Desc: p.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), Type: string(p.Type), Value: val, EnumsValues: ConvertEnumsValuesToRes(ctx, p.Enums), @@ -182,11 +183,11 @@ func ConvertEnumsValuesToRes(ctx context.Context, ems []params.EnumsValue) []Enu func ConvertEnumsValueToRes(ctx context.Context, ems params.EnumsValue) EnumsValueResV1 { if ems.Desc != "" { - ems.I18nDesc.SetStrInLang(locale.DefaultLang, ems.Desc) + ems.I18nDesc.SetStrInLang(i18nPkg.DefaultLang, ems.Desc) } return EnumsValueResV1{ Value: ems.Value, - Desc: ems.I18nDesc.GetStrInLang(locale.GetLangTagFromCtx(ctx)), + Desc: ems.I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)), } } @@ -243,7 +244,7 @@ func GetAuditPlanTypes(c echo.Context) error { for _, meta := range auditplan.Metas { auditPlanTypesV1 = append(auditPlanTypesV1, AuditPlanTypesV1{ Type: meta.Type, - Desc: locale.ShouldLocalizeMsg(c.Request().Context(), meta.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), meta.Desc), InstanceType: meta.InstanceType, }) } @@ -1424,7 +1425,7 @@ func GetAuditPlanSQLs(c echo.Context) error { for _, v := range head { res.Head = append(res.Head, AuditPlanSQLHeadV1{ Name: v.Name, - Desc: locale.ShouldLocalizeMsg(c.Request().Context(), v.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), v.Desc), Type: v.Type, }) } @@ -1516,7 +1517,7 @@ func GetAuditPlanReportSQLsV1(c echo.Context) error { } func spliceAuditResults(ctx context.Context, auditResults []model.AuditResult) string { - lang := locale.GetLangTagFromCtx(ctx) + lang := locale.Bundle.GetLangTagFromCtx(ctx) results := []string{} for _, auditResult := range auditResults { results = append(results, @@ -1563,15 +1564,15 @@ func ExportAuditPlanReportV1(c echo.Context) error { ctx := c.Request().Context() baseInfo := [][]string{ - {locale.ShouldLocalizeMsg(ctx, locale.APExportTaskName), auditPlanName}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportGenerationTime), reportInfo.CreatedAt.Format("2006/01/02 15:04")}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportResultRating), strconv.FormatInt(int64(reportInfo.Score), 10)}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportApprovalRate), fmt.Sprintf("%v%%", reportInfo.PassRate*100)}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportBelongingProject), projectName}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportCreator), dms.GetUserNameWithDelTag(reportInfo.AuditPlan.CreateUserID)}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportType), reportInfo.AuditPlan.Type}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportDbType), reportInfo.AuditPlan.DBType}, - {locale.ShouldLocalizeMsg(ctx, locale.APExportDatabase), reportInfo.AuditPlan.InstanceDatabase}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportTaskName), auditPlanName}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportGenerationTime), reportInfo.CreatedAt.Format("2006/01/02 15:04")}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportResultRating), strconv.FormatInt(int64(reportInfo.Score), 10)}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportApprovalRate), fmt.Sprintf("%v%%", reportInfo.PassRate*100)}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportBelongingProject), projectName}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportCreator), dms.GetUserNameWithDelTag(reportInfo.AuditPlan.CreateUserID)}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportType), reportInfo.AuditPlan.Type}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportDbType), reportInfo.AuditPlan.DBType}, + {locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportDatabase), reportInfo.AuditPlan.InstanceDatabase}, } err = csvWriter.WriteAll(baseInfo) if err != nil { @@ -1585,9 +1586,9 @@ func ExportAuditPlanReportV1(c echo.Context) error { } err = csvWriter.Write([]string{ - locale.ShouldLocalizeMsg(ctx, locale.APExportNumber), // 编号 + locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportNumber), // 编号 "SQL", - locale.ShouldLocalizeMsg(ctx, locale.APExportAuditResult), // 审核结果 + locale.Bundle.LocalizeMsgByCtx(ctx, locale.APExportAuditResult), // 审核结果 }) if err != nil { return controller.JSONBaseErrorReq(c, err) diff --git a/sqle/api/controller/v1/instance_audit_plan.go b/sqle/api/controller/v1/instance_audit_plan.go index 97a872b10..f0977332b 100644 --- a/sqle/api/controller/v1/instance_audit_plan.go +++ b/sqle/api/controller/v1/instance_audit_plan.go @@ -564,7 +564,7 @@ func ConvertAuditPlanTypeToResByID(ctx context.Context, id string) (AuditPlanTyp if meta.Type == auditPlan.Type { return AuditPlanTypeResBase{ AuditPlanType: auditPlan.Type, - AuditPlanTypeDesc: locale.ShouldLocalizeMsg(ctx, meta.Desc), + AuditPlanTypeDesc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc), AuditPlanId: auditPlan.ID, }, nil } @@ -577,7 +577,7 @@ func ConvertAuditPlanTypeToRes(ctx context.Context, id uint, auditPlanType strin if meta.Type == auditPlanType { return AuditPlanTypeResBase{ AuditPlanType: auditPlanType, - AuditPlanTypeDesc: locale.ShouldLocalizeMsg(ctx, meta.Desc), + AuditPlanTypeDesc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc), AuditPlanId: id, } } @@ -670,7 +670,7 @@ func ConvertAuditPlansToRes(ctx context.Context, auditPlans []*model.AuditPlanV2 } paramRes := AuditPlanParamResV1{ Key: p.Key, - Desc: p.GetDesc(locale.GetLangTagFromCtx(ctx)), + Desc: p.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), Type: string(p.Type), Value: val, } @@ -688,7 +688,7 @@ func ConvertAuditPlansToRes(ctx context.Context, auditPlans []*model.AuditPlanV2 } highParamRes := HighPriorityCondition{ Key: metaHpp.Key, - Desc: metaHpp.GetDesc(locale.GetLangTagFromCtx(ctx)), + Desc: metaHpp.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), Value: hpp.Value, Type: string(metaHpp.Type), Operator: Operator{ @@ -1002,7 +1002,7 @@ func GetInstanceAuditPlanSQLs(c echo.Context) error { for _, v := range head { res.Head = append(res.Head, AuditPlanSQLHeadV1{ Name: v.Name, - Desc: locale.ShouldLocalizeMsg(c.Request().Context(), v.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), v.Desc), Type: v.Type, }) } @@ -1096,7 +1096,7 @@ func GetInstanceAuditPlanSQLMeta(c echo.Context) error { for _, v := range head { data.Head = append(data.Head, AuditPlanSQLHeadV1{ Name: v.Name, - Desc: locale.ShouldLocalizeMsg(ctx, v.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(ctx, v.Desc), Type: v.Type, Sortable: v.Sortable, }) @@ -1104,7 +1104,7 @@ func GetInstanceAuditPlanSQLMeta(c echo.Context) error { for _, v := range filter { data.FilterMetaList = append(data.FilterMetaList, FilterMeta{ Name: v.Name, - Desc: locale.ShouldLocalizeMsg(ctx, v.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(ctx, v.Desc), FilterInputType: string(v.FilterInputType), FilterOpType: string(v.FilterOpType), FilterTips: ConvertFilterTipsToRes(v.FilterTips), @@ -1262,7 +1262,7 @@ func GetInstanceAuditPlanSQLExport(c echo.Context) error { csvWriter := csv.NewWriter(buff) toWrite := make([]string, len(head)) for col, h := range head { - toWrite[col] = locale.ShouldLocalizeMsg(c.Request().Context(), h.Desc) + toWrite[col] = locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), h.Desc) } if err = csvWriter.Write(toWrite); err != nil { return controller.JSONBaseErrorReq(c, err) diff --git a/sqle/api/controller/v1/rule.go b/sqle/api/controller/v1/rule.go index ae4eeff78..12cc715aa 100644 --- a/sqle/api/controller/v1/rule.go +++ b/sqle/api/controller/v1/rule.go @@ -444,7 +444,7 @@ func convertDefaultRuleTemplatesToRes(ctx context.Context, ruleTemplates []*mode for _, ruleTemplate := range ruleTemplates { ruleTemplateReq := RuleTemplateResV1{ Name: ruleTemplate.Name, - Desc: locale.ShouldLocalizeMsg(ctx, locale.DefaultRuleTemplatesDesc), + Desc: locale.Bundle.LocalizeMsgByCtx(ctx, locale.DefaultRuleTemplatesDesc), DBType: ruleTemplate.DBType, } ruleTemplatesReq = append(ruleTemplatesReq, ruleTemplateReq) @@ -485,7 +485,7 @@ type RuleParamResV1 struct { } func convertRuleToRes(ctx context.Context, rule *model.Rule) RuleResV1 { - lang := locale.GetLangTagFromCtx(ctx) + lang := locale.Bundle.GetLangTagFromCtx(ctx) if rule.I18nRuleInfo == nil { rule.I18nRuleInfo = make(driverV2.I18nRuleInfo) // avoid panic } @@ -506,7 +506,7 @@ func convertRuleToRes(ctx context.Context, rule *model.Rule) RuleResV1 { for _, p := range params { paramRes := RuleParamResV1{ Key: p.Key, - Desc: p.GetDesc(locale.GetLangTagFromCtx(ctx)), + Desc: p.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), Type: string(p.Type), Value: rule.Params.GetParam(p.Key).Value, } @@ -1327,7 +1327,7 @@ func exportRuleTemplateFile(c echo.Context, projectID string, ruleTemplateName s return controller.JSONBaseErrorReq(c, ErrRuleTemplateNotExist) } - lang := locale.GetLangTagFromCtx(c.Request().Context()) + lang := locale.Bundle.GetLangTagFromCtx(c.Request().Context()) // 补充缺失的信息(规则说明等描述信息) ruleNames := []string{} @@ -1367,7 +1367,7 @@ func exportRuleTemplateFile(c echo.Context, projectID string, ruleTemplateName s r.Params = append(r.Params, RuleParamResV1{ Key: param.Key, Value: param.Value, - Desc: param.GetDesc(locale.GetLangTagFromCtx(c.Request().Context())), + Desc: param.GetDesc(locale.Bundle.GetLangTagFromCtx(c.Request().Context())), Type: string(param.Type), }) } diff --git a/sqle/api/controller/v1/sql_audit_record.go b/sqle/api/controller/v1/sql_audit_record.go index 514ab4254..85ca894ac 100644 --- a/sqle/api/controller/v1/sql_audit_record.go +++ b/sqle/api/controller/v1/sql_audit_record.go @@ -883,8 +883,8 @@ func GetSQLAuditRecordTagTipsV1(c echo.Context) error { return c.JSON(http.StatusOK, &GetSQLAuditRecordTagTipsResV1{ BaseRes: controller.BaseRes{}, Tags: []string{ - locale.ShouldLocalizeMsg(c.Request().Context(), locale.AuditRecordTagFull), // 全量 - locale.ShouldLocalizeMsg(c.Request().Context(), locale.AuditRecordTagIncrement), // 增量 + locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), locale.AuditRecordTagFull), // 全量 + locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), locale.AuditRecordTagIncrement), // 增量 }, }) } diff --git a/sqle/api/controller/v1/statistic.go b/sqle/api/controller/v1/statistic.go index cf72f582d..d3476ee4a 100644 --- a/sqle/api/controller/v1/statistic.go +++ b/sqle/api/controller/v1/statistic.go @@ -355,7 +355,7 @@ func GetLicenseUsageV1(c echo.Context) error { Data: &LicenseUsageV1{ UsersUsage: LicenseUsageItem{ ResourceType: "user", - ResourceTypeDesc: locale.ShouldLocalizeMsg(c.Request().Context(), locale.StatisticResourceTypeUser), + ResourceTypeDesc: locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), locale.StatisticResourceTypeUser), Used: 0, Limit: 0, IsLimited: false, @@ -680,7 +680,7 @@ func StatisticAuditPlanV1(c echo.Context) error { newAuditPlanCount := &AuditPlanCount{ Count: dBTypeAuditPlanCounts[i].AuditPlanCount, Type: dBTypeAuditPlanCounts[i].Type, - Desc: locale.ShouldLocalizeMsg(c.Request().Context(), meta.Desc), + Desc: locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), meta.Desc), } dbTypeAuditPlanCountSliceMap[dbType] = append(auditPlanCountSlice, newAuditPlanCount) } diff --git a/sqle/api/controller/v1/task.go b/sqle/api/controller/v1/task.go index c641c8af1..333f3ce67 100644 --- a/sqle/api/controller/v1/task.go +++ b/sqle/api/controller/v1/task.go @@ -593,14 +593,14 @@ func DownloadTaskSQLReportFile(c echo.Context) error { buff.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM cw := csv.NewWriter(buff) err = cw.Write([]string{ - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportIndex), // "序号", - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportSQL), // "SQL", - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportAuditStatus), // "SQL审核状态", - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportAuditResult), // "SQL审核结果", - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportExecStatus), // "SQL执行状态", - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportExecResult), // "SQL执行结果", - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportRollbackSQL), // "SQL对应的回滚语句", - locale.ShouldLocalizeMsg(ctx, locale.TaskSQLReportDescription), // "SQL描述", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportIndex), // "序号", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportSQL), // "SQL", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportAuditStatus), // "SQL审核状态", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportAuditResult), // "SQL审核结果", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportExecStatus), // "SQL执行状态", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportExecResult), // "SQL执行结果", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportRollbackSQL), // "SQL对应的回滚语句", + locale.Bundle.LocalizeMsgByCtx(ctx, locale.TaskSQLReportDescription), // "SQL描述", }) if err != nil { return controller.JSONBaseErrorReq(c, errors.New(errors.WriteDataToTheFileError, err)) diff --git a/sqle/api/controller/v1/workflow_ce.go b/sqle/api/controller/v1/workflow_ce.go index 187fbc151..a912968bc 100644 --- a/sqle/api/controller/v1/workflow_ce.go +++ b/sqle/api/controller/v1/workflow_ce.go @@ -35,7 +35,7 @@ func getWorkflowTemplate(c echo.Context) error { } td := model.DefaultWorkflowTemplate(projectUid) - td.Desc = fmt.Sprintf(locale.ShouldLocalizeMsg(c.Request().Context(), locale.DefaultTemplatesDesc), projectUid) + td.Desc = fmt.Sprintf(locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), locale.DefaultTemplatesDesc), projectUid) return c.JSON(http.StatusOK, &GetWorkflowTemplateResV1{ BaseRes: controller.NewBaseReq(nil), diff --git a/sqle/api/controller/v2/audit_plan.go b/sqle/api/controller/v2/audit_plan.go index 94dca87e1..05da2d112 100644 --- a/sqle/api/controller/v2/audit_plan.go +++ b/sqle/api/controller/v2/audit_plan.go @@ -204,7 +204,7 @@ func GetAuditPlanReportSQLs(c echo.Context) error { } limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize) - lang := locale.GetLangTagFromCtx(c.Request().Context()) + lang := locale.Bundle.GetLangTagFromCtx(c.Request().Context()) data := map[string]interface{}{ "audit_plan_report_id": c.Param("audit_plan_report_id"), diff --git a/sqle/api/controller/v2/instance.go b/sqle/api/controller/v2/instance.go index e5eef5526..0cf304d59 100644 --- a/sqle/api/controller/v2/instance.go +++ b/sqle/api/controller/v2/instance.go @@ -112,7 +112,7 @@ func convertInstanceToRes(ctx context.Context, instance *model.Instance) Instanc for _, param := range instance.AdditionalParams { instanceResV2.AdditionalParams = append(instanceResV2.AdditionalParams, &v1.InstanceAdditionalParamResV1{ Name: param.Key, - Description: param.GetDesc(locale.GetLangTagFromCtx(ctx)), + Description: param.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), Type: string(param.Type), Value: fmt.Sprintf("%v", param.Value), }) diff --git a/sqle/api/controller/v2/sql_audit.go b/sqle/api/controller/v2/sql_audit.go index dfdd1cb2d..4a2432336 100644 --- a/sqle/api/controller/v2/sql_audit.go +++ b/sqle/api/controller/v2/sql_audit.go @@ -84,7 +84,7 @@ func DirectAudit(c echo.Context) error { } func convertTaskResultToAuditResV2(ctx context.Context, task *model.Task) *AuditResDataV2 { - lang := locale.GetLangTagFromCtx(ctx) + lang := locale.Bundle.GetLangTagFromCtx(ctx) results := make([]AuditSQLResV2, len(task.ExecuteSQLs)) for i, sql := range task.ExecuteSQLs { @@ -237,7 +237,7 @@ func convertFileAuditTaskResultToAuditResV2(ctx context.Context, task *model.Tas } func convertAuditResultToAuditResV2(ctx context.Context, auditResults model.AuditResults) []AuditResult { - lang := locale.GetLangTagFromCtx(ctx) + lang := locale.Bundle.GetLangTagFromCtx(ctx) ar := make([]AuditResult, len(auditResults)) for i := range auditResults { ar[i] = AuditResult{ diff --git a/sqle/api/controller/v2/task.go b/sqle/api/controller/v2/task.go index 168e3eb89..f1f8d13f0 100644 --- a/sqle/api/controller/v2/task.go +++ b/sqle/api/controller/v2/task.go @@ -118,7 +118,7 @@ func GetTaskSQLs(c echo.Context) error { ar := taskSQL.AuditResults[i] taskSQLRes.AuditResult = append(taskSQLRes.AuditResult, &AuditResult{ Level: ar.Level, - Message: ar.GetAuditMsgByLangTag(locale.GetLangTagFromCtx(c.Request().Context())), + Message: ar.GetAuditMsgByLangTag(locale.Bundle.GetLangTagFromCtx(c.Request().Context())), RuleName: ar.RuleName, DbType: task.DBType, I18nAuditResultInfo: ar.I18nAuditResultInfo, diff --git a/sqle/api/middleware/verify_user.go b/sqle/api/middleware/verify_user.go index 73e386576..755096ae1 100644 --- a/sqle/api/middleware/verify_user.go +++ b/sqle/api/middleware/verify_user.go @@ -1,7 +1,6 @@ package middleware import ( - v1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" dmsJWT "github.com/actiontech/dms/pkg/dms-common/api/jwt" dmsObject "github.com/actiontech/dms/pkg/dms-common/dmsobject" "github.com/actiontech/sqle/sqle/api/controller" @@ -20,7 +19,7 @@ func VerifyUserIsDisabled() echo.MiddlewareFunc { if err != nil { return controller.JSONBaseErrorReq(c, err) } - if user.Stat != v1.StatOK { + if user.Stat != "正常" && user.Stat != "Normal" { // todo i18n user Stat return controller.JSONBaseErrorReq(c, errors.NewUserDisabledErr("current user status is %s", user.Stat)) } return next(c) diff --git a/sqle/dms/common.go b/sqle/dms/common.go index d6d06dc63..32b65523b 100644 --- a/sqle/dms/common.go +++ b/sqle/dms/common.go @@ -74,7 +74,7 @@ func convertListUserToModel(user *dmsV1.ListUser) *model.User { Phone: user.Phone, WeChatID: user.WxID, } - if user.Stat != dmsV1.StatOK { + if user.Stat != "正常" && user.Stat != "Normal" { // todo i18n user Stat ret.Stat = 1 } return ret @@ -100,7 +100,7 @@ func convertUserToModel(user *dmsV1.GetUser) *model.User { WeChatID: user.WxID, ThirdPartyUserInfo: user.ThirdPartyUserInfo, } - if user.Stat != dmsV1.StatOK { + if user.Stat != "正常" && user.Stat != "Normal" { // todo i18n user Stat ret.Stat = 1 } return ret diff --git a/sqle/driver/mysql/advisor.go b/sqle/driver/mysql/advisor.go index ca8d3b42b..851e26e46 100644 --- a/sqle/driver/mysql/advisor.go +++ b/sqle/driver/mysql/advisor.go @@ -6,11 +6,11 @@ import ( "strings" "github.com/Masterminds/semver/v3" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/executor" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" "github.com/actiontech/sqle/sqle/driver/mysql/session" "github.com/actiontech/sqle/sqle/driver/mysql/util" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/pkg/params" "github.com/pingcap/parser/ast" "github.com/pingcap/parser/format" @@ -18,7 +18,6 @@ import ( "github.com/pingcap/parser/opcode" parser_driver "github.com/pingcap/tidb/types/parser_driver" "github.com/sirupsen/logrus" - "golang.org/x/text/language" ) const ( @@ -352,14 +351,14 @@ func (a *threeStarIndexAdvisor) GiveAdvices() []*OptimizeResult { } tableName := util.GetTableNameFromTableSource(a.drivingTableSource) indexColumns := a.adviceColumns.stringSlice() - var indexType = plocale.ShouldLocalizeMsgByLang(language.English, plocale.AdvisorIndexTypeComposite) + var indexType = plocale.AdvisorIndexTypeComposite if len(indexColumns) == 1 { - indexType = plocale.ShouldLocalizeMsgByLang(language.English, plocale.AdvisorIndexTypeSingle) + indexType = plocale.AdvisorIndexTypeSingle } return []*OptimizeResult{{ TableName: tableName, IndexedColumns: indexColumns, - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.ThreeStarIndexAdviceFormat, tableName, indexType, strings.Join(indexColumns, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.ThreeStarIndexAdviceFormat, tableName, indexType, strings.Join(indexColumns, ",")), }} } @@ -891,7 +890,7 @@ func (a *joinIndexAdvisor) giveAdvice() { a.advices = append(a.advices, &OptimizeResult{ TableName: drivenTableName, IndexedColumns: indexColumn, - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.JoinIndexAdviceFormat, strings.Join(indexColumn, ","), drivenTableName, drivenTableName, strings.Join(indexColumn, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.JoinIndexAdviceFormat, strings.Join(indexColumn, ","), drivenTableName, drivenTableName, strings.Join(indexColumn, ",")), }) } @@ -1031,7 +1030,7 @@ func (a *functionIndexAdvisor) giveAdvice() { a.advices = append(a.advices, &OptimizeResult{ TableName: tableName, IndexedColumns: columns, - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.FunctionIndexAdviceFormatV57, tableName, strings.Join(columns, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.FunctionIndexAdviceFormatV57, tableName, strings.Join(columns, ",")), }) return } @@ -1039,7 +1038,7 @@ func (a *functionIndexAdvisor) giveAdvice() { a.advices = append(a.advices, &OptimizeResult{ TableName: tableName, IndexedColumns: columns, - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.FunctionIndexAdviceFormatV80, tableName, strings.Join(columns, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.FunctionIndexAdviceFormatV80, tableName, strings.Join(columns, ",")), }) return } @@ -1047,7 +1046,7 @@ func (a *functionIndexAdvisor) giveAdvice() { a.advices = append(a.advices, &OptimizeResult{ TableName: tableName, IndexedColumns: columns, - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.FunctionIndexAdviceFormatAll, tableName, strings.Join(columns, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.FunctionIndexAdviceFormatAll, tableName, strings.Join(columns, ",")), }) } @@ -1144,7 +1143,7 @@ func (a *extremalIndexAdvisor) giveAdvice() { a.advices = append(a.advices, &OptimizeResult{ TableName: tableName, IndexedColumns: []string{indexColumn}, - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.ExtremalIndexAdviceFormat, tableName, indexColumn), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.ExtremalIndexAdviceFormat, tableName, indexColumn), }) } @@ -1236,6 +1235,6 @@ func (a *prefixIndexAdvisor) giveAdvice() { a.advices = append(a.advices, &OptimizeResult{ TableName: tableName, IndexedColumns: []string{column.Name.Name.L}, - Reason: plocale.ShouldLocalizeAll(plocale.PrefixIndexAdviceFormat), + Reason: plocale.Bundle.LocalizeAll(plocale.PrefixIndexAdviceFormat), }) } diff --git a/sqle/driver/mysql/advisor_test.go b/sqle/driver/mysql/advisor_test.go index 6c4b1a350..8be889b0e 100644 --- a/sqle/driver/mysql/advisor_test.go +++ b/sqle/driver/mysql/advisor_test.go @@ -6,15 +6,13 @@ import ( "strings" "testing" - "github.com/actiontech/sqle/sqle/driver/mysql/plocale" - "github.com/nicksnyder/go-i18n/v2/i18n" - "golang.org/x/text/language" - sqlmock "github.com/DATA-DOG/go-sqlmock" "github.com/actiontech/sqle/sqle/driver/mysql/executor" + "github.com/actiontech/sqle/sqle/driver/mysql/plocale" "github.com/actiontech/sqle/sqle/driver/mysql/session" "github.com/actiontech/sqle/sqle/driver/mysql/util" "github.com/actiontech/sqle/sqle/pkg/params" + "github.com/nicksnyder/go-i18n/v2/i18n" "github.com/pingcap/parser/ast" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -34,7 +32,7 @@ func newPrefixOptimizeResult(columns []string, tableName string) *OptimizeResult return &OptimizeResult{ TableName: tableName, IndexedColumns: columns, - Reason: plocale.ShouldLocalizeAll(plocale.PrefixIndexAdviceFormat), + Reason: plocale.Bundle.LocalizeAll(plocale.PrefixIndexAdviceFormat), } } @@ -43,12 +41,12 @@ func mockThreeStarOptimizeResult(caseName string, c optimizerTestContent, t *tes } func newThreeStarOptimizeResult(columns []string, tableName string) *OptimizeResult { - var indexType = plocale.ShouldLocalizeMsgByLang(language.English, plocale.AdvisorIndexTypeComposite) + var indexType = plocale.AdvisorIndexTypeComposite if len(columns) == 1 { - indexType = plocale.ShouldLocalizeMsgByLang(language.English, plocale.AdvisorIndexTypeSingle) + indexType = plocale.AdvisorIndexTypeSingle } return &OptimizeResult{ - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.ThreeStarIndexAdviceFormat, tableName, indexType, strings.Join(columns, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.ThreeStarIndexAdviceFormat, tableName, indexType, strings.Join(columns, ",")), IndexedColumns: columns, TableName: tableName, } @@ -62,7 +60,7 @@ func newFunctionIndexOptimizeResult(format *i18n.Message, columns []string, tabl return &OptimizeResult{ TableName: tableName, IndexedColumns: columns, - Reason: plocale.ShouldLocalizeAllWithArgs(format, tableName, strings.Join(columns, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(format, tableName, strings.Join(columns, ",")), } } @@ -74,7 +72,7 @@ func newExtremalIndexOptimizeResult(column string, tableName string) *OptimizeRe return &OptimizeResult{ TableName: tableName, IndexedColumns: []string{column}, - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.ExtremalIndexAdviceFormat, tableName, column), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.ExtremalIndexAdviceFormat, tableName, column), } } @@ -84,7 +82,7 @@ func mockJoinOptimizeResult(caseName string, c optimizerTestContent, t *testing. func newJoinIndexOptimizeResult(indexColumn []string, drivenTableName string) *OptimizeResult { return &OptimizeResult{ - Reason: plocale.ShouldLocalizeAllWithArgs(plocale.JoinIndexAdviceFormat, strings.Join(indexColumn, ","), drivenTableName, drivenTableName, strings.Join(indexColumn, ",")), + Reason: plocale.Bundle.LocalizeAllWithArgs(plocale.JoinIndexAdviceFormat, strings.Join(indexColumn, ","), drivenTableName, drivenTableName, strings.Join(indexColumn, ",")), IndexedColumns: indexColumn, TableName: drivenTableName, } diff --git a/sqle/driver/mysql/analysis.go b/sqle/driver/mysql/analysis.go index bf7da0add..942a6e088 100644 --- a/sqle/driver/mysql/analysis.go +++ b/sqle/driver/mysql/analysis.go @@ -87,28 +87,28 @@ func (i *MysqlDriverImpl) getTableColumnsInfo(conn *executor.Executor, schema, t columns := []driverV2.TabularDataHead{ { Name: "COLUMN_NAME", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnName), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescColumnName), }, { Name: "COLUMN_TYPE", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnType), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescColumnType), }, { Name: "CHARACTER_SET_NAME", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescCharacterSetName), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescCharacterSetName), }, { Name: "IS_NULLABLE", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescIsNullable), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescIsNullable), }, { Name: "COLUMN_KEY", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnKey), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescColumnKey), }, { Name: "COLUMN_DEFAULT", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnDefault), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescColumnDefault), }, { Name: "EXTRA", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescExtra), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescExtra), }, { Name: "COLUMN_COMMENT", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnComment), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescColumnComment), }, } @@ -146,30 +146,30 @@ func (i *MysqlDriverImpl) getTableIndexesInfo(conn *executor.Executor, schema, t columns := []driverV2.TabularDataHead{ { Name: "Column_name", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescColumnName), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescColumnName), }, { Name: "Key_name", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescKeyName), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescKeyName), }, { // set the row's value as Yes if Non_unique is 0 and No if Non_unique is 1 Name: "Unique", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescUnique), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescUnique), }, { Name: "Seq_in_index", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescSeqInIndex), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescSeqInIndex), }, { Name: "Cardinality", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescCardinality), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescCardinality), }, { // set the row's value as Yes if the column may contain NULL values and No if not Name: "Null", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescIsNullable), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescIsNullable), }, { Name: "Index_type", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescIndexType), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescIndexType), }, { Name: "Comment", - I18nDesc: plocale.ShouldLocalizeAll(plocale.AnalysisDescComment), + I18nDesc: plocale.Bundle.LocalizeAll(plocale.AnalysisDescComment), }, } diff --git a/sqle/driver/mysql/audit.go b/sqle/driver/mysql/audit.go index 418f28427..0c86100b3 100644 --- a/sqle/driver/mysql/audit.go +++ b/sqle/driver/mysql/audit.go @@ -50,7 +50,7 @@ func (i *MysqlDriverImpl) CheckInvalid(node ast.Node) error { if err != nil && session.IsParseShowCreateTableContentErr(err) { return err // todo #1630 直接返回原始错误类型,方便跳过 } else if err != nil { - return fmt.Errorf(plocale.ShouldLocalizeMsgByLang(language.English, plocale.CheckInvalidErrorFormat), err) + return fmt.Errorf(plocale.Bundle.LocalizeMsgByLang(language.English, plocale.CheckInvalidErrorFormat), err) } return nil @@ -67,7 +67,7 @@ func (i *MysqlDriverImpl) CheckExplain(node ast.Node) error { } if err != nil { i.result.Add(driverV2.RuleLevelWarn, rulepkg.ConfigDMLExplainPreCheckEnable, - plocale.ShouldLocalizeAll(plocale.CheckInvalidErrorFormat), err) + plocale.Bundle.LocalizeAll(plocale.CheckInvalidErrorFormat), err) } return nil @@ -88,7 +88,7 @@ func (i *MysqlDriverImpl) CheckInvalidOffline(node ast.Node) error { err = i.checkUnparsedStmt(stmt) } if err != nil { - return fmt.Errorf(plocale.ShouldLocalizeMsgByLang(language.English, plocale.CheckInvalidErrorFormat), err) + return fmt.Errorf(plocale.Bundle.LocalizeMsgByLang(language.English, plocale.CheckInvalidErrorFormat), err) } return nil } @@ -109,14 +109,14 @@ func (i *MysqlDriverImpl) checkInvalidCreateTable(stmt *ast.CreateTableStmt) err return err } if !schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), schemaName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), schemaName) } else { tableExist, err := i.Ctx.IsTableExist(stmt.Table) if err != nil { return err } if tableExist && !stmt.IfNotExists { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableExistMessage), i.getTableName(stmt.Table)) } if stmt.ReferTable != nil { @@ -125,7 +125,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateTable(stmt *ast.CreateTableStmt) err return err } if !referTableExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), i.getTableName(stmt.ReferTable)) } } @@ -170,7 +170,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateTableOffline(stmt *ast.CreateTableSt } duplicateName := utils.GetDuplicate(names) if len(duplicateName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicatePrimaryKeyedColumnMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicatePrimaryKeyedColumnMessage), strings.Join(duplicateName, ",")) } case ast.ConstraintIndex, ast.ConstraintUniq, ast.ConstraintFulltext: @@ -178,7 +178,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateTableOffline(stmt *ast.CreateTableSt if constraintName != "" { indexesName = append(indexesName, constraint.Name) } else { - constraintName = plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnonymousMark) + constraintName = plocale.Bundle.LocalizeMsgByLang(language.English, plocale.AnonymousMark) } names := []string{} for _, col := range constraint.Keys { @@ -188,23 +188,23 @@ func (i *MysqlDriverImpl) checkInvalidCreateTableOffline(stmt *ast.CreateTableSt } duplicateName := utils.GetDuplicate(names) if len(duplicateName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateIndexedColumnMessage), constraintName, + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateIndexedColumnMessage), constraintName, strings.Join(duplicateName, ",")) } } } if d := utils.GetDuplicate(colsName); len(d) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateColumnsMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateColumnsMessage), strings.Join(d, ",")) } if d := utils.GetDuplicate(indexesName); len(d) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateIndexesMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateIndexesMessage), strings.Join(d, ",")) } if pkCounter > 1 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.MultiPrimaryKeyMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.MultiPrimaryKeyMessage)) } notExistKeyColsName := []string{} for _, colName := range keyColsName { @@ -213,7 +213,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateTableOffline(stmt *ast.CreateTableSt } } if len(notExistKeyColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.KeyedColumnNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.KeyedColumnNotExistMessage), strings.Join(utils.RemoveDuplicate(notExistKeyColsName), ",")) } return nil @@ -242,7 +242,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error return err } if !schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), schemaName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), schemaName) return nil } createTableStmt, tableExist, err := i.Ctx.GetCreateTableStmt(stmt.Table) @@ -250,7 +250,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error return err } if !tableExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), i.getTableName(stmt.Table)) return nil } @@ -320,7 +320,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error } else { colNameMap[colName] = struct{}{} if hasPk && util.HasOneInOptions(col.Options, ast.ColumnOptionPrimaryKey) { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.PrimaryKeyExistMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.PrimaryKeyExistMessage)) } else { hasPk = true } @@ -344,7 +344,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error if len(util.GetAlterTableSpecByTp(stmt.Specs, ast.AlterTableDropPrimaryKey)) > 0 && !hasPk { // primary key not exist, can not drop primary key - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.PrimaryKeyNotExistMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.PrimaryKeyNotExistMessage)) } for _, spec := range util.GetAlterTableSpecByTp(stmt.Specs, ast.AlterTableDropIndex) { @@ -379,7 +379,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error case ast.ConstraintPrimaryKey: if hasPk { // primary key has exist, can not add primary key - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.PrimaryKeyExistMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.PrimaryKeyExistMessage)) } else { hasPk = true } @@ -393,7 +393,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error } duplicateColumn := utils.GetDuplicate(names) if len(duplicateColumn) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicatePrimaryKeyedColumnMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicatePrimaryKeyedColumnMessage), strings.Join(duplicateColumn, ",")) } case ast.ConstraintUniq, ast.ConstraintIndex, ast.ConstraintFulltext: @@ -405,7 +405,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error indexLowerCaseNameMap.Add(indexName) } } else { - indexName = plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnonymousMark) + indexName = plocale.Bundle.LocalizeMsgByLang(language.English, plocale.AnonymousMark) } names := []string{} for _, col := range spec.Constraint.Keys { @@ -417,30 +417,30 @@ func (i *MysqlDriverImpl) checkInvalidAlterTable(stmt *ast.AlterTableStmt) error } duplicateColumn := utils.GetDuplicate(names) if len(duplicateColumn) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateIndexedColumnMessage), indexName, + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateIndexedColumnMessage), indexName, strings.Join(duplicateColumn, ",")) } } } if len(needExistsColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsColsName), ",")) } if len(needNotExistsColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnExistMessage), strings.Join(utils.RemoveDuplicate(needNotExistsColsName), ",")) } if len(needExistsIndexesName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.IndexNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.IndexNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsIndexesName), ",")) } if len(needNotExistsIndexesName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.IndexExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.IndexExistMessage), strings.Join(utils.RemoveDuplicate(needNotExistsIndexesName), ",")) } if len(needExistsKeyColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.KeyedColumnNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.KeyedColumnNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsKeyColsName), ",")) } return nil @@ -461,7 +461,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTableOffline(stmt *ast.AlterTableStmt for _, spec := range util.GetAlterTableSpecByTp(stmt.Specs, ast.AlterTableAddColumns) { for _, col := range spec.NewColumns { if hasPk && util.HasOneInOptions(col.Options, ast.ColumnOptionPrimaryKey) { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.PrimaryKeyExistMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.PrimaryKeyExistMessage)) } else { hasPk = true } @@ -474,7 +474,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTableOffline(stmt *ast.AlterTableStmt case ast.ConstraintPrimaryKey: if hasPk { // primary key has exist, can not add primary key - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.PrimaryKeyExistMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.PrimaryKeyExistMessage)) } else { hasPk = true } @@ -485,13 +485,13 @@ func (i *MysqlDriverImpl) checkInvalidAlterTableOffline(stmt *ast.AlterTableStmt } duplicateColumn := utils.GetDuplicate(names) if len(duplicateColumn) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicatePrimaryKeyedColumnMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicatePrimaryKeyedColumnMessage), strings.Join(duplicateColumn, ",")) } case ast.ConstraintUniq, ast.ConstraintIndex, ast.ConstraintFulltext: indexName := spec.Constraint.Name if indexName == "" { - indexName = plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnonymousMark) + indexName = plocale.Bundle.LocalizeMsgByLang(language.English, plocale.AnonymousMark) } names := []string{} for _, col := range spec.Constraint.Keys { @@ -500,7 +500,7 @@ func (i *MysqlDriverImpl) checkInvalidAlterTableOffline(stmt *ast.AlterTableStmt } duplicateColumn := utils.GetDuplicate(names) if len(duplicateColumn) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateIndexedColumnMessage), indexName, + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateIndexedColumnMessage), indexName, strings.Join(duplicateColumn, ",")) } } @@ -541,11 +541,11 @@ func (i *MysqlDriverImpl) checkInvalidDropTable(stmt *ast.DropTableStmt) error { } } if len(needExistsSchemasName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsSchemasName), ",")) } if len(needExistsTablesName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsTablesName), ",")) } return nil @@ -564,7 +564,7 @@ func (i *MysqlDriverImpl) checkInvalidUse(stmt *ast.UseStmt) error { return err } if !schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), stmt.DBName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), stmt.DBName) } return nil } @@ -586,7 +586,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateDatabase(stmt *ast.CreateDatabaseStm return err } if schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaExistMessage), schemaName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaExistMessage), schemaName) } return nil } @@ -608,7 +608,7 @@ func (i *MysqlDriverImpl) checkInvalidDropDatabase(stmt *ast.DropDatabaseStmt) e return err } if !schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), schemaName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), schemaName) } return nil } @@ -630,7 +630,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateIndex(stmt *ast.CreateIndexStmt) err return err } if !schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), schemaName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), schemaName) return nil } createTableStmt, tableExist, err := i.Ctx.GetCreateTableStmt(stmt.Table) @@ -638,7 +638,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateIndex(stmt *ast.CreateIndexStmt) err return err } if !tableExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), i.getTableName(stmt.Table)) return nil } @@ -653,7 +653,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateIndex(stmt *ast.CreateIndexStmt) err } } if _, ok := indexNameMap[stmt.IndexName]; ok { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.IndexExistMessage), stmt.IndexName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.IndexExistMessage), stmt.IndexName) } keyColsName := []string{} keyColNeedExist := []string{} @@ -666,12 +666,12 @@ func (i *MysqlDriverImpl) checkInvalidCreateIndex(stmt *ast.CreateIndexStmt) err } duplicateName := utils.GetDuplicate(keyColsName) if len(duplicateName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateIndexedColumnMessage), stmt.IndexName, + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateIndexedColumnMessage), stmt.IndexName, strings.Join(duplicateName, ",")) } if len(keyColNeedExist) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.KeyedColumnNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.KeyedColumnNotExistMessage), strings.Join(utils.RemoveDuplicate(keyColNeedExist), ",")) } return nil @@ -692,7 +692,7 @@ func (i *MysqlDriverImpl) checkInvalidCreateIndexOffline(stmt *ast.CreateIndexSt } duplicateName := utils.GetDuplicate(keyColsName) if len(duplicateName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateIndexedColumnMessage), stmt.IndexName, + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateIndexedColumnMessage), stmt.IndexName, strings.Join(duplicateName, ",")) } return nil @@ -717,7 +717,7 @@ func (i *MysqlDriverImpl) checkInvalidDropIndex(stmt *ast.DropIndexStmt) error { return err } if !schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), schemaName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), schemaName) return nil } createTableStmt, tableExist, err := i.Ctx.GetCreateTableStmt(stmt.Table) @@ -725,7 +725,7 @@ func (i *MysqlDriverImpl) checkInvalidDropIndex(stmt *ast.DropIndexStmt) error { return err } if !tableExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), i.getTableName(stmt.Table)) return nil } @@ -736,7 +736,7 @@ func (i *MysqlDriverImpl) checkInvalidDropIndex(stmt *ast.DropIndexStmt) error { } } if _, ok := indexNameMap[stmt.IndexName]; !ok { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.IndexNotExistMessage), stmt.IndexName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.IndexNotExistMessage), stmt.IndexName) } return nil } @@ -761,7 +761,7 @@ func (i *MysqlDriverImpl) checkInvalidInsert(stmt *ast.InsertStmt) error { return err } if !schemaExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), schemaName) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), schemaName) return nil } createTableStmt, tableExist, err := i.Ctx.GetCreateTableStmt(table) @@ -769,7 +769,7 @@ func (i *MysqlDriverImpl) checkInvalidInsert(stmt *ast.InsertStmt) error { return err } if !tableExist { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), i.getTableName(table)) return nil } @@ -795,7 +795,7 @@ func (i *MysqlDriverImpl) checkInvalidInsert(stmt *ast.InsertStmt) error { } } if d := utils.GetDuplicate(insertColsName); len(d) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateColumnsMessage), strings.Join(d, ",")) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateColumnsMessage), strings.Join(d, ",")) } needExistColsName := []string{} @@ -805,14 +805,14 @@ func (i *MysqlDriverImpl) checkInvalidInsert(stmt *ast.InsertStmt) error { } } if len(needExistColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistColsName), ",")) } if stmt.Lists != nil { for _, list := range stmt.Lists { if len(list) != len(insertColsName) { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnsValuesNotMatchMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnsValuesNotMatchMessage)) break } } @@ -841,13 +841,13 @@ func (i *MysqlDriverImpl) checkInvalidInsertOffline(stmt *ast.InsertStmt) error } } if d := utils.GetDuplicate(insertColsName); len(d) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.DuplicateColumnsMessage), strings.Join(d, ",")) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.DuplicateColumnsMessage), strings.Join(d, ",")) } if stmt.Lists != nil && len(insertColsName) > 0 { for _, list := range stmt.Lists { if len(list) != len(insertColsName) { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnsValuesNotMatchMessage)) + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnsValuesNotMatchMessage)) break } } @@ -906,11 +906,11 @@ func (i *MysqlDriverImpl) checkInvalidUpdate(stmt *ast.UpdateStmt) error { } } if len(needExistsSchemasName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsSchemasName), ",")) } if len(needExistsTablesName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsTablesName), ",")) } @@ -971,12 +971,12 @@ func (i *MysqlDriverImpl) checkInvalidUpdate(stmt *ast.UpdateStmt) error { }, stmt.Where) if len(needExistColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistColsName), ",")) } if len(ambiguousColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnIsAmbiguousMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnIsAmbiguousMessage), strings.Join(utils.RemoveDuplicate(ambiguousColsName), ",")) } return nil @@ -1034,11 +1034,11 @@ func (i *MysqlDriverImpl) checkInvalidDelete(stmt *ast.DeleteStmt) error { } } if len(needExistsSchemasName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsSchemasName), ",")) } if len(needExistsTablesName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsTablesName), ",")) } if len(needExistsSchemasName) > 0 || len(needExistsTablesName) > 0 { @@ -1086,12 +1086,12 @@ func (i *MysqlDriverImpl) checkInvalidDelete(stmt *ast.DeleteStmt) error { }, stmt.Where) if len(needExistColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistColsName), ",")) } if len(ambiguousColsName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.ColumnIsAmbiguousMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.ColumnIsAmbiguousMessage), strings.Join(utils.RemoveDuplicate(ambiguousColsName), ",")) } return nil @@ -1145,11 +1145,11 @@ func (i *MysqlDriverImpl) checkInvalidSelect(stmt *ast.SelectStmt) error { } } if len(needExistsSchemasName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.SchemaNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.SchemaNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsSchemasName), ",")) } if len(needExistsTablesName) > 0 { - i.result.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAll(plocale.TableNotExistMessage), + i.result.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAll(plocale.TableNotExistMessage), strings.Join(utils.RemoveDuplicate(needExistsTablesName), ",")) } return nil @@ -1157,6 +1157,6 @@ func (i *MysqlDriverImpl) checkInvalidSelect(stmt *ast.SelectStmt) error { // checkUnparsedStmt might add more check in future. func (i *MysqlDriverImpl) checkUnparsedStmt(stmt *ast.UnparsedStmt) error { - i.result.Add(driverV2.RuleLevelWarn, "", plocale.ShouldLocalizeAll(plocale.UnsupportedSyntaxError)) + i.result.Add(driverV2.RuleLevelWarn, "", plocale.Bundle.LocalizeAll(plocale.UnsupportedSyntaxError)) return nil } diff --git a/sqle/driver/mysql/audit_test.go b/sqle/driver/mysql/audit_test.go index 60eb45440..8d13176e0 100644 --- a/sqle/driver/mysql/audit_test.go +++ b/sqle/driver/mysql/audit_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" "golang.org/x/text/language" @@ -36,7 +37,7 @@ func newTestResult() *testResult { } func (t *testResult) add(level driverV2.RuleLevel, ruleName string, message string, args ...interface{}) *testResult { - t.Results.Add(level, ruleName, plocale.ConvertStr2I18n(message), args...) + t.Results.Add(level, ruleName, i18nPkg.ConvertStr2I18nAsDefaultLang(message), args...) return t } @@ -48,7 +49,7 @@ func (t *testResult) addResult(ruleName string, args ...interface{}) *testResult level := handler.Rule.Level var m string if handler.Message != nil { - m = plocale.ShouldLocalizeMsgByLang(language.Chinese, handler.Message) + m = plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, handler.Message) } return t.add(level, ruleName, m, args...) } @@ -219,7 +220,7 @@ func inspectCase(t *testing.T, desc string, i *MysqlDriverImpl, sql string, resu t.Errorf("%s test failed, \n\nsql:\n %s\n\nexpect level: %s\nexpect result:\n%s\n\nactual level: %s\nactual result:\n%s\n", desc, stmt.Text(), results[idx].level(), results[idx].message(), actualResults[idx].Level(), actualResults[idx].Message()) } else { - t.Logf("\n\ncase:%s\nactual level: %s\nactual result:\n%s\n\n", desc, actualResults[idx].Level(), actualResults[idx].Message()) + //t.Logf("\n\ncase:%s\nactual level: %s\nactual result:\n%s\n\n", desc, actualResults[idx].Level(), actualResults[idx].Message()) } } } @@ -232,7 +233,7 @@ func TestMessage(t *testing.T) { func TestCheckInvalidUse(t *testing.T) { runDefaultRulesInspectCase(t, "use_database: database not exist", DefaultMysqlInspect(), "use no_exist_db", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "no_exist_db"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "no_exist_db"), ) inspect1 := DefaultMysqlInspect() @@ -248,7 +249,7 @@ func TestCaseSensitive(t *testing.T) { ` select id from exist_db.EXIST_TB_1 where id = 1 limit 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.EXIST_TB_1"). + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.EXIST_TB_1"). add(driverV2.RuleLevelNotice, "", "LIMIT 查询建议使用ORDER BY")) inspect1 := DefaultMysqlInspect() @@ -272,7 +273,7 @@ func TestDDLCheckTableSize(t *testing.T) { runSingleRuleInspectCase(rule, t, "drop_table: table4 oversized", DefaultMysqlInspect(), `drop table exist_db.exist_tb_4;`, newTestResult().addResult(rulepkg.DDLCheckTableSize, "exist_tb_4", 16)) runSingleRuleInspectCase(rule, t, "alter_table: table4 oversized", DefaultMysqlInspect(), - `alter table exist_db.exist_tb_4;`, newTestResult().addResult(rulepkg.DDLCheckTableSize, "exist_tb_4", 16) /*.addResult(rulepkg.ConfigDDLOSCMinSize, plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PTOSCNoUniqueIndexOrPrimaryKey))*/) + `alter table exist_db.exist_tb_4;`, newTestResult().addResult(rulepkg.DDLCheckTableSize, "exist_tb_4", 16) /*.addResult(rulepkg.ConfigDDLOSCMinSize, plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.PTOSCNoUniqueIndexOrPrimaryKey))*/) } @@ -329,7 +330,7 @@ v2 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test", PRIMARY KEY (id) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db"), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"), ) runDefaultRulesInspectCase(t, "create_table: table is exist(1)", DefaultMysqlInspect(), @@ -361,14 +362,14 @@ v2 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test", PRIMARY KEY (id) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableExistMessage), "exist_db.exist_tb_1"), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableExistMessage), "exist_db.exist_tb_1"), ) runDefaultRulesInspectCase(t, "create_table: refer table not exist", DefaultMysqlInspect(), ` CREATE TABLE exist_db.not_exist_tb_1 like exist_db.not_exist_tb_2; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb_2"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb_2"), ) runDefaultRulesInspectCase(t, "create_table: multi pk(1)", DefaultMysqlInspect(), @@ -382,7 +383,7 @@ v2 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test", PRIMARY KEY (id) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.MultiPrimaryKeyMessage))) runDefaultRulesInspectCase(t, "create_table: multi pk(2)", DefaultMysqlInspect(), ` @@ -396,7 +397,7 @@ PRIMARY KEY (id), PRIMARY KEY (v1) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.MultiPrimaryKeyMessage))) runDefaultRulesInspectCase(t, "create_table: duplicate column", DefaultMysqlInspect(), ` @@ -409,7 +410,7 @@ v1 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test", PRIMARY KEY (id) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateColumnsMessage), "v1")) runDefaultRulesInspectCase(t, "create_table: duplicate index", DefaultMysqlInspect(), @@ -425,7 +426,7 @@ INDEX idx_1 (v1), INDEX idx_1 (v2) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexesMessage), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexesMessage), "idx_1")) runDefaultRulesInspectCase(t, "create_table: key column not exist", DefaultMysqlInspect(), @@ -441,7 +442,7 @@ INDEX idx_1 (v3), INDEX idx_2 (v4,v5) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.KeyedColumnNotExistMessage), "v3,v4,v5").add(driverV2.RuleLevelWarn, rulepkg.DDLCheckIndexNotNullConstraint, "这些索引字段(v3,v4,v5)需要有非空约束")) runDefaultRulesInspectCase(t, "create_table: pk column not exist", DefaultMysqlInspect(), @@ -455,7 +456,7 @@ v2 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test", PRIMARY KEY (id11) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.KeyedColumnNotExistMessage), "id11").addResult(rulepkg.DDLCheckFieldNotNUllMustContainDefaultValue, "id").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "id11")) runDefaultRulesInspectCase(t, "create_table: pk column is duplicate", DefaultMysqlInspect(), @@ -469,7 +470,7 @@ v2 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test", PRIMARY KEY (id,id) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicatePrimaryKeyedColumnMessage), "id")) + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicatePrimaryKeyedColumnMessage), "id")) runDefaultRulesInspectCase(t, "create_table: index column is duplicate", DefaultMysqlInspect(), ` @@ -483,7 +484,7 @@ PRIMARY KEY (id), INDEX idx_1 (v1,v1) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx_1", + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), "idx_1", "v1")) runDefaultRulesInspectCase(t, "create_table: index column is duplicate(2)", DefaultMysqlInspect(), @@ -498,7 +499,7 @@ PRIMARY KEY (id), INDEX (v1,v1) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnonymousMark), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), plocale.Bundle.LocalizeMsgByLang(language.English, plocale.AnonymousMark), "v1").addResult(rulepkg.DDLCheckIndexPrefix, "idx_")) runDefaultRulesInspectCase(t, "create_table: index column is duplicate(3)", DefaultMysqlInspect(), @@ -514,8 +515,8 @@ INDEX idx_1 (v1,v1), INDEX idx_2 (v1,v2,v2) )ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT="unit test"; `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx_1", "v1"). - add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx_2", "v2")) + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), "idx_1", "v1"). + add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), "idx_2", "v2")) } func TestCheckInvalidAlterTable(t *testing.T) { @@ -535,7 +536,7 @@ func TestCheckInvalidAlterTable(t *testing.T) { runDefaultRulesInspectCase(t, "alter_table: schema not exist", DefaultMysqlInspect(), `ALTER TABLE not_exist_db.exist_tb_1 add column v5 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test"; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"), ) @@ -543,7 +544,7 @@ func TestCheckInvalidAlterTable(t *testing.T) { ` ALTER TABLE exist_db.not_exist_tb_1 add column v5 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test"; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb_1"), ) @@ -551,14 +552,14 @@ ALTER TABLE exist_db.not_exist_tb_1 add column v5 varchar(255) NOT NULL DEFAULT ` ALTER TABLE exist_db.exist_tb_1 Add column v1 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test"; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnExistMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnExistMessage), "v1"), ) runDefaultRulesInspectCase(t, "alter_table: drop a not exist column", DefaultMysqlInspect(), ` ALTER TABLE exist_db.exist_tb_1 drop column v5; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v5"), ) @@ -566,7 +567,7 @@ ALTER TABLE exist_db.exist_tb_1 drop column v5; ` ALTER TABLE exist_db.exist_tb_1 alter column v5 set default 'v5'; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v5"), ) @@ -581,7 +582,7 @@ ALTER TABLE exist_db.exist_tb_1 change column v1 v1 varchar(255) NOT NULL DEFAUL ` ALTER TABLE exist_db.exist_tb_1 change column v5 v5 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test"; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v5"), ) @@ -589,7 +590,7 @@ ALTER TABLE exist_db.exist_tb_1 change column v5 v5 varchar(255) NOT NULL DEFAUL ` ALTER TABLE exist_db.exist_tb_1 change column v2 v1 varchar(255) NOT NULL DEFAULT "unit test" COMMENT "unit test"; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnExistMessage), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnExistMessage), "v1"), ) @@ -605,7 +606,7 @@ ALTER TABLE exist_db.exist_tb_2 Add primary key(id); ALTER TABLE exist_db.exist_tb_1 Add primary key(v1); `, newTestResult().addResult(rulepkg.DDLCheckPKName). - add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PrimaryKeyExistMessage)). + add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.PrimaryKeyExistMessage)). addResult(rulepkg.DDLCheckPKWithoutAutoIncrement). addResult(rulepkg.DDLCheckPKWithoutBigintUnsigned), ) @@ -614,14 +615,14 @@ ALTER TABLE exist_db.exist_tb_1 Add primary key(v1); ` ALTER TABLE exist_db.exist_tb_2 Add primary key(id11); `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), "id11").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "id11"), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.KeyedColumnNotExistMessage), "id11").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "id11"), ) runDefaultRulesInspectCase(t, "alter_table: Add pk but key column is duplicate", DefaultMysqlInspect(), ` ALTER TABLE exist_db.exist_tb_2 Add primary key(id,id); `, - newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicatePrimaryKeyedColumnMessage), + newTestResult().addResult(rulepkg.DDLCheckPKName).add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicatePrimaryKeyedColumnMessage), "id"), ) @@ -629,28 +630,28 @@ ALTER TABLE exist_db.exist_tb_2 Add primary key(id,id); ` ALTER TABLE exist_db.exist_tb_1 Add index idx_1 (v1); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.IndexExistMessage), "idx_1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.IndexExistMessage), "idx_1"), ) runDefaultRulesInspectCase(t, "alter_table: drop a not exist index", DefaultMysqlInspect(), ` ALTER TABLE exist_db.exist_tb_1 drop index idx_2; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.IndexNotExistMessage), "idx_2"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.IndexNotExistMessage), "idx_2"), ) runDefaultRulesInspectCase(t, "alter_table: Add index but key column not exist", DefaultMysqlInspect(), ` ALTER TABLE exist_db.exist_tb_1 Add index idx_2 (v3); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), "v3").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.KeyedColumnNotExistMessage), "v3").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v3"), ) runDefaultRulesInspectCase(t, "alter_table: Add index but key column is duplicate", DefaultMysqlInspect(), ` ALTER TABLE exist_db.exist_tb_1 Add index idx_2 (id,id); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx_2", + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), "idx_2", "id"), ) @@ -658,7 +659,7 @@ ALTER TABLE exist_db.exist_tb_1 Add index idx_2 (id,id); ` ALTER TABLE exist_db.exist_tb_1 Add index (id,id); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), plocale.ShouldLocalizeMsgByLang(language.English, plocale.AnonymousMark), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), plocale.Bundle.LocalizeMsgByLang(language.English, plocale.AnonymousMark), "id").addResult(rulepkg.DDLCheckIndexPrefix, "idx_"), ) } @@ -675,7 +676,7 @@ CREATE DATABASE if not exists exist_db; ` CREATE DATABASE exist_db; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaExistMessage), "exist_db"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaExistMessage), "exist_db"), ) } @@ -684,42 +685,42 @@ func TestCheckInvalidCreateIndex(t *testing.T) { ` CREATE INDEX idx_1 ON not_exist_db.not_exist_tb(v1); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v1"), ) runDefaultRulesInspectCase(t, "create_index: table not exist", DefaultMysqlInspect(), ` CREATE INDEX idx_1 ON exist_db.not_exist_tb(v1); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v1"), ) runDefaultRulesInspectCase(t, "create_index: index exist", DefaultMysqlInspect(), ` CREATE INDEX idx_1 ON exist_db.exist_tb_1(v1); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.IndexExistMessage), "idx_1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.IndexExistMessage), "idx_1"), ) runDefaultRulesInspectCase(t, "create_index: key column not exist", DefaultMysqlInspect(), ` CREATE INDEX idx_2 ON exist_db.exist_tb_1(v3); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), "v3").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.KeyedColumnNotExistMessage), "v3").addResult(rulepkg.DDLCheckIndexNotNullConstraint, "v3"), ) runDefaultRulesInspectCase(t, "create_index: key column is duplicate", DefaultMysqlInspect(), ` CREATE INDEX idx_2 ON exist_db.exist_tb_1(id,id); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx_2", "id"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), "idx_2", "id"), ) runDefaultRulesInspectCase(t, "create_index: key column is duplicate", DefaultMysqlInspect(), ` CREATE INDEX idx_2 ON exist_db.exist_tb_1(id,id,v1); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx_2", "id"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateIndexedColumnMessage), "idx_2", "id"), ) } @@ -747,7 +748,7 @@ DROP DATABASE if exists not_exist_db; ` DROP DATABASE not_exist_db; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"), ) runDefaultRulesInspectCase(t, "drop_table: ok", DefaultMysqlInspect(), @@ -768,14 +769,14 @@ DROP TABLE if exists not_exist_db.not_exist_tb_1; ` DROP TABLE not_exist_db.not_exist_tb_1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"), ) runDefaultRulesInspectCase(t, "drop_table: table not exist", DefaultMysqlInspect(), ` DROP TABLE exist_db.not_exist_tb_1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb_1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb_1"), ) runDefaultRulesInspectCase(t, "drop_index: ok", DefaultMysqlInspect(), @@ -789,7 +790,7 @@ DROP INDEX idx_1 ON exist_db.exist_tb_1; ` DROP INDEX idx_2 ON exist_db.exist_tb_1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.IndexNotExistMessage), "idx_2"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.IndexNotExistMessage), "idx_2"), ) runDefaultRulesInspectCase(t, "drop_index: if exists and index not exist", DefaultMysqlInspect(), @@ -805,49 +806,49 @@ func TestCheckInvalidInsert(t *testing.T) { ` insert into not_exist_db.not_exist_tb values (1,"1","1"); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"), ) runDefaultRulesInspectCase(t, "insert: table not exist", DefaultMysqlInspect(), ` insert into exist_db.not_exist_tb values (1,"1","1"); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), ) runDefaultRulesInspectCase(t, "insert: column not exist(1)", DefaultMysqlInspect(), ` insert into exist_db.exist_tb_1 (id,v1,v3) values (1,"1","1"); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v3"), ) runDefaultRulesInspectCase(t, "insert: column not exist(2)", DefaultMysqlInspect(), ` insert into exist_db.exist_tb_1 set id=1,v1="1",v3="1"; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v3"), ) runDefaultRulesInspectCase(t, "insert: column is duplicate(1)", DefaultMysqlInspect(), ` insert into exist_db.exist_tb_1 (id,v1,v1) values (1,"1","1"); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateColumnsMessage), "v1"), ) runDefaultRulesInspectCase(t, "insert: column is duplicate(2)", DefaultMysqlInspect(), ` insert into exist_db.exist_tb_1 set id=1,v1="1",v1="1"; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.DuplicateColumnsMessage), "v1"), ) runDefaultRulesInspectCase(t, "insert: do not match values and columns", DefaultMysqlInspect(), ` insert into exist_db.exist_tb_1 (id,v1,v2) values (1,"1","1"),(2,"2","2","2"); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnsValuesNotMatchMessage)), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnsValuesNotMatchMessage)), ) } @@ -982,28 +983,28 @@ update exist_tb_1 set v1="2" where exist_db.exist_tb_1.id=1; ` update not_exist_db.not_exist_tb set v1="2" where id=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"), ) runDefaultRulesInspectCase(t, "update: table not exist", DefaultMysqlInspect(), ` update exist_db.not_exist_tb set v1="2" where id=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), ) runDefaultRulesInspectCase(t, "update: column not exist", DefaultMysqlInspect(), ` update exist_db.exist_tb_1 set v3="2" where id=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v3"), ) runDefaultRulesInspectCase(t, "update: where column not exist", DefaultMysqlInspect(), ` update exist_db.exist_tb_1 set v1="2" where v3=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v3"), ) runDefaultRulesInspectCase(t, "update with alias: ok", DefaultMysqlInspect(), @@ -1016,28 +1017,28 @@ update exist_tb_1 as t set t.v1 = "1" where t.id = 1; ` update exist_db.not_exist_tb as t set t.v3 = "1" where t.id = 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), ) runDefaultRulesInspectCase(t, "update with alias: column not exist", DefaultMysqlInspect(), ` update exist_tb_1 as t set t.v3 = "1" where t.id = 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "t.v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "t.v3"), ) runDefaultRulesInspectCase(t, "update with alias: column not exist", DefaultMysqlInspect(), ` update exist_tb_1 as t set t.v1 = "1" where t.v3 = 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "t.v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "t.v3"), ) runDefaultRulesInspectCase(t, "update with alias: column not exist", DefaultMysqlInspect(), ` update exist_tb_1 as t set exist_tb_1.v1 = "1" where t.id = 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "exist_tb_1.v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "exist_tb_1.v1"), ) runDefaultRulesInspectCase(t, "multi-update: ok", DefaultMysqlInspect(), @@ -1058,28 +1059,28 @@ update exist_tb_1 inner join exist_tb_2 on exist_tb_1.id = exist_tb_2.id set exi ` update exist_db.not_exist_tb set exist_tb_1.v2 = "1" where exist_tb_1.id = exist_tb_2.id; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), ) runDefaultRulesInspectCase(t, "multi-update: column not exist 1", DefaultMysqlInspect(), ` update exist_tb_1,exist_tb_2 set exist_tb_1.v3 = "1" where exist_tb_1.id = exist_tb_2.id; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "exist_tb_1.v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "exist_tb_1.v3"), ) runDefaultRulesInspectCase(t, "multi-update: column not exist 2", DefaultMysqlInspect(), ` update exist_tb_1,exist_tb_2 set exist_tb_2.v3 = "1" where exist_tb_1.id = exist_tb_2.id; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "exist_tb_2.v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "exist_tb_2.v3"), ) runDefaultRulesInspectCase(t, "multi-update: column not exist 3", DefaultMysqlInspect(), ` update exist_tb_1,exist_tb_2 set exist_tb_1.v1 = "1" where exist_tb_1.v3 = exist_tb_2.v3; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "exist_tb_1.v3,exist_tb_2.v3"). + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "exist_tb_1.v3,exist_tb_2.v3"). addResult(rulepkg.DMLCheckJoinFieldUseIndex), ) @@ -1087,7 +1088,7 @@ update exist_tb_1,exist_tb_2 set exist_tb_1.v1 = "1" where exist_tb_1.v3 = exist ` update exist_db.exist_tb_1,exist_db.exist_tb_2 set exist_tb_3.v1 = "1" where exist_tb_1.v1 = exist_tb_2.v1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "exist_tb_3.v1"). + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "exist_tb_3.v1"). addResult(rulepkg.DMLCheckJoinFieldUseIndex), ) @@ -1095,7 +1096,7 @@ update exist_db.exist_tb_1,exist_db.exist_tb_2 set exist_tb_3.v1 = "1" where exi ` update exist_db.exist_tb_1,exist_db.exist_tb_2 set not_exist_db.exist_tb_1.v1 = "1" where exist_tb_1.v1 = exist_tb_2.v1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "not_exist_db.exist_tb_1.v1"). + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "not_exist_db.exist_tb_1.v1"). addResult(rulepkg.DMLCheckJoinFieldUseIndex), ) @@ -1110,21 +1111,21 @@ update exist_tb_1,exist_tb_2 set user_id = "1" where exist_tb_1.id = exist_tb_2. ` update exist_tb_1,exist_tb_2 set v1 = "1" where exist_tb_1.id = exist_tb_2.id; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnIsAmbiguousMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnIsAmbiguousMessage), "v1"), ) runDefaultRulesInspectCase(t, "multi-update: column not ambiguous", DefaultMysqlInspect(), ` update exist_tb_1,exist_tb_2 set v1 = "1" where exist_tb_1.id = exist_tb_2.id; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnIsAmbiguousMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnIsAmbiguousMessage), "v1"), ) runDefaultRulesInspectCase(t, "multi-update: where column not ambiguous", DefaultMysqlInspect(), ` update exist_tb_1,exist_tb_2 set exist_tb_1.v1 = "1" where v1 = 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnIsAmbiguousMessage), "v1").addResult(rulepkg.DMLCheckHasJoinCondition), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnIsAmbiguousMessage), "v1").addResult(rulepkg.DMLCheckHasJoinCondition), ) } @@ -1140,35 +1141,35 @@ delete from exist_db.exist_tb_1 where id=1; ` delete from not_exist_db.not_exist_tb where id=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"), ) runDefaultRulesInspectCase(t, "delete: table not exist", DefaultMysqlInspect(), ` delete from exist_db.not_exist_tb where id=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb"), ) runDefaultRulesInspectCase(t, "delete: where column not exist", DefaultMysqlInspect(), ` delete from exist_db.exist_tb_1 where v3=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "v3"), ) runDefaultRulesInspectCase(t, "delete: where column not exist", DefaultMysqlInspect(), ` delete from exist_db.exist_tb_1 where exist_tb_1.v3=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "exist_tb_1.v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "exist_tb_1.v3"), ) runDefaultRulesInspectCase(t, "delete: where column not exist", DefaultMysqlInspect(), ` delete from exist_db.exist_tb_1 where exist_tb_2.id=1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "exist_tb_2.id"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.ColumnNotExistMessage), "exist_tb_2.id"), ) } @@ -1177,7 +1178,7 @@ func TestCheckInvalidSelect(t *testing.T) { ` select id from not_exist_db.not_exist_tb where id=1 limit 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db"). + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db"). add(driverV2.RuleLevelNotice, "", "LIMIT 查询建议使用ORDER BY"), ) @@ -1185,7 +1186,7 @@ select id from not_exist_db.not_exist_tb where id=1 limit 1; ` select id from exist_db.not_exist_tb where id=1 limit 1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb"). + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.not_exist_tb"). add(driverV2.RuleLevelNotice, "", "LIMIT 查询建议使用ORDER BY"), ) } @@ -4716,12 +4717,12 @@ func Test_LowerCaseTableNameOpen(t *testing.T) { runEmptyRuleInspectCase(t, "test lower case table name open 1-1", getLowerCaseOpenInspect(), `use not_exist_db;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db")) runEmptyRuleInspectCase(t, "test lower case table name open 1-2", getLowerCaseOpenInspect(), `use NOT_EXIST_DB;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "NOT_EXIST_DB")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "NOT_EXIST_DB")) runEmptyRuleInspectCase(t, "test lower case table name open 1-3", getLowerCaseOpenInspect(), `use EXIST_DB;`, @@ -4740,12 +4741,12 @@ func Test_LowerCaseTableNameOpen(t *testing.T) { runEmptyRuleInspectCase(t, "test lower case table name open 2-1", getLowerCaseOpenInspect(), `create database EXIST_DB;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaExistMessage), "EXIST_DB")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaExistMessage), "EXIST_DB")) runEmptyRuleInspectCase(t, "test lower case table name open 2-2", getLowerCaseOpenInspect(), `create database exist_db;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaExistMessage), "exist_db")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaExistMessage), "exist_db")) runEmptyRuleInspectCase(t, "test lower case table name open 2-3", getLowerCaseOpenInspect(), `create database not_exist_db;`, @@ -4760,45 +4761,45 @@ func Test_LowerCaseTableNameOpen(t *testing.T) { create database NOT_EXIST_DB;`, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaExistMessage), "NOT_EXIST_DB")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaExistMessage), "NOT_EXIST_DB")) runEmptyRuleInspectCase(t, "test lower case table name open 2-6", getLowerCaseOpenInspect(), `create database NOT_EXIST_DB; create database not_exist_db;`, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaExistMessage), "not_exist_db")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaExistMessage), "not_exist_db")) } // check table { runEmptyRuleInspectCase(t, "test lower case table name open 3-1", getLowerCaseOpenInspect(), `create table EXIST_DB.exist_tb_1 (id int);`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableExistMessage), "EXIST_DB.exist_tb_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableExistMessage), "EXIST_DB.exist_tb_1")) runEmptyRuleInspectCase(t, "test lower case table name open 3-2", getLowerCaseOpenInspect(), `create table exist_db.exist_tb_1 (id int);`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableExistMessage), "exist_db.exist_tb_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableExistMessage), "exist_db.exist_tb_1")) runEmptyRuleInspectCase(t, "test lower case table name open 3-3", getLowerCaseOpenInspect(), `create table EXIST_DB.EXIST_TB_1 (id int);`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableExistMessage), "EXIST_DB.EXIST_TB_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableExistMessage), "EXIST_DB.EXIST_TB_1")) runEmptyRuleInspectCase(t, "test lower case table name open 3-4", getLowerCaseOpenInspect(), `create table EXIST_DB.EXIST_TB_2 (id int); create table EXIST_DB.exist_tb_2 (id int);`, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableExistMessage), "EXIST_DB.exist_tb_2")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableExistMessage), "EXIST_DB.exist_tb_2")) runEmptyRuleInspectCase(t, "test lower case table name open 3-5", getLowerCaseOpenInspect(), `create table EXIST_DB.exist_tb_2 (id int); create table EXIST_DB.EXIST_TB_2 (id int);`, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableExistMessage), "EXIST_DB.EXIST_TB_2")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableExistMessage), "EXIST_DB.EXIST_TB_2")) runEmptyRuleInspectCase(t, "test lower case table name open 3-6", getLowerCaseOpenInspect(), `alter table exist_db.EXIST_TB_1 add column v3 varchar(255) COMMENT "unit test";`, @@ -4810,7 +4811,7 @@ alter table exist_db.EXIST_TB_1 add column v3 varchar(255) COMMENT "unit test"; `, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.EXIST_TB_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.EXIST_TB_1")) runEmptyRuleInspectCase(t, "test lower case table name open 3-8", getLowerCaseOpenInspect(), `alter table exist_db.EXIST_TB_1 rename AS exist_tb_2; @@ -4832,12 +4833,12 @@ alter table exist_db.EXIST_TB_2 add column v3 varchar(255) COMMENT "unit test"; runEmptyRuleInspectCase(t, "test lower case table name open 4-1", getLowerCaseOpenInspect(), `select id from exist_db.EXIST_TB_2 where id = 1;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.EXIST_TB_2")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.EXIST_TB_2")) runEmptyRuleInspectCase(t, "test lower case table name open 4-2", getLowerCaseOpenInspect(), `select id from exist_db.exist_tb_2 where id = 1;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.exist_tb_2")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db.exist_tb_2")) runEmptyRuleInspectCase(t, "test lower case table name open 4-3", getLowerCaseOpenInspect(), `select id from exist_db.EXIST_TB_1 where id = 1;`, newTestResult()) @@ -4858,12 +4859,12 @@ func Test_LowerCaseTableNameClose(t *testing.T) { runEmptyRuleInspectCase(t, "test lower case table name close 1-1", getLowerCaseCloseInspect(), `use not_exist_db;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "not_exist_db")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "not_exist_db")) runEmptyRuleInspectCase(t, "test lower case table name close 1-2", getLowerCaseCloseInspect(), `use NOT_EXIST_DB;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "NOT_EXIST_DB")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "NOT_EXIST_DB")) runEmptyRuleInspectCase(t, "test lower case table name close 1-3", getLowerCaseCloseInspect(), `use exist_db_1;`, @@ -4872,12 +4873,12 @@ func Test_LowerCaseTableNameClose(t *testing.T) { runEmptyRuleInspectCase(t, "test lower case table name close 1-4", getLowerCaseCloseInspect(), `use EXIST_DB_1;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "EXIST_DB_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "EXIST_DB_1")) runEmptyRuleInspectCase(t, "test lower case table name close 1-5", getLowerCaseCloseInspect(), `use exist_DB_1;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "exist_DB_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "exist_DB_1")) runEmptyRuleInspectCase(t, "test lower case table name close 1-6", getLowerCaseCloseInspect(), `use EXIST_DB_2;`, @@ -4886,14 +4887,14 @@ func Test_LowerCaseTableNameClose(t *testing.T) { runEmptyRuleInspectCase(t, "test lower case table name close 1-7", getLowerCaseCloseInspect(), `use exist_db_2;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaNotExistMessage), "exist_db_2")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaNotExistMessage), "exist_db_2")) } // check schema { runEmptyRuleInspectCase(t, "test lower case table name close 2-1", getLowerCaseCloseInspect(), `create database exist_db_1;`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaExistMessage), "exist_db_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaExistMessage), "exist_db_1")) runEmptyRuleInspectCase(t, "test lower case table name close 2-2", getLowerCaseCloseInspect(), `create database EXIST_DB_1;`, @@ -4914,14 +4915,14 @@ create database not_exist_db;`, create database NOT_EXIST_DB;`, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.SchemaExistMessage), "NOT_EXIST_DB")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.SchemaExistMessage), "NOT_EXIST_DB")) } // check table { runEmptyRuleInspectCase(t, "test lower case table name close 3-1", getLowerCaseCloseInspect(), `create table exist_db_1.exist_tb_1 (id int);`, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableExistMessage), "exist_db_1.exist_tb_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableExistMessage), "exist_db_1.exist_tb_1")) runEmptyRuleInspectCase(t, "test lower case table name close 3-2", getLowerCaseCloseInspect(), `create table exist_db_1.EXIST_TB_1 (id int);`, @@ -4931,7 +4932,7 @@ create database NOT_EXIST_DB;`, `alter table exist_db_1.EXIST_TB_1 rename AS exist_tb_2; `, newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db_1.EXIST_TB_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db_1.EXIST_TB_1")) runEmptyRuleInspectCase(t, "test lower case table name close 3-4", getLowerCaseCloseInspect(), `alter table exist_db_1.exist_tb_1 rename AS exist_tb_2; @@ -4939,7 +4940,7 @@ alter table exist_db_1.exist_tb_1 add column v3 varchar(255) COMMENT "unit test" `, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db_1.exist_tb_1")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db_1.exist_tb_1")) runEmptyRuleInspectCase(t, "test lower case table name close 3-5", getLowerCaseCloseInspect(), `alter table exist_db_1.exist_tb_1 rename AS exist_tb_2; @@ -4954,7 +4955,7 @@ alter table exist_db_1.EXIST_TB_2 add column v3 varchar(255) COMMENT "unit test" `, newTestResult(), newTestResult().add(driverV2.RuleLevelError, "", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db_1.EXIST_TB_2")) + plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, plocale.TableNotExistMessage), "exist_db_1.EXIST_TB_2")) } } @@ -7164,7 +7165,7 @@ func TestMustMatchLeftMostPrefix(t *testing.T) { t.Run(arg.Name, func(t *testing.T) { res := newTestResult() if arg.TriggerRule { - res = newTestResult().add(rule.Level, rule.Name, plocale.ShouldLocalizeMsgByLang(language.Chinese, rulepkg.RuleHandlerMap[rulepkg.DMLMustMatchLeftMostPrefix].Message)) + res = newTestResult().add(rule.Level, rule.Name, plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, rulepkg.RuleHandlerMap[rulepkg.DMLMustMatchLeftMostPrefix].Message)) } runSingleRuleInspectCase(rulepkg.RuleHandlerMap[rulepkg.DMLMustMatchLeftMostPrefix].Rule, t, "", inspect, arg.Sql, res) }) @@ -7443,7 +7444,7 @@ func TestMustUseLeftMostPrefix(t *testing.T) { t.Run(arg.Name, func(t *testing.T) { res := newTestResult() if arg.TriggerRule { - res = newTestResult().add(rule.Level, rule.Name, plocale.ShouldLocalizeMsgByLang(language.Chinese, rulepkg.RuleHandlerMap[rulepkg.DMLMustUseLeftMostPrefix].Message)) + res = newTestResult().add(rule.Level, rule.Name, plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, rulepkg.RuleHandlerMap[rulepkg.DMLMustUseLeftMostPrefix].Message)) } runSingleRuleInspectCase(rulepkg.RuleHandlerMap[rulepkg.DMLMustUseLeftMostPrefix].Rule, t, "", inspect, arg.Sql, res) }) @@ -7670,7 +7671,7 @@ func TestDDLCheckCharLength(t *testing.T) { t.Run(arg.Name, func(t *testing.T) { res := newTestResult() if arg.TriggerRule { - res = newTestResult().add(rule.Level, rule.Name, plocale.ShouldLocalizeMsgByLang(language.Chinese, rulepkg.RuleHandlerMap[rulepkg.DDLCheckCharLength].Message), arg.Param) + res = newTestResult().add(rule.Level, rule.Name, plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, rulepkg.RuleHandlerMap[rulepkg.DDLCheckCharLength].Message), arg.Param) } runSingleRuleInspectCase(rulepkg.RuleHandlerMap[rulepkg.DDLCheckCharLength].Rule, t, "", inspect, arg.Sql, res) }) diff --git a/sqle/driver/mysql/context_test.go b/sqle/driver/mysql/context_test.go index cf093bc60..7eea09bb3 100644 --- a/sqle/driver/mysql/context_test.go +++ b/sqle/driver/mysql/context_test.go @@ -40,7 +40,7 @@ alter table not_exist_tb_1 drop column v1; newTestResult().addResult(rulepkg.DDLCheckPKName), newTestResult(), newTestResult(), - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb_1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.TableNotExistMessage), "exist_db.not_exist_tb_1"), ) runDefaultRulesInspectCase(t, "drop column twice: column not exists(1)", DefaultMysqlInspect(), @@ -51,7 +51,7 @@ alter table not_exist_tb_1 drop column v1; `, newTestResult(), newTestResult(), - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), ) runDefaultRulesInspectCase(t, "drop column twice: column not exists(2)", DefaultMysqlInspect(), ` @@ -70,7 +70,7 @@ alter table not_exist_tb_1 drop column v1; newTestResult(), newTestResult().addResult(rulepkg.DDLCheckPKName), newTestResult(), - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), ) runDefaultRulesInspectCase(t, "change and drop column: column not exists", DefaultMysqlInspect(), @@ -81,7 +81,7 @@ alter table not_exist_tb_1 drop column v1; `, newTestResult(), newTestResult(), - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), ) runDefaultRulesInspectCase(t, "Add column twice: column exists", DefaultMysqlInspect(), @@ -92,7 +92,7 @@ alter table not_exist_tb_1 drop column v1; `, newTestResult(), newTestResult(), - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnExistMessage), "v3"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.ColumnExistMessage), "v3"), ) runDefaultRulesInspectCase(t, "drop index twice: index not exists", DefaultMysqlInspect(), @@ -103,7 +103,7 @@ alter table not_exist_tb_1 drop column v1; `, newTestResult(), newTestResult(), - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.IndexNotExistMessage), "idx_1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.IndexNotExistMessage), "idx_1"), ) runDefaultRulesInspectCase(t, "drop index, rename index: index not exists", DefaultMysqlInspect(), ` @@ -113,7 +113,7 @@ alter table not_exist_tb_1 drop column v1; `, newTestResult(), newTestResult(), - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.IndexNotExistMessage), "idx_1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.IndexNotExistMessage), "idx_1"), ) } @@ -160,7 +160,7 @@ alter table not_exist_tb_1 drop column v1; ` alter table not_exist_tb_1 drop column v1; `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), ) inspect4 := DefaultMysqlInspect() @@ -178,7 +178,7 @@ alter table not_exist_tb_1 add column v3 varchar(255) NOT NULL DEFAULT "unit tes ` insert into not_exist_tb_1 (id,v1,v2) values (1,"1","1"); `, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.ColumnNotExistMessage), "v1"), ) inspect6 := DefaultMysqlInspect() diff --git a/sqle/driver/mysql/invalid_offline_test.go b/sqle/driver/mysql/invalid_offline_test.go index 41bbd8b8e..546b900d6 100644 --- a/sqle/driver/mysql/invalid_offline_test.go +++ b/sqle/driver/mysql/invalid_offline_test.go @@ -18,50 +18,50 @@ func TestCheckInvalidOffline(t *testing.T) { func testCheckInvalidCreateTableOffline(t *testing.T) { runEmptyRuleInspectCase(t, "column name can't duplicated. f", DefaultMysqlInspectOffline(), `create table t (a int,b int, a int)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "a")) runEmptyRuleInspectCase(t, "column name can't duplicated. t", DefaultMysqlInspectOffline(), `create table t (a int,b int)`, newTestResult()) runEmptyRuleInspectCase(t, "pk can only be set once. f1", DefaultMysqlInspectOffline(), `create table t (a int primary key,b int primary key)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) runEmptyRuleInspectCase(t, "pk can only be set once. f2", DefaultMysqlInspectOffline(), "create table t (a int primary key,b int, PRIMARY KEY (`b`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) runEmptyRuleInspectCase(t, "pk can only be set once. f3", DefaultMysqlInspectOffline(), "create table t (a int primary key,b int, PRIMARY KEY (`a`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) runEmptyRuleInspectCase(t, "pk can only be set once. f4", DefaultMysqlInspectOffline(), "create table t (a int ,b int, PRIMARY KEY (`a`), PRIMARY KEY (`b`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.MultiPrimaryKeyMessage))) runEmptyRuleInspectCase(t, "pk can only be set once. t", DefaultMysqlInspectOffline(), `create table t (a int,b int primary key)`, newTestResult()) runEmptyRuleInspectCase(t, "index name can't be duplicated. f1", DefaultMysqlInspectOffline(), "create table t (a int ,b int , KEY `a` (`a`), KEY `a` (`b`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexesMessage), "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexesMessage), "a")) runEmptyRuleInspectCase(t, "index name can't be duplicated. f2", DefaultMysqlInspectOffline(), "create table t (a int ,b int , unique `a`(`a`), KEY `a`(`b`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexesMessage), "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexesMessage), "a")) runEmptyRuleInspectCase(t, "index name can't be duplicated. t", DefaultMysqlInspectOffline(), "create table t (a int ,b int , unique `a`(`a`), KEY `b`(`b`))", newTestResult()) runEmptyRuleInspectCase(t, "index column must exist. f1", DefaultMysqlInspectOffline(), "create table t (a int ,b int , unique `a`(`c`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), "c")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), "c")) runEmptyRuleInspectCase(t, "index column must exist. f2", DefaultMysqlInspectOffline(), "create table t (a int ,b int , unique `a`(`a`,`c`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), "c")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.KeyedColumnNotExistMessage), "c")) runEmptyRuleInspectCase(t, "index column must exist. t", DefaultMysqlInspectOffline(), "create table t (a int ,b int , unique `a`(`b`))", newTestResult()) runEmptyRuleInspectCase(t, "index column can't duplicated. f", DefaultMysqlInspectOffline(), "create table t (a int ,b int , index `idx`(`a`,`a`))", - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx", "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx", "a")) runEmptyRuleInspectCase(t, "index column can't duplicated. t", DefaultMysqlInspectOffline(), "create table t (a int ,b int , index `idx`(`a`,`b`))", newTestResult()) @@ -71,10 +71,10 @@ func testCheckInvalidCreateTableOffline(t *testing.T) { func testCheckInvalidAlterTableOffline(t *testing.T) { runEmptyRuleInspectCase(t, "add pk, ok can only be set once. f1", DefaultMysqlInspectOffline(), `alter table t add (a int primary key, b int primary key)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PrimaryKeyExistMessage))) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.PrimaryKeyExistMessage))) runEmptyRuleInspectCase(t, "add pk, ok can only be set once. f2", DefaultMysqlInspectOffline(), `alter table t add primary key (a), add primary key (b)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PrimaryKeyExistMessage))) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.PrimaryKeyExistMessage))) runEmptyRuleInspectCase(t, "add pk, ok can only be set once. t1", DefaultMysqlInspectOffline(), `alter table t add primary key (a), add index (b)`, newTestResult()) @@ -84,10 +84,10 @@ func testCheckInvalidAlterTableOffline(t *testing.T) { runEmptyRuleInspectCase(t, "index column can't duplicated. f1", DefaultMysqlInspectOffline(), `alter table t add index b(a,a)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "b", "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "b", "a")) runEmptyRuleInspectCase(t, "index column can't duplicated. f2", DefaultMysqlInspectOffline(), `alter table t add primary key a(a,a)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicatePrimaryKeyedColumnMessage), "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicatePrimaryKeyedColumnMessage), "a")) runEmptyRuleInspectCase(t, "index column can't duplicated. t", DefaultMysqlInspectOffline(), `alter table t add index a(a,b), add index b(b,c)`, newTestResult()) @@ -97,7 +97,7 @@ func testCheckInvalidAlterTableOffline(t *testing.T) { func testCheckInvalidCreateIndexOffline(t *testing.T) { runEmptyRuleInspectCase(t, "index column name can't be duplicated. f", DefaultMysqlInspectOffline(), `create index idx on t (a,a)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx", "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateIndexedColumnMessage), "idx", "a")) runEmptyRuleInspectCase(t, "index column name can't be duplicated. t", DefaultMysqlInspectOffline(), `create index idx on t (a,b)`, newTestResult()) @@ -106,10 +106,10 @@ func testCheckInvalidCreateIndexOffline(t *testing.T) { func testCheckInvalidInsertOffline(t *testing.T) { runEmptyRuleInspectCase(t, "index column can't be duplicated. f1", DefaultMysqlInspectOffline(), `insert into t (a,a) value (1,1)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "a")) runEmptyRuleInspectCase(t, "index column can't be duplicated. f2", DefaultMysqlInspectOffline(), `insert into t set a=1, a=1`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "a")) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.DuplicateColumnsMessage), "a")) runEmptyRuleInspectCase(t, "index column can't be duplicated. t1", DefaultMysqlInspectOffline(), `insert into t set a=1, b=1`, newTestResult()) @@ -119,7 +119,7 @@ func testCheckInvalidInsertOffline(t *testing.T) { runEmptyRuleInspectCase(t, "value length must match column length. f", DefaultMysqlInspectOffline(), `insert into t (a,b) value (1,1,1)`, - newTestResult().add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.ColumnsValuesNotMatchMessage))) + newTestResult().add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.ColumnsValuesNotMatchMessage))) runEmptyRuleInspectCase(t, "value length must match column length. t1", DefaultMysqlInspectOffline(), `insert into t (a,b) value (1,1)`, newTestResult()) diff --git a/sqle/driver/mysql/mysql.go b/sqle/driver/mysql/mysql.go index 049b04d61..bdbab3a6b 100644 --- a/sqle/driver/mysql/mysql.go +++ b/sqle/driver/mysql/mysql.go @@ -7,13 +7,11 @@ import ( "fmt" "strings" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver" "github.com/actiontech/sqle/sqle/driver/mysql/executor" "github.com/actiontech/sqle/sqle/driver/mysql/onlineddl" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" - "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" - rulepkg "github.com/actiontech/sqle/sqle/driver/mysql/rule" "github.com/actiontech/sqle/sqle/driver/mysql/session" "github.com/actiontech/sqle/sqle/driver/mysql/util" @@ -350,7 +348,7 @@ func (i *MysqlDriverImpl) audit(ctx context.Context, sql string) (*driverV2.Audi i.Logger().Errorf("check invalid failed: %v", err) i.result.Add(driverV2.RuleLevelWarn, "pre_check_err", // todo i18n 预检查失败规则名称 - plocale.ShouldLocalizeAllWithFmt(plocale.CheckInvalidErrorFormat, plocale.ParseDDLError), + plocale.Bundle.LocalizeAllWithArgs(plocale.CheckInvalidErrorFormat, plocale.ParseDDLError), ) } else if err != nil { return nil, err @@ -399,7 +397,7 @@ func (i *MysqlDriverImpl) audit(ctx context.Context, sql string) (*driverV2.Audi if err := handler.Func(input); err != nil { // todo #1630 临时跳过解析建表语句失败导致的规则 if session.IsParseShowCreateTableContentErr(err) { - i.Logger().Errorf("skip rule, rule_desc_name=%v rule_desc=%v err:%v", rule.Name, rule.I18nRuleInfo[locale.DefaultLang].Desc, err.Error()) + i.Logger().Errorf("skip rule, rule_desc_name=%v rule_desc=%v err:%v", rule.Name, rule.I18nRuleInfo[i18nPkg.DefaultLang].Desc, err.Error()) continue } return nil, err @@ -437,9 +435,9 @@ func (i *MysqlDriverImpl) audit(ctx context.Context, sql string) (*driverV2.Audi if useGhost { if _, err := i.executeByGhost(ctx, sql, true); err != nil { // todo - i.result.Add(driverV2.RuleLevelError, ghostRule.Name, plocale.ShouldLocalizeAll(plocale.GhostDryRunError), i.cnf.DDLGhostMinSize, err) + i.result.Add(driverV2.RuleLevelError, ghostRule.Name, plocale.Bundle.LocalizeAll(plocale.GhostDryRunError), i.cnf.DDLGhostMinSize, err) } else { - i.result.Add(ghostRule.Level, ghostRule.Name, plocale.ShouldLocalizeAll(plocale.GhostDryRunNotice), i.cnf.DDLGhostMinSize) + i.result.Add(ghostRule.Level, ghostRule.Name, plocale.Bundle.LocalizeAll(plocale.GhostDryRunNotice), i.cnf.DDLGhostMinSize) } } diff --git a/sqle/driver/mysql/mysql_test.go b/sqle/driver/mysql/mysql_test.go index 7e17a5391..1a435185f 100644 --- a/sqle/driver/mysql/mysql_test.go +++ b/sqle/driver/mysql/mysql_test.go @@ -4,9 +4,9 @@ import ( "context" "testing" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/util" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" - "github.com/actiontech/sqle/sqle/locale" "github.com/stretchr/testify/assert" ) @@ -165,17 +165,17 @@ func TestInspect_GenRollbackSQL(t *testing.T) { rollback, reason, err := i.GenRollbackSQL(context.TODO(), "create table t1(id int, c1 int)") assert.NoError(t, err) - assert.Equal(t, "", reason[locale.DefaultLang]) + assert.Equal(t, "", reason[i18nPkg.DefaultLang]) assert.Equal(t, "DROP TABLE IF EXISTS `exist_db`.`t1`", rollback) rollback, reason, err = i.GenRollbackSQL(context.TODO(), "alter table t1 drop column c1") assert.NoError(t, err) - assert.Equal(t, "", reason[locale.DefaultLang]) + assert.Equal(t, "", reason[i18nPkg.DefaultLang]) assert.Equal(t, "ALTER TABLE `exist_db`.`t1`\nADD COLUMN `c1` int(11);", rollback) rollback, reason, err = i.GenRollbackSQL(context.TODO(), "alter table t1 add column c1 int") assert.NoError(t, err) - assert.Equal(t, "", reason[locale.DefaultLang]) + assert.Equal(t, "", reason[i18nPkg.DefaultLang]) assert.Equal(t, "ALTER TABLE `exist_db`.`t1`\nDROP COLUMN `c1`;", rollback) } func TestInspect_assertSQLType(t *testing.T) { diff --git a/sqle/driver/mysql/plocale/locale.go b/sqle/driver/mysql/plocale/locale.go index dc31a8169..3cfa28461 100644 --- a/sqle/driver/mysql/plocale/locale.go +++ b/sqle/driver/mysql/plocale/locale.go @@ -3,10 +3,8 @@ package plocale import ( "embed" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/log" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" - "github.com/nicksnyder/go-i18n/v2/i18n" - "golang.org/x/text/language" ) //go:embed active.*.toml @@ -21,26 +19,3 @@ func init() { } Bundle = b } - -// todo i18n 把调用下列函数的地方改成直接使用 Bundle对应方法 - -// ShouldLocalizeMsgByLang todo i18n MySQL插件用到这个函数的地方应该都没完成国际化(低优先级) -func ShouldLocalizeMsgByLang(lang language.Tag, msg *i18n.Message) string { - return Bundle.ShouldLocalizeMsgByLang(lang, msg) -} - -func ShouldLocalizeAll(msg *i18n.Message) i18nPkg.I18nStr { - return Bundle.ShouldLocalizeAll(msg) -} - -func ShouldLocalizeAllWithArgs(msg *i18n.Message, args ...any) i18nPkg.I18nStr { - return Bundle.ShouldLocalizeAllWithArgs(msg, args...) -} - -func ShouldLocalizeAllWithFmt(fmtMsg *i18n.Message, msg ...*i18n.Message) i18nPkg.I18nStr { - return Bundle.ShouldLocalizeAllWithMsgArgs(fmtMsg, msg...) -} - -func ConvertStr2I18n(s string) i18nPkg.I18nStr { - return i18nPkg.ConvertStr2I18nAsDefaultLang(s) -} diff --git a/sqle/driver/mysql/pt_osc.go b/sqle/driver/mysql/pt_osc.go index c7d50a632..afb2fb18e 100644 --- a/sqle/driver/mysql/pt_osc.go +++ b/sqle/driver/mysql/pt_osc.go @@ -9,9 +9,9 @@ import ( "sync" "text/template" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" "github.com/actiontech/sqle/sqle/driver/mysql/util" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/pingcap/parser/ast" ) @@ -61,12 +61,12 @@ func (i *MysqlDriverImpl) generateOSCCommandLine(node ast.Node) (i18nPkg.I18nStr // This is necessary because the tool creates a DELETE trigger to keep the new table // updated while the process is running. if !util.HasPrimaryKey(createTableStmt) && !util.HasUniqIndex(createTableStmt) { - return plocale.ShouldLocalizeAll(plocale.PTOSCNoUniqueIndexOrPrimaryKey), nil + return plocale.Bundle.LocalizeAll(plocale.PTOSCNoUniqueIndexOrPrimaryKey), nil } // The RENAME clause cannot be used to rename the table. if len(util.GetAlterTableSpecByTp(stmt.Specs, ast.AlterTableRenameTable)) > 0 { - return plocale.ShouldLocalizeAll(plocale.PTOSCAvoidRenameTable), nil + return plocale.Bundle.LocalizeAll(plocale.PTOSCAvoidRenameTable), nil } // If you add a column without a default value and make it NOT NULL, the tool will fail, @@ -75,7 +75,7 @@ func (i *MysqlDriverImpl) generateOSCCommandLine(node ast.Node) (i18nPkg.I18nStr for _, col := range spec.NewColumns { if util.HasOneInOptions(col.Options, ast.ColumnOptionNotNull) { if !util.HasOneInOptions(col.Options, ast.ColumnOptionDefaultValue) { - return plocale.ShouldLocalizeAll(plocale.PTOSCAvoidNoDefaultValueOnNotNullColumn), nil + return plocale.Bundle.LocalizeAll(plocale.PTOSCAvoidNoDefaultValueOnNotNullColumn), nil } } } @@ -87,7 +87,7 @@ func (i *MysqlDriverImpl) generateOSCCommandLine(node ast.Node) (i18nPkg.I18nStr for _, spec := range util.GetAlterTableSpecByTp(stmt.Specs, ast.AlterTableAddConstraint) { switch spec.Constraint.Tp { case ast.ConstraintUniq: - return plocale.ShouldLocalizeAll(plocale.PTOSCAvoidUniqueIndex), nil + return plocale.Bundle.LocalizeAll(plocale.PTOSCAvoidUniqueIndex), nil } } diff --git a/sqle/driver/mysql/pt_osc_test.go b/sqle/driver/mysql/pt_osc_test.go index 6258d9a1a..49abd4db1 100644 --- a/sqle/driver/mysql/pt_osc_test.go +++ b/sqle/driver/mysql/pt_osc_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" "github.com/actiontech/sqle/sqle/driver/mysql/util" - "github.com/actiontech/sqle/sqle/locale" "github.com/stretchr/testify/assert" "golang.org/x/text/language" ) @@ -16,19 +16,19 @@ func TestPTOSC(t *testing.T) { runOSCCase(t, "add column not null no default", "alter table exist_tb_1 add column v3 varchar(255) NOT NULL;", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PTOSCAvoidNoDefaultValueOnNotNullColumn)) + plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.PTOSCAvoidNoDefaultValueOnNotNullColumn)) runOSCCase(t, "not pk and unique key", "alter table exist_tb_3 add column v3 varchar(255);", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PTOSCNoUniqueIndexOrPrimaryKey)) + plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.PTOSCNoUniqueIndexOrPrimaryKey)) runOSCCase(t, "rename table", "alter table exist_tb_1 rename as not_exist_tb_1;", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PTOSCAvoidRenameTable)) + plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.PTOSCAvoidRenameTable)) runOSCCase(t, "add unique index", "alter table exist_tb_1 add unique index u_1 (v1) ", - plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.PTOSCAvoidUniqueIndex)) + plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.PTOSCAvoidUniqueIndex)) runOSCCase(t, "add column ok", "alter table exist_tb_1 add column v3 varchar(255);", @@ -60,5 +60,5 @@ func runOSCCase(t *testing.T, desc string, sql, expect string) { t.Error(err) return } - assert.Equal(t, expect, actual[locale.DefaultLang], desc) + assert.Equal(t, expect, actual[i18nPkg.DefaultLang], desc) } diff --git a/sqle/driver/mysql/rollback.go b/sqle/driver/mysql/rollback.go index 4f89e469a..0d596db4a 100644 --- a/sqle/driver/mysql/rollback.go +++ b/sqle/driver/mysql/rollback.go @@ -7,8 +7,8 @@ import ( "strconv" "strings" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/util" "github.com/actiontech/sqle/sqle/errors" @@ -55,13 +55,13 @@ func (i *MysqlDriverImpl) GenerateDMLStmtRollbackSql(node ast.Node) (rollbackSql paramMarkerChecker := util.ParamMarkerChecker{} node.Accept(¶mMarkerChecker) if paramMarkerChecker.HasParamMarker { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportParamMarkerStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportParamMarkerStatementRollback), nil } hasVarChecker := util.HasVarChecker{} node.Accept(&hasVarChecker) if hasVarChecker.HasVar { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportHasVariableRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportHasVariableRollback), nil } switch stmt := node.(type) { @@ -350,7 +350,7 @@ func (i *MysqlDriverImpl) generateDropIndexRollbackSql(stmt *ast.DropIndexStmt) sql = fmt.Sprintf("CREATE UNIQUE INDEX `%s` ON %s", indexName, i.getTableNameWithQuote(stmt.Table)) default: - return "", plocale.ShouldLocalizeAll(plocale.NotSupportStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportStatementRollback), nil } if constraint.Option != nil { sql = fmt.Sprintf("%s %s", sql, util.IndexOptionFormat(constraint.Option)) @@ -366,10 +366,10 @@ func (i *MysqlDriverImpl) generateInsertRollbackSql(stmt *ast.InsertStmt) (strin tables := util.GetTables(stmt.Table.TableRefs) // table just has one in insert stmt. if len(tables) != 1 { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportMultiTableStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportMultiTableStatementRollback), nil } if stmt.OnDuplicate != nil { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportOnDuplicatStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportOnDuplicatStatementRollback), nil } table := tables[0] createTableStmt, exist, err := i.Ctx.GetCreateTableStmt(table) @@ -385,7 +385,7 @@ func (i *MysqlDriverImpl) generateInsertRollbackSql(stmt *ast.InsertStmt) (strin return "", nil, err } if !hasPk { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportNoPrimaryKeyTableRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportNoPrimaryKeyTableRollback), nil } rollbackSql := "" @@ -394,7 +394,7 @@ func (i *MysqlDriverImpl) generateInsertRollbackSql(stmt *ast.InsertStmt) (strin // match "insert into table_name value (v1,...)" if stmt.Lists != nil { if int64(len(stmt.Lists)) > i.cnf.DMLRollbackMaxRows { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil } columnsName := []string{} if stmt.Columns != nil { @@ -419,7 +419,7 @@ func (i *MysqlDriverImpl) generateInsertRollbackSql(stmt *ast.InsertStmt) (strin } } if len(where) != len(pkColumnsName) { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportInsertWithoutPrimaryKeyRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportInsertWithoutPrimaryKeyRollback), nil } rollbackSql += fmt.Sprintf("DELETE FROM %s WHERE %s;\n", i.getTableNameWithQuote(table), strings.Join(where, " AND ")) @@ -430,7 +430,7 @@ func (i *MysqlDriverImpl) generateInsertRollbackSql(stmt *ast.InsertStmt) (strin // match "insert into table_name set col_name = value1, ..." if stmt.Setlist != nil { if 1 > i.cnf.DMLRollbackMaxRows { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil } where := []string{} for _, setExpr := range stmt.Setlist { @@ -460,12 +460,12 @@ func (i *MysqlDriverImpl) generateDeleteRollbackSql(stmt *ast.DeleteStmt) (strin // not support multi-table syntax if stmt.IsMultiTable { i.Logger().Infof("not support generate rollback sql with multi-delete statement") - return "", plocale.ShouldLocalizeAll(plocale.NotSupportMultiTableStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportMultiTableStatementRollback), nil } // sub query statement if util.WhereStmtHasSubQuery(stmt.Where) { i.Logger().Infof("not support generate rollback sql with sub query") - return "", plocale.ShouldLocalizeAll(plocale.NotSupportSubQueryStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportSubQueryStatementRollback), nil } var err error tables := util.GetTables(stmt.TableRefs.TableRefs) @@ -479,7 +479,7 @@ func (i *MysqlDriverImpl) generateDeleteRollbackSql(stmt *ast.DeleteStmt) (strin return "", nil, err } if !hasPk { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportNoPrimaryKeyTableRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportNoPrimaryKeyTableRollback), nil } var max = i.cnf.DMLRollbackMaxRows @@ -493,7 +493,7 @@ func (i *MysqlDriverImpl) generateDeleteRollbackSql(stmt *ast.DeleteStmt) (strin return "", nil, err } if count > max { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil } } records, err := i.getRecords(table, "", stmt.Where, stmt.Order, limit) @@ -543,12 +543,12 @@ func (i *MysqlDriverImpl) generateUpdateRollbackSql(stmt *ast.UpdateStmt) (strin // multi table syntax if len(tableSources) != 1 { i.Logger().Infof("not support generate rollback sql with multi-update statement") - return "", plocale.ShouldLocalizeAll(plocale.NotSupportMultiTableStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportMultiTableStatementRollback), nil } // sub query statement if util.WhereStmtHasSubQuery(stmt.Where) { i.Logger().Infof("not support generate rollback sql with sub query") - return "", plocale.ShouldLocalizeAll(plocale.NotSupportSubQueryStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportSubQueryStatementRollback), nil } var ( table *ast.TableName @@ -561,9 +561,9 @@ func (i *MysqlDriverImpl) generateUpdateRollbackSql(stmt *ast.UpdateStmt) (strin tableAlias = tableSource.AsName.String() case *ast.SelectStmt, *ast.UnionStmt: i.Logger().Infof("not support generate rollback sql with update-select statement") - return "", plocale.ShouldLocalizeAll(plocale.NotSupportSubQueryStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportSubQueryStatementRollback), nil default: - return "", plocale.ShouldLocalizeAll(plocale.NotSupportStatementRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportStatementRollback), nil } createTableStmt, exist, err := i.Ctx.GetCreateTableStmt(table) if err != nil || !exist { @@ -574,7 +574,7 @@ func (i *MysqlDriverImpl) generateUpdateRollbackSql(stmt *ast.UpdateStmt) (strin return "", nil, err } if !hasPk { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportNoPrimaryKeyTableRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportNoPrimaryKeyTableRollback), nil } var max = i.cnf.DMLRollbackMaxRows @@ -588,7 +588,7 @@ func (i *MysqlDriverImpl) generateUpdateRollbackSql(stmt *ast.UpdateStmt) (strin return "", nil, err } if count > max { - return "", plocale.ShouldLocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil + return "", plocale.Bundle.LocalizeAll(plocale.NotSupportExceedMaxRowsRollback), nil } } records, err := i.getRecords(table, tableAlias, stmt.Where, stmt.Order, limit) diff --git a/sqle/driver/mysql/rollback_test.go b/sqle/driver/mysql/rollback_test.go index aedc0dba6..0a044be1c 100644 --- a/sqle/driver/mysql/rollback_test.go +++ b/sqle/driver/mysql/rollback_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" - "github.com/actiontech/sqle/sqle/locale" "golang.org/x/text/language" "github.com/actiontech/sqle/sqle/driver/mysql/util" @@ -42,7 +42,7 @@ func TestRollbackWithVariable(t *testing.T) { i := DefaultMysqlInspect() rollbackSQL, reason, err := i.GenRollbackSQL(context.Background(), sql) assert.NoError(t, err) - assert.Equal(t, plocale.ShouldLocalizeMsgByLang(language.Chinese, plocale.NotSupportHasVariableRollback), reason[locale.DefaultLang]) + assert.Equal(t, plocale.Bundle.LocalizeMsgByLang(language.Chinese, plocale.NotSupportHasVariableRollback), reason[i18nPkg.DefaultLang]) assert.Equal(t, "", rollbackSQL) } } diff --git a/sqle/driver/mysql/rule/rule.go b/sqle/driver/mysql/rule/rule.go index 3c7a9ac2c..bece9492c 100644 --- a/sqle/driver/mysql/rule/rule.go +++ b/sqle/driver/mysql/rule/rule.go @@ -11,13 +11,13 @@ import ( "strings" "unicode" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/executor" "github.com/actiontech/sqle/sqle/driver/mysql/keyword" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" "github.com/actiontech/sqle/sqle/driver/mysql/session" "github.com/actiontech/sqle/sqle/driver/mysql/util" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" - "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/log" "github.com/actiontech/sqle/sqle/pkg/params" "github.com/actiontech/sqle/sqle/utils" @@ -305,8 +305,8 @@ func ConvertSourceRule(sr *SourceRule) *driverV2.Rule { r.Params = append(r.Params, ¶ms.Param{ Key: v.Key, Value: v.Value, - Desc: plocale.ShouldLocalizeMsgByLang(locale.DefaultLang, v.Desc), - I18nDesc: plocale.ShouldLocalizeAll(v.Desc), + Desc: plocale.Bundle.LocalizeMsgByLang(i18nPkg.DefaultLang, v.Desc), + I18nDesc: plocale.Bundle.LocalizeAll(v.Desc), Type: v.Type, Enums: nil, // all nil now }) @@ -319,9 +319,9 @@ func genAllI18nRuleInfo(sr *SourceRule) map[language.Tag]*driverV2.RuleInfo { result := make(map[language.Tag]*driverV2.RuleInfo, len(plocale.Bundle.LanguageTags())) for _, langTag := range plocale.Bundle.LanguageTags() { newInfo := &driverV2.RuleInfo{ - Desc: plocale.ShouldLocalizeMsgByLang(langTag, sr.Desc), - Annotation: plocale.ShouldLocalizeMsgByLang(langTag, sr.Annotation), - Category: plocale.ShouldLocalizeMsgByLang(langTag, sr.Category), + Desc: plocale.Bundle.LocalizeMsgByLang(langTag, sr.Desc), + Annotation: plocale.Bundle.LocalizeMsgByLang(langTag, sr.Annotation), + Category: plocale.Bundle.LocalizeMsgByLang(langTag, sr.Category), //Level: sr.Level, Knowledge: driverV2.RuleKnowledge{Content: sr.Knowledge.Content}, //todo i18n Knowledge } @@ -340,7 +340,7 @@ func init() { for i, rh := range RuleHandlers { if knowledge, ok := defaultRulesKnowledge[rh.Rule.Name]; ok { // todo i18n Knowledge - rh.Rule.I18nRuleInfo[locale.DefaultLang].Knowledge = driverV2.RuleKnowledge{Content: knowledge} + rh.Rule.I18nRuleInfo[i18nPkg.DefaultLang].Knowledge = driverV2.RuleKnowledge{Content: knowledge} RuleHandlers[i] = rh } RuleHandlerMap[rh.Rule.Name] = rh @@ -359,7 +359,7 @@ func addResult(result *driverV2.AuditResults, currentRule driverV2.Rule, ruleNam } level := currentRule.Level message := RuleHandlerMap[ruleName].Message - result.Add(level, ruleName, plocale.ShouldLocalizeAll(message), args...) + result.Add(level, ruleName, plocale.Bundle.LocalizeAll(message), args...) } func (rh *RuleHandler) IsAllowOfflineRule(node ast.Node) bool { diff --git a/sqle/driver/mysql/rule/rule_test.go b/sqle/driver/mysql/rule/rule_test.go index ac49f1c30..9844d1311 100644 --- a/sqle/driver/mysql/rule/rule_test.go +++ b/sqle/driver/mysql/rule/rule_test.go @@ -3,6 +3,7 @@ package rule import ( "testing" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/mysql/plocale" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" "github.com/stretchr/testify/assert" @@ -11,19 +12,19 @@ import ( func TestInspectResults(t *testing.T) { results := driverV2.NewAuditResults() handler := RuleHandlerMap[DDLCheckPKWithoutIfNotExists] - results.Add(handler.Rule.Level, handler.Rule.Name, plocale.ShouldLocalizeAll(plocale.DDLCheckPKWithoutIfNotExistsMessage)) + results.Add(handler.Rule.Level, handler.Rule.Name, plocale.Bundle.LocalizeAll(plocale.DDLCheckPKWithoutIfNotExistsMessage)) assert.Equal(t, driverV2.RuleLevelError, results.Level()) assert.Equal(t, "[error]新建表建议加入 IF NOT EXISTS,保证重复执行不报错", results.Message()) - results.Add(driverV2.RuleLevelError, "", plocale.ShouldLocalizeAllWithArgs(plocale.TableNotExistMessage, "not_exist_tb")) + results.Add(driverV2.RuleLevelError, "", plocale.Bundle.LocalizeAllWithArgs(plocale.TableNotExistMessage, "not_exist_tb")) assert.Equal(t, driverV2.RuleLevelError, results.Level()) assert.Equal(t, `[error]新建表建议加入 IF NOT EXISTS,保证重复执行不报错 [error]表 not_exist_tb 不存在`, results.Message()) results2 := driverV2.NewAuditResults() - results2.Add(results.Level(), "", plocale.ConvertStr2I18n(results.Message())) - results2.Add(driverV2.RuleLevelNotice, "", plocale.ConvertStr2I18n("test")) + results2.Add(results.Level(), "", i18nPkg.ConvertStr2I18nAsDefaultLang(results.Message())) + results2.Add(driverV2.RuleLevelNotice, "", i18nPkg.ConvertStr2I18nAsDefaultLang("test")) assert.Equal(t, driverV2.RuleLevelError, results2.Level()) assert.Equal(t, `[error]新建表建议加入 IF NOT EXISTS,保证重复执行不报错 @@ -31,8 +32,8 @@ func TestInspectResults(t *testing.T) { [notice]test`, results2.Message()) results3 := driverV2.NewAuditResults() - results3.Add(results2.Level(), "", plocale.ConvertStr2I18n(results2.Message())) - results3.Add(driverV2.RuleLevelNotice, "", plocale.ConvertStr2I18n("[osc]test")) + results3.Add(results2.Level(), "", i18nPkg.ConvertStr2I18nAsDefaultLang(results2.Message())) + results3.Add(driverV2.RuleLevelNotice, "", i18nPkg.ConvertStr2I18nAsDefaultLang("[osc]test")) assert.Equal(t, driverV2.RuleLevelError, results3.Level()) assert.Equal(t, `[error]新建表建议加入 IF NOT EXISTS,保证重复执行不报错 @@ -41,16 +42,16 @@ func TestInspectResults(t *testing.T) { [osc]test`, results3.Message()) results4 := driverV2.NewAuditResults() - results4.Add(driverV2.RuleLevelNotice, "", plocale.ConvertStr2I18n("[notice]test")) - results4.Add(driverV2.RuleLevelError, "", plocale.ConvertStr2I18n("[osc]test")) + results4.Add(driverV2.RuleLevelNotice, "", i18nPkg.ConvertStr2I18nAsDefaultLang("[notice]test")) + results4.Add(driverV2.RuleLevelError, "", i18nPkg.ConvertStr2I18nAsDefaultLang("[osc]test")) assert.Equal(t, driverV2.RuleLevelError, results4.Level()) assert.Equal(t, `[osc]test [notice]test`, results4.Message()) results5 := driverV2.NewAuditResults() - results5.Add(driverV2.RuleLevelWarn, "", plocale.ConvertStr2I18n("[warn]test")) - results5.Add(driverV2.RuleLevelNotice, "", plocale.ConvertStr2I18n("[osc]test")) + results5.Add(driverV2.RuleLevelWarn, "", i18nPkg.ConvertStr2I18nAsDefaultLang("[warn]test")) + results5.Add(driverV2.RuleLevelNotice, "", i18nPkg.ConvertStr2I18nAsDefaultLang("[osc]test")) assert.Equal(t, driverV2.RuleLevelWarn, results5.Level()) assert.Equal(t, `[warn]test diff --git a/sqle/driver/plugin_adapter_v1.go b/sqle/driver/plugin_adapter_v1.go index 7fe1f9953..89a7d6406 100644 --- a/sqle/driver/plugin_adapter_v1.go +++ b/sqle/driver/plugin_adapter_v1.go @@ -5,11 +5,10 @@ import ( sqlDriver "database/sql/driver" "fmt" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV1 "github.com/actiontech/sqle/sqle/driver/v1" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" "github.com/actiontech/sqle/sqle/errors" - "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/pkg/params" goPlugin "github.com/hashicorp/go-plugin" "github.com/sirupsen/logrus" @@ -40,7 +39,7 @@ func convertRuleFromV1ToV2(rule *driverV1.Rule) *driverV2.Rule { Level: driverV2.RuleLevel(rule.Level), Params: ps, I18nRuleInfo: map[language.Tag]*driverV2.RuleInfo{ - locale.DefaultLang: { + i18nPkg.DefaultLang: { Desc: rule.Desc, Annotation: rule.Annotation, Category: rule.Category, @@ -105,9 +104,9 @@ func (d *PluginProcessorV1) Open(l *logrus.Entry, cfgV2 *driverV2.Config) (Plugi for _, rule := range cfgV2.Rules { cfg.Rules = append(cfg.Rules, &driverV1.Rule{ Name: rule.Name, - Desc: rule.I18nRuleInfo.GetRuleInfoByLangTag(locale.DefaultLang).Desc, - Annotation: rule.I18nRuleInfo.GetRuleInfoByLangTag(locale.DefaultLang).Annotation, - Category: rule.I18nRuleInfo.GetRuleInfoByLangTag(locale.DefaultLang).Category, + Desc: rule.I18nRuleInfo.GetRuleInfoByLangTag(i18nPkg.DefaultLang).Desc, + Annotation: rule.I18nRuleInfo.GetRuleInfoByLangTag(i18nPkg.DefaultLang).Annotation, + Category: rule.I18nRuleInfo.GetRuleInfoByLangTag(i18nPkg.DefaultLang).Category, Level: driverV1.RuleLevel(rule.Level), Params: rule.Params, }) @@ -174,7 +173,7 @@ func (p *PluginImplV1) Audit(ctx context.Context, sqls []string) ([]*driverV2.Au resultV2.Results = append(resultV2.Results, &driverV2.AuditResult{ Level: driverV2.RuleLevel(result.Level), I18nAuditResultInfo: map[language.Tag]driverV2.AuditResultInfo{ - locale.DefaultLang: { + i18nPkg.DefaultLang: { Message: result.Message, }, }, diff --git a/sqle/driver/plugin_adapter_v2.go b/sqle/driver/plugin_adapter_v2.go index 4cd06b156..0f3c1553a 100644 --- a/sqle/driver/plugin_adapter_v2.go +++ b/sqle/driver/plugin_adapter_v2.go @@ -8,11 +8,10 @@ import ( "os" "sync" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" protoV2 "github.com/actiontech/sqle/sqle/driver/v2/proto" - "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/log" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/pkg/params" "golang.org/x/text/language" @@ -81,9 +80,9 @@ func (d *PluginProcessorV2) GetDriverMetas() (*driverV2.DriverMetas, error) { rules := make([]*driverV2.Rule, 0, len(result.Rules)) for _, r := range result.Rules { if len(r.I18NRuleInfo) > 0 { - if _, exist := r.I18NRuleInfo[locale.DefaultLang.String()]; !exist { - // 多语言插件必须支持 locale.DefaultLang 用以默认展示 - return nil, fmt.Errorf("client rule: %s not support language: %s", r.Name, locale.DefaultLang.String()) + if _, exist := r.I18NRuleInfo[i18nPkg.DefaultLang.String()]; !exist { + // 多语言插件必须支持 i18nPkg.DefaultLang 用以默认展示 + return nil, fmt.Errorf("client rule: %s not support language: %s", r.Name, i18nPkg.DefaultLang.String()) } } dr, err := driverV2.ConvertI18nRuleFromProtoToDriver(r) diff --git a/sqle/driver/plugin_interface.go b/sqle/driver/plugin_interface.go index 51374f111..31fba5447 100644 --- a/sqle/driver/plugin_interface.go +++ b/sqle/driver/plugin_interface.go @@ -4,8 +4,8 @@ import ( "context" "database/sql/driver" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/sirupsen/logrus" ) diff --git a/sqle/driver/v1/driver_audit.go b/sqle/driver/v1/driver_audit.go index 56a3e839b..f35e4d713 100644 --- a/sqle/driver/v1/driver_audit.go +++ b/sqle/driver/v1/driver_audit.go @@ -8,8 +8,8 @@ import ( "sort" "strings" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/v1/proto" - "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/pkg/params" "github.com/pkg/errors" @@ -427,7 +427,7 @@ func convertRuleFromDriverToProto(rule *Rule) *proto.Rule { params = append(params, &proto.Param{ Key: p.Key, Value: p.Value, - Desc: p.GetDesc(locale.DefaultLang), + Desc: p.GetDesc(i18nPkg.DefaultLang), Type: string(p.Type), }) } diff --git a/sqle/driver/v1/plugin_query.go b/sqle/driver/v1/plugin_query.go index b66b379d3..b6738512d 100644 --- a/sqle/driver/v1/plugin_query.go +++ b/sqle/driver/v1/plugin_query.go @@ -3,9 +3,8 @@ package driverV1 import ( "context" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/v1/proto" - "github.com/actiontech/sqle/sqle/locale" - goPlugin "github.com/hashicorp/go-plugin" "google.golang.org/grpc" ) @@ -67,7 +66,7 @@ func (q *queryDriverGRPCServer) Query(ctx context.Context, req *proto.QueryReque resp.Column = append(resp.Column, &proto.Param{ Key: param.Key, Value: param.Value, - Desc: param.GetDesc(locale.DefaultLang), + Desc: param.GetDesc(i18nPkg.DefaultLang), Type: string(param.Type), }) } diff --git a/sqle/driver/v1/proto/util.go b/sqle/driver/v1/proto/util.go index bdb411da1..20ba59e4e 100644 --- a/sqle/driver/v1/proto/util.go +++ b/sqle/driver/v1/proto/util.go @@ -1,7 +1,7 @@ package proto import ( - "github.com/actiontech/sqle/sqle/locale" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/pkg/params" ) @@ -14,7 +14,7 @@ func ConvertParamToProtoParam(p params.Params) []*Param { pp[i] = &Param{ Key: v.Key, Value: v.Value, - Desc: v.GetDesc(locale.DefaultLang), + Desc: v.GetDesc(i18nPkg.DefaultLang), Type: string(v.Type), } } diff --git a/sqle/driver/v2/driver_grpc_server.go b/sqle/driver/v2/driver_grpc_server.go index 5289bdbe1..9248c0bd5 100644 --- a/sqle/driver/v2/driver_grpc_server.go +++ b/sqle/driver/v2/driver_grpc_server.go @@ -7,8 +7,8 @@ import ( "fmt" "sync" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" protoV2 "github.com/actiontech/sqle/sqle/driver/v2/proto" - "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/pkg/params" "golang.org/x/text/language" @@ -47,7 +47,7 @@ func (i *I18nRuleInfo) GetRuleInfoByLangTag(lang language.Tag) *RuleInfo { if ruleInfo, ok := (*i)[lang]; ok { return ruleInfo } - return (*i)[locale.DefaultLang] + return (*i)[i18nPkg.DefaultLang] } func (i I18nRuleInfo) Value() (driver.Value, error) { @@ -395,7 +395,7 @@ func (d *DriverGrpcServer) Query(ctx context.Context, req *protoV2.QueryRequest) resp.Column = append(resp.Column, &protoV2.Param{ Key: param.Key, Value: param.Value, - Desc: param.GetDesc(locale.DefaultLang), + Desc: param.GetDesc(i18nPkg.DefaultLang), I18NDesc: param.I18nDesc.StrMap(), Type: string(param.Type), }) diff --git a/sqle/driver/v2/driver_interface.go b/sqle/driver/v2/driver_interface.go index eefcae103..0e36ac33a 100644 --- a/sqle/driver/v2/driver_interface.go +++ b/sqle/driver/v2/driver_interface.go @@ -8,10 +8,9 @@ import ( "sort" "strings" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver/common" protoV2 "github.com/actiontech/sqle/sqle/driver/v2/proto" - "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/pkg/params" "golang.org/x/text/language" @@ -183,7 +182,7 @@ func (rs *AuditResults) Message() string { repeatCheck := map[string]struct{}{} messages := []string{} for _, result := range rs.Results { - token := result.I18nAuditResultInfo[locale.DefaultLang].Message + string(result.Level) + token := result.I18nAuditResultInfo[i18nPkg.DefaultLang].Message + string(result.Level) if _, ok := repeatCheck[token]; ok { continue } @@ -192,11 +191,11 @@ func (rs *AuditResults) Message() string { var message string match, _ := regexp.MatchString(fmt.Sprintf(`^\[%s|%s|%s|%s|%s\]`, RuleLevelError, RuleLevelWarn, RuleLevelNotice, RuleLevelNormal, "osc"), - result.I18nAuditResultInfo[locale.DefaultLang].Message) + result.I18nAuditResultInfo[i18nPkg.DefaultLang].Message) if match { - message = result.I18nAuditResultInfo[locale.DefaultLang].Message + message = result.I18nAuditResultInfo[i18nPkg.DefaultLang].Message } else { - message = fmt.Sprintf("[%s]%s", result.Level, result.I18nAuditResultInfo[locale.DefaultLang].Message) + message = fmt.Sprintf("[%s]%s", result.Level, result.I18nAuditResultInfo[i18nPkg.DefaultLang].Message) } messages = append(messages, message) } diff --git a/sqle/driver/v2/util.go b/sqle/driver/v2/util.go index 57adafdc0..27fbbc508 100644 --- a/sqle/driver/v2/util.go +++ b/sqle/driver/v2/util.go @@ -5,9 +5,8 @@ import ( "math/rand" "time" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" protoV2 "github.com/actiontech/sqle/sqle/driver/v2/proto" - "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/pkg/params" "golang.org/x/text/language" ) @@ -109,11 +108,11 @@ func ConvertI18nAuditResultFromProtoToDriver(par *protoV2.AuditResult) (*AuditRe if len(par.I18NAuditResultInfo) == 0 { // 对非多语言的插件支持 ar.I18nAuditResultInfo = map[language.Tag]AuditResultInfo{ - locale.DefaultLang: {Message: par.Message}, + i18nPkg.DefaultLang: {Message: par.Message}, } } else { if _, exist := par.I18NAuditResultInfo[i18nPkg.DefaultLang.String()]; !exist { - // 多语言的插件 需包含 locale.DefaultLang + // 多语言的插件 需包含 i18nPkg.DefaultLang return nil, fmt.Errorf("client audit results must support language: %s", i18nPkg.DefaultLang.String()) } } @@ -131,7 +130,7 @@ func ConvertI18nAuditResultFromProtoToDriver(par *protoV2.AuditResult) (*AuditRe func ConvertI18nAuditResultFromDriverToProto(ar *AuditResult) *protoV2.AuditResult { par := &protoV2.AuditResult{ - Message: ar.I18nAuditResultInfo[locale.DefaultLang].Message, + Message: ar.I18nAuditResultInfo[i18nPkg.DefaultLang].Message, RuleName: ar.RuleName, Level: string(ar.Level), I18NAuditResultInfo: make(map[string]*protoV2.I18NAuditResultInfo, len(ar.I18nAuditResultInfo)), @@ -173,11 +172,11 @@ func ConvertI18nRuleFromProtoToDriver(rule *protoV2.Rule) (*Rule, error) { ruleInfo.Knowledge = RuleKnowledge{Content: rule.Knowledge.Content} } dRule.I18nRuleInfo = I18nRuleInfo{ - locale.DefaultLang: ruleInfo, + i18nPkg.DefaultLang: ruleInfo, } } else { if _, exist := rule.I18NRuleInfo[i18nPkg.DefaultLang.String()]; !exist { - // 多语言的插件 需包含 locale.DefaultLang + // 多语言的插件 需包含 i18nPkg.DefaultLang return nil, fmt.Errorf("client rule: %s does not support language: %s", rule.Name, i18nPkg.DefaultLang.String()) } } @@ -205,13 +204,13 @@ func ConvertI18nRuleFromDriverToProto(rule *Rule) *protoV2.Rule { // 填充默认语言以支持非多语言插件 pRule := &protoV2.Rule{ Name: rule.Name, - Desc: rule.I18nRuleInfo[locale.DefaultLang].Desc, + Desc: rule.I18nRuleInfo[i18nPkg.DefaultLang].Desc, Level: string(rule.Level), - Category: rule.I18nRuleInfo[locale.DefaultLang].Category, + Category: rule.I18nRuleInfo[i18nPkg.DefaultLang].Category, Params: ConvertParamToProtoParam(rule.Params), - Annotation: rule.I18nRuleInfo[locale.DefaultLang].Annotation, + Annotation: rule.I18nRuleInfo[i18nPkg.DefaultLang].Annotation, Knowledge: &protoV2.Knowledge{ - Content: rule.I18nRuleInfo[locale.DefaultLang].Knowledge.Content, + Content: rule.I18nRuleInfo[i18nPkg.DefaultLang].Knowledge.Content, }, I18NRuleInfo: make(map[string]*protoV2.I18NRuleInfo, len(rule.I18nRuleInfo)), } @@ -302,7 +301,7 @@ func ConvertParamToProtoParam(p params.Params) []*protoV2.Param { pp[i] = &protoV2.Param{ Key: v.Key, Value: v.Value, - Desc: v.GetDesc(locale.DefaultLang), + Desc: v.GetDesc(i18nPkg.DefaultLang), I18NDesc: v.I18nDesc.StrMap(), Type: string(v.Type), } @@ -363,7 +362,7 @@ func ConvertProtoTabularDataToDriver(pTd *protoV2.TabularData) (TabularData, err } if len(c.I18NDesc) > 0 { if _, exist := c.I18NDesc[i18nPkg.DefaultLang.String()]; !exist { - // 多语言的插件 需包含 locale.DefaultLang + // 多语言的插件 需包含 i18nPkg.DefaultLang return TabularData{}, fmt.Errorf("client TabularDataHead: %s does not support language: %s", c.Name, i18nPkg.DefaultLang.String()) } i18nDesc, err := i18nPkg.ConvertStrMap2I18nStr(c.I18NDesc) diff --git a/sqle/locale/locale.go b/sqle/locale/locale.go index db3c7dc4e..089759958 100644 --- a/sqle/locale/locale.go +++ b/sqle/locale/locale.go @@ -1,14 +1,10 @@ package locale import ( - "context" "embed" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/log" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" - "github.com/labstack/echo/v4" - "github.com/nicksnyder/go-i18n/v2/i18n" - "golang.org/x/text/language" ) //go:embed active.*.toml @@ -16,8 +12,6 @@ var localeFS embed.FS var Bundle *i18nPkg.Bundle -var DefaultLang = i18nPkg.DefaultLang // todo i18n make sure plugins support - func init() { b, err := i18nPkg.NewBundleFromTomlDir(localeFS, log.NewEntry()) if err != nil { @@ -25,25 +19,3 @@ func init() { } Bundle = b } - -// todo i18n 把调用下列函数的地方改成直接使用 Bundle对应方法 - -func EchoMiddlewareI18nByAcceptLanguage() echo.MiddlewareFunc { - return Bundle.EchoMiddlewareByAcceptLanguage() -} - -func ShouldLocalizeMsg(ctx context.Context, msg *i18n.Message) string { - return Bundle.ShouldLocalizeMsg(ctx, msg) -} - -func GetLangTagFromCtx(ctx context.Context) language.Tag { - return Bundle.GetLangTagFromCtx(ctx) -} - -func ShouldLocalizeAll(msg *i18n.Message) i18nPkg.I18nStr { - return Bundle.ShouldLocalizeAll(msg) -} - -func ShouldLocalizeAllWithArgs(fmtMsg *i18n.Message, args ...any) i18nPkg.I18nStr { - return Bundle.ShouldLocalizeAllWithArgs(fmtMsg, args) -} diff --git a/sqle/model/operation.go b/sqle/model/operation.go index 40178f0cd..95dab224f 100644 --- a/sqle/model/operation.go +++ b/sqle/model/operation.go @@ -59,19 +59,19 @@ func getConfigurableOperationCodeList() []uint { func GetOperationCodeDesc(ctx context.Context, opCode uint) string { switch opCode { case OP_WORKFLOW_VIEW_OTHERS: - return locale.ShouldLocalizeMsg(ctx, locale.OpWorkflowViewOthers) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpWorkflowViewOthers) case OP_WORKFLOW_SAVE: - return locale.ShouldLocalizeMsg(ctx, locale.OpWorkflowSave) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpWorkflowSave) case OP_WORKFLOW_AUDIT: - return locale.ShouldLocalizeMsg(ctx, locale.OpWorkflowAudit) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpWorkflowAudit) case OP_WORKFLOW_EXECUTE: - return locale.ShouldLocalizeMsg(ctx, locale.OpWorkflowExecute) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpWorkflowExecute) case OP_AUDIT_PLAN_VIEW_OTHERS: - return locale.ShouldLocalizeMsg(ctx, locale.OpAuditPlanViewOthers) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpAuditPlanViewOthers) case OP_AUDIT_PLAN_SAVE: - return locale.ShouldLocalizeMsg(ctx, locale.OpAuditPlanSave) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpAuditPlanSave) case OP_SQL_QUERY_QUERY: - return locale.ShouldLocalizeMsg(ctx, locale.OpSqlQueryQuery) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpSqlQueryQuery) default: return additionalOperationForEE(ctx, opCode) } diff --git a/sqle/model/operation_ce.go b/sqle/model/operation_ce.go index c31ef2eca..480523552 100644 --- a/sqle/model/operation_ce.go +++ b/sqle/model/operation_ce.go @@ -14,5 +14,5 @@ func getConfigurableOperationCodeListForEE() []uint { } func additionalOperationForEE(ctx context.Context, opCode uint) string { - return locale.ShouldLocalizeMsg(ctx, locale.OpUnknown) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.OpUnknown) } diff --git a/sqle/model/operation_record.go b/sqle/model/operation_record.go index fbb36cad6..172845c94 100644 --- a/sqle/model/operation_record.go +++ b/sqle/model/operation_record.go @@ -3,8 +3,7 @@ package model import ( "time" - "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "golang.org/x/text/language" ) @@ -24,7 +23,7 @@ type OperationRecord struct { func (o *OperationRecord) GetOperationContentByLangTag(lang language.Tag) string { if o.OperationContent != "" { // 兼容老sqle的数据 - o.OperationI18nContent.SetStrInLang(locale.DefaultLang, o.OperationContent) + o.OperationI18nContent.SetStrInLang(i18nPkg.DefaultLang, o.OperationContent) } return o.OperationI18nContent.GetStrInLang(lang) } diff --git a/sqle/model/rule.go b/sqle/model/rule.go index 69d7580fb..501f9c78c 100644 --- a/sqle/model/rule.go +++ b/sqle/model/rule.go @@ -5,10 +5,10 @@ import ( "fmt" "strings" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" "github.com/actiontech/sqle/sqle/errors" "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/pkg/params" "golang.org/x/text/language" "gorm.io/gorm" @@ -514,7 +514,7 @@ func (s *Storage) GetAuditPlanNamesByRuleTemplateAndProject( } func (s *Storage) GetRuleTypeByDBType(ctx context.Context, DBType string) ([]string, error) { - lang := locale.GetLangTagFromCtx(ctx) + lang := locale.Bundle.GetLangTagFromCtx(ctx) rules := []*Rule{} err := s.db.Where("db_type = ?", DBType).Find(&rules).Error if err != nil { diff --git a/sqle/model/task.go b/sqle/model/task.go index 17adaa4fb..3dccca486 100644 --- a/sqle/model/task.go +++ b/sqle/model/task.go @@ -10,10 +10,10 @@ import ( "strings" "time" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" "github.com/actiontech/sqle/sqle/errors" "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "github.com/actiontech/sqle/sqle/utils" "golang.org/x/text/language" "gorm.io/gorm" @@ -139,17 +139,17 @@ type BaseSQL struct { func (s *BaseSQL) GetExecStatusDesc(ctx context.Context) string { switch s.ExecStatus { case SQLExecuteStatusInitialized: - return locale.ShouldLocalizeMsg(ctx, locale.SQLExecuteStatusInitialized) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLExecuteStatusInitialized) case SQLExecuteStatusDoing: - return locale.ShouldLocalizeMsg(ctx, locale.SQLExecuteStatusDoing) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLExecuteStatusDoing) case SQLExecuteStatusFailed: - return locale.ShouldLocalizeMsg(ctx, locale.SQLExecuteStatusFailed) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLExecuteStatusFailed) case SQLExecuteStatusSucceeded: - return locale.ShouldLocalizeMsg(ctx, locale.SQLExecuteStatusSucceeded) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLExecuteStatusSucceeded) case SQLExecuteStatusManuallyExecuted: - return locale.ShouldLocalizeMsg(ctx, locale.SQLExecuteStatusManuallyExecuted) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLExecuteStatusManuallyExecuted) default: - return locale.ShouldLocalizeMsg(ctx, locale.SQLExecuteStatusUnknown) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLExecuteStatusUnknown) } } @@ -183,7 +183,7 @@ func (i *I18nAuditResultInfo) GetAuditResultInfoByLangTag(lang language.Tag) *Au return &info } - info := (*i)[locale.DefaultLang] + info := (*i)[i18nPkg.DefaultLang] return &info } @@ -259,7 +259,7 @@ func (a *AuditResults) Scan(input interface{}) error { // todo check somewhere fmt Sprint AuditResults to frontend? func (a *AuditResults) String(ctx context.Context) string { - lang := locale.GetLangTagFromCtx(ctx) + lang := locale.Bundle.GetLangTagFromCtx(ctx) msgs := make([]string, len(*a)) for i := range *a { res := (*a)[i] @@ -325,13 +325,13 @@ func (s ExecuteSQL) TableName() string { func (s *ExecuteSQL) GetAuditStatusDesc(ctx context.Context) string { switch s.AuditStatus { case SQLAuditStatusInitialized: - return locale.ShouldLocalizeMsg(ctx, locale.SQLAuditStatusInitialized) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLAuditStatusInitialized) case SQLAuditStatusDoing: - return locale.ShouldLocalizeMsg(ctx, locale.SQLAuditStatusDoing) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLAuditStatusDoing) case SQLAuditStatusFinished: - return locale.ShouldLocalizeMsg(ctx, locale.SQLAuditStatusFinished) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLAuditStatusFinished) default: - return locale.ShouldLocalizeMsg(ctx, locale.SQLAuditStatusUnknown) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLAuditStatusUnknown) } } @@ -345,7 +345,7 @@ func (s *ExecuteSQL) GetAuditResults(ctx context.Context) string { func (s *ExecuteSQL) GetAuditResultDesc(ctx context.Context) string { if len(s.AuditResults) == 0 { - return locale.ShouldLocalizeMsg(ctx, locale.SQLAuditResultDescPass) + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.SQLAuditResultDescPass) } return s.AuditResults.String(ctx) diff --git a/sqle/model/utils.go b/sqle/model/utils.go index 29844ad8f..418a3e34c 100644 --- a/sqle/model/utils.go +++ b/sqle/model/utils.go @@ -13,10 +13,10 @@ import ( "text/template" "time" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" "github.com/actiontech/sqle/sqle/errors" "github.com/actiontech/sqle/sqle/log" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" opt "github.com/actiontech/sqle/sqle/server/optimization/rule" "github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx/reflectx" diff --git a/sqle/pkg/driver/builder.go b/sqle/pkg/driver/builder.go index 817020e33..c9228d914 100644 --- a/sqle/pkg/driver/builder.go +++ b/sqle/pkg/driver/builder.go @@ -4,8 +4,8 @@ import ( "context" "os" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" hclog "github.com/hashicorp/go-hclog" "github.com/pkg/errors" ) diff --git a/sqle/pkg/params/params.go b/sqle/pkg/params/params.go index 6fe647217..db2494d31 100644 --- a/sqle/pkg/params/params.go +++ b/sqle/pkg/params/params.go @@ -6,9 +6,8 @@ import ( "fmt" "strconv" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" dmsCommonAes "github.com/actiontech/dms/pkg/dms-common/pkg/aes" - "github.com/actiontech/sqle/sqle/locale" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" "golang.org/x/text/language" ) @@ -41,7 +40,7 @@ type EnumsValue struct { func (e EnumsValue) GetDesc(lang language.Tag) string { if e.Desc != "" { - e.I18nDesc.SetStrInLang(locale.DefaultLang, e.Desc) + e.I18nDesc.SetStrInLang(i18nPkg.DefaultLang, e.Desc) } return e.I18nDesc.GetStrInLang(lang) } @@ -129,7 +128,7 @@ func (r *Param) GetDesc(lang language.Tag) string { return "" } if r.Desc != "" { - r.I18nDesc.SetStrInLang(locale.DefaultLang, r.Desc) + r.I18nDesc.SetStrInLang(i18nPkg.DefaultLang, r.Desc) } return r.I18nDesc.GetStrInLang(lang) } diff --git a/sqle/server/audit.go b/sqle/server/audit.go index d1c3c52ef..14c53a765 100644 --- a/sqle/server/audit.go +++ b/sqle/server/audit.go @@ -180,7 +180,7 @@ func hookAudit(l *logrus.Entry, task *model.Task, p driver.Plugin, hook AuditHoo } if whitelistMatch { result := driverV2.NewAuditResults() - result.Add(driverV2.RuleLevelNormal, "", plocale.ShouldLocalizeAll(plocale.AuditResultMsgExcludedSQL)) + result.Add(driverV2.RuleLevelNormal, "", plocale.Bundle.LocalizeAll(plocale.AuditResultMsgExcludedSQL)) executeSQL.AuditStatus = model.SQLAuditStatusFinished executeSQL.AuditLevel = string(result.Level()) executeSQL.AuditFingerprint = utils.Md5String(string(append([]byte(result.Message()), []byte(node.Fingerprint)...))) diff --git a/sqle/server/auditplan/task_filter_tips.go b/sqle/server/auditplan/task_filter_tips.go index d303fff85..25e93c34e 100644 --- a/sqle/server/auditplan/task_filter_tips.go +++ b/sqle/server/auditplan/task_filter_tips.go @@ -19,7 +19,7 @@ func GetSqlManagerRuleTips(ctx context.Context, logger *logrus.Entry, auditPlanI for _, rule := range rules { ruleFilterTips = append(ruleFilterTips, FilterTip{ Value: rule.RuleName, - Desc: rule.I18nRuleInfo.GetRuleInfoByLangTag(locale.GetLangTagFromCtx(ctx)).Desc, + Desc: rule.I18nRuleInfo.GetRuleInfoByLangTag(locale.Bundle.GetLangTagFromCtx(ctx)).Desc, Group: rule.DbType, }) } @@ -65,7 +65,7 @@ func GetSqlManagerPriorityTips(ctx context.Context, logger *logrus.Entry) []Filt return []FilterTip{ { Value: model.PriorityHigh, - Desc: locale.ShouldLocalizeMsg(ctx, locale.ApPriorityHigh), + Desc: locale.Bundle.LocalizeMsgByCtx(ctx, locale.ApPriorityHigh), }, } } diff --git a/sqle/server/auditplan/task_type_default.go b/sqle/server/auditplan/task_type_default.go index daf548b4c..eda683e5e 100644 --- a/sqle/server/auditplan/task_type_default.go +++ b/sqle/server/auditplan/task_type_default.go @@ -33,13 +33,13 @@ func (at *DefaultTaskV2) Params(instanceId ...string) params.Params { var defaultOperatorEnums = []params.EnumsValue{ { Value: ">", - I18nDesc: locale.ShouldLocalizeAll(locale.OperatorGreaterThan), + I18nDesc: locale.Bundle.LocalizeAll(locale.OperatorGreaterThan), }, { Value: "=", - I18nDesc: locale.ShouldLocalizeAll(locale.OperatorEqualTo), + I18nDesc: locale.Bundle.LocalizeAll(locale.OperatorEqualTo), }, { Value: "<", - I18nDesc: locale.ShouldLocalizeAll(locale.OperatorLessThan), + I18nDesc: locale.Bundle.LocalizeAll(locale.OperatorLessThan), }, } @@ -61,7 +61,7 @@ var defaultAuditLevelOperateParams = ¶ms.ParamWithOperator{ Desc: string(driverV2.RuleLevelError), }, }, - I18nDesc: locale.ShouldLocalizeAll(locale.OperationParamAuditLevel), + I18nDesc: locale.Bundle.LocalizeAll(locale.OperationParamAuditLevel), }, Operator: params.Operator{ Value: ">", @@ -250,7 +250,7 @@ func (at *DefaultTaskV2) GetSQLData(ctx context.Context, ap *AuditPlan, persist "priority": sql.Priority.String, MetricNameCounter: strconv.Itoa(int(info.Get(MetricNameCounter).Int())), MetricNameLastReceiveTimestamp: info.Get(MetricNameLastReceiveTimestamp).String(), - model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.GetLangTagFromCtx(ctx)), + model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.Bundle.GetLangTagFromCtx(ctx)), }) } return rows, count, nil diff --git a/sqle/server/auditplan/task_type_mysql_audit_log_ali.go b/sqle/server/auditplan/task_type_mysql_audit_log_ali.go index 5da297e75..c76545fa7 100644 --- a/sqle/server/auditplan/task_type_mysql_audit_log_ali.go +++ b/sqle/server/auditplan/task_type_mysql_audit_log_ali.go @@ -36,31 +36,31 @@ func (at *MySQLAuditLogAliTaskV2) Params(instanceId ...string) params.Params { Key: paramKeyDBInstanceId, Value: "", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamDBInstanceId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamDBInstanceId), }, { Key: paramKeyAccessKeyId, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeyId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeyId), }, { Key: paramKeyAccessKeySecret, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeySecret), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeySecret), }, { Key: paramKeyFirstSqlsScrappedInLastPeriodHours, Value: "24", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 31), + I18nDesc: locale.Bundle.LocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 31), }, { Key: paramKeyRdsPath, Value: "rds.aliyuncs.com", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamRdsPath), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamRdsPath), }, } diff --git a/sqle/server/auditplan/task_type_mysql_processlist.go b/sqle/server/auditplan/task_type_mysql_processlist.go index eb7ea9194..1e963eb24 100644 --- a/sqle/server/auditplan/task_type_mysql_processlist.go +++ b/sqle/server/auditplan/task_type_mysql_processlist.go @@ -36,13 +36,13 @@ func (at *MySQLProcessListTaskV2) Params(instanceId ...string) params.Params { Key: paramKeyCollectIntervalSecond, Value: "60", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamCollectIntervalSecond), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamCollectIntervalSecond), }, { Key: paramKeySQLMinSecond, Value: "0", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamSQLMinSecond), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamSQLMinSecond), }, } diff --git a/sqle/server/auditplan/task_type_mysql_schema_meta.go b/sqle/server/auditplan/task_type_mysql_schema_meta.go index 987416954..48d14057f 100644 --- a/sqle/server/auditplan/task_type_mysql_schema_meta.go +++ b/sqle/server/auditplan/task_type_mysql_schema_meta.go @@ -129,13 +129,13 @@ func (at *BaseSchemaMetaTaskV2) Params(instanceId ...string) params.Params { Key: paramKeyCollectIntervalMinute, Value: "60", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamCollectIntervalMinuteOracle), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamCollectIntervalMinuteOracle), }, { Key: "collect_view", Value: "0", Type: params.ParamTypeBool, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamCollectView), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamCollectView), }, } } @@ -354,7 +354,7 @@ func (at *BaseSchemaMetaTaskV2) GetSQLData(ctx context.Context, ap *AuditPlan, p "id": sql.AuditPlanSqlId, MetricNameMetaName: info.Get(MetricNameMetaName).String(), MetricNameMetaType: info.Get(MetricNameMetaType).String(), - model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.GetLangTagFromCtx(ctx)), + model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.Bundle.GetLangTagFromCtx(ctx)), }) } return rows, count, nil diff --git a/sqle/server/auditplan/task_type_mysql_slowlog_ali.go b/sqle/server/auditplan/task_type_mysql_slowlog_ali.go index 503310f3d..620d651c1 100644 --- a/sqle/server/auditplan/task_type_mysql_slowlog_ali.go +++ b/sqle/server/auditplan/task_type_mysql_slowlog_ali.go @@ -38,31 +38,31 @@ func (at *MySQLSlowLogAliTaskV2) Params(instanceId ...string) params.Params { Key: paramKeyDBInstanceId, Value: "", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamDBInstanceId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamDBInstanceId), }, { Key: paramKeyAccessKeyId, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeyId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeyId), }, { Key: paramKeyAccessKeySecret, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeySecret), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeySecret), }, { Key: paramKeyFirstSqlsScrappedInLastPeriodHours, Value: "24", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 31), + I18nDesc: locale.Bundle.LocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 31), }, { Key: paramKeyRdsPath, Value: "rds.aliyuncs.com", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamRdsPath), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamRdsPath), }, } } diff --git a/sqle/server/auditplan/task_type_mysql_slowlog_baidu.go b/sqle/server/auditplan/task_type_mysql_slowlog_baidu.go index c36e8a52d..c48af5c55 100644 --- a/sqle/server/auditplan/task_type_mysql_slowlog_baidu.go +++ b/sqle/server/auditplan/task_type_mysql_slowlog_baidu.go @@ -36,19 +36,19 @@ func (at *MySQLSlowLogBaiduTaskV2) Params(instanceId ...string) params.Params { Key: paramKeyDBInstanceId, Value: "", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamDBInstanceId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamDBInstanceId), }, { Key: paramKeyAccessKeyId, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeyId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeyId), }, { Key: paramKeyAccessKeySecret, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeySecret), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeySecret), }, { Key: paramKeyFirstSqlsScrappedInLastPeriodHours, @@ -56,13 +56,13 @@ func (at *MySQLSlowLogBaiduTaskV2) Params(instanceId ...string) params.Params { // https://cloud.baidu.com/doc/RDS/s/Tjwvz046g Value: "24", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 7), + I18nDesc: locale.Bundle.LocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 7), }, { Key: paramKeyRdsPath, Value: "rds.bj.baidubce.com", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamRdsPath), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamRdsPath), }, } } diff --git a/sqle/server/auditplan/task_type_mysql_slowlog_huawei.go b/sqle/server/auditplan/task_type_mysql_slowlog_huawei.go index 483645a23..5f7d914c1 100644 --- a/sqle/server/auditplan/task_type_mysql_slowlog_huawei.go +++ b/sqle/server/auditplan/task_type_mysql_slowlog_huawei.go @@ -41,37 +41,37 @@ func (at *MySQLSlowLogHuaweiTaskV2) Params(instanceId ...string) params.Params { Key: paramKeyProjectId, Value: "", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamProjectId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamProjectId), }, { Key: paramKeyDBInstanceId, Value: "", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamDBInstanceId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamDBInstanceId), }, { Key: paramKeyAccessKeyId, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeyId), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeyId), }, { Key: paramKeyAccessKeySecret, Value: "", Type: params.ParamTypePassword, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamAccessKeySecret), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamAccessKeySecret), }, { Key: paramKeyFirstSqlsScrappedInLastPeriodHours, Value: "24", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 30), + I18nDesc: locale.Bundle.LocalizeAllWithArgs(locale.ParamFirstCollectDurationWithMaxDays, 30), }, { Key: paramKeyRegion, Value: "", Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamRegion), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamRegion), }, } } diff --git a/sqle/server/auditplan/task_type_oracle_topsql.go b/sqle/server/auditplan/task_type_oracle_topsql.go index 9314e3ca3..0ea86fc8c 100644 --- a/sqle/server/auditplan/task_type_oracle_topsql.go +++ b/sqle/server/auditplan/task_type_oracle_topsql.go @@ -35,7 +35,7 @@ func (at *OracleTopSQLTaskV2) Params(instanceId ...string) params.Params { Key: paramKeyCollectIntervalMinute, Value: "60", Type: params.ParamTypeInt, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamCollectIntervalMinuteOracle), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamCollectIntervalMinuteOracle), }, { Key: "top_n", @@ -47,7 +47,7 @@ func (at *OracleTopSQLTaskV2) Params(instanceId ...string) params.Params { Key: "order_by_column", Value: oracle.DynPerformanceViewSQLAreaColumnElapsedTime, Type: params.ParamTypeString, - I18nDesc: locale.ShouldLocalizeAll(locale.ParamOrderByColumn), + I18nDesc: locale.Bundle.LocalizeAll(locale.ParamOrderByColumn), }, } @@ -235,7 +235,7 @@ func (at *OracleTopSQLTaskV2) GetSQLData(ctx context.Context, ap *AuditPlan, per MetricNameDiskReadTotal: strconv.Itoa(int(info.Get(MetricNameDiskReadTotal).Int())), MetricNameBufferGetCounter: strconv.Itoa(int(info.Get(MetricNameBufferGetCounter).Int())), MetricNameUserIOWaitTimeTotal: fmt.Sprintf("%v", utils.Round(info.Get(MetricNameUserIOWaitTimeTotal).Float()/1000, 3)), - model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.GetLangTagFromCtx(ctx)), + model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.Bundle.GetLangTagFromCtx(ctx)), }) } return rows, count, nil diff --git a/sqle/server/optimization/rule/rule.go b/sqle/server/optimization/rule/rule.go index 5c4a65839..f1c662a89 100644 --- a/sqle/server/optimization/rule/rule.go +++ b/sqle/server/optimization/rule/rule.go @@ -1,8 +1,8 @@ package optimization import ( + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" - "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/log" ) @@ -88,7 +88,7 @@ func init() { for i, rule := range optimizationRule { if knowledge, ok := defaultRulesKnowledge[rule.RuleCode]; ok { // todo i18n rewrite rule Knowledge - rule.Rule.I18nRuleInfo[locale.DefaultLang].Knowledge = driverV2.RuleKnowledge{Content: knowledge} + rule.Rule.I18nRuleInfo[i18nPkg.DefaultLang].Knowledge = driverV2.RuleKnowledge{Content: knowledge} optimizationRule[i] = rule } } diff --git a/sqle/server/pipeline/pipeline.go b/sqle/server/pipeline/pipeline.go index bec68bf66..0691e13e8 100644 --- a/sqle/server/pipeline/pipeline.go +++ b/sqle/server/pipeline/pipeline.go @@ -52,7 +52,7 @@ func (node PipelineNode) IntegrationInfo(ctx context.Context, projectName string switch model.PipelineNodeType(node.NodeType) { case model.NodeTypeAudit: - var cmdUsage = locale.ShouldLocalizeMsg(ctx, locale.PipelineCmdUsage) + var cmdUsage = locale.Bundle.LocalizeMsgByCtx(ctx, locale.PipelineCmdUsage) var cmd string var cmdType string diff --git a/sqle/server/sqled_test.go b/sqle/server/sqled_test.go index 19c4bf36b..048cb9f3b 100644 --- a/sqle/server/sqled_test.go +++ b/sqle/server/sqled_test.go @@ -9,12 +9,12 @@ import ( "regexp" "testing" + "github.com/actiontech/dms/pkg/dms-common/i18nPkg" "github.com/actiontech/sqle/sqle/driver" _ "github.com/actiontech/sqle/sqle/driver/mysql" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" "github.com/actiontech/sqle/sqle/log" "github.com/actiontech/sqle/sqle/model" - "github.com/actiontech/sqle/sqle/pkg/i18nPkg" sqlmock "github.com/DATA-DOG/go-sqlmock" "github.com/agiledragon/gomonkey" diff --git a/vendor/github.com/actiontech/dms/pkg/dms-common/api/dms/v1/user.go b/vendor/github.com/actiontech/dms/pkg/dms-common/api/dms/v1/user.go index 64603c31c..8cfb8413a 100644 --- a/vendor/github.com/actiontech/dms/pkg/dms-common/api/dms/v1/user.go +++ b/vendor/github.com/actiontech/dms/pkg/dms-common/api/dms/v1/user.go @@ -57,12 +57,6 @@ type UserBindProject struct { // swagger:enum Stat type Stat string -const ( - StatOK Stat = "正常" - StatDisable Stat = "被禁用" - StatUnknown Stat = "未知" -) - type UidWithName struct { Uid string `json:"uid"` Name string `json:"name"` diff --git a/sqle/pkg/i18nPkg/bundle.go b/vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/bundle.go similarity index 72% rename from sqle/pkg/i18nPkg/bundle.go rename to vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/bundle.go index e6dd498cc..19f9dc006 100644 --- a/sqle/pkg/i18nPkg/bundle.go +++ b/vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/bundle.go @@ -1,7 +1,5 @@ package i18nPkg -// todo i18n 将该包换到可以同时给dms sqle provision使用的地方 - import ( "context" "fmt" @@ -71,7 +69,7 @@ func (b *Bundle) GetLocalizer(tag language.Tag) *i18n.Localizer { return b.DefaultLocalizer() } -func (b *Bundle) shouldLocalizeMsg(localizer *i18n.Localizer, msg *i18n.Message) string { +func (b *Bundle) localizeMsg(localizer *i18n.Localizer, msg *i18n.Message) string { if msg == nil { b.logger.Errorf("i18nPkg localize nil msg") return "" @@ -83,45 +81,55 @@ func (b *Bundle) shouldLocalizeMsg(localizer *i18n.Localizer, msg *i18n.Message) return m } -func (b *Bundle) ShouldLocalizeMsg(ctx context.Context, msg *i18n.Message) string { +func (b *Bundle) LocalizeMsgByCtx(ctx context.Context, msg *i18n.Message) string { l, ok := ctx.Value(LocalizerCtxKey).(*i18n.Localizer) if !ok { l = b.DefaultLocalizer() b.logger.Errorf("i18nPkg No localizer in context when localize msg: %v, use default", msg.ID) } - return b.shouldLocalizeMsg(l, msg) + return b.localizeMsg(l, msg) } -func (b *Bundle) ShouldLocalizeMsgByLang(lang language.Tag, msg *i18n.Message) string { +func (b *Bundle) LocalizeMsgByLang(lang language.Tag, msg *i18n.Message) string { l := b.GetLocalizer(lang) - return b.shouldLocalizeMsg(l, msg) + return b.localizeMsg(l, msg) } -func (b *Bundle) ShouldLocalizeAll(msg *i18n.Message) I18nStr { +func (b *Bundle) LocalizeAll(msg *i18n.Message) I18nStr { result := make(I18nStr, len(b.localizers)) for langTag, localizer := range b.localizers { - result[langTag] = b.shouldLocalizeMsg(localizer, msg) + result[langTag] = b.localizeMsg(localizer, msg) } return result } -func (b *Bundle) ShouldLocalizeAllWithArgs(fmtMsg *i18n.Message, args ...any) I18nStr { +// LocalizeAllWithArgs if there is any i18n.Message or I18nStr in args, it will be Localized in the corresponding language too +func (b *Bundle) LocalizeAllWithArgs(fmtMsg *i18n.Message, args ...any) I18nStr { result := make(I18nStr, len(b.localizers)) - for langTag, localizer := range b.localizers { - result[langTag] = fmt.Sprintf(b.shouldLocalizeMsg(localizer, fmtMsg), args...) + msgs := map[int]*i18n.Message{} + i18nStrs := map[int]*I18nStr{} + for k, v := range args { + switch arg := v.(type) { + case i18n.Message: + msgs[k] = &arg + case *i18n.Message: + msgs[k] = arg + case I18nStr: + i18nStrs[k] = &arg + case *I18nStr: + i18nStrs[k] = arg + default: + } } - return result -} - -func (b *Bundle) ShouldLocalizeAllWithMsgArgs(fmtMsg *i18n.Message, msgArgs ...*i18n.Message) I18nStr { - result := make(I18nStr, len(b.localizers)) for langTag, localizer := range b.localizers { - strs := make([]any, len(msgArgs)) - for k, m := range msgArgs { - strs[k] = b.shouldLocalizeMsg(localizer, m) + for k := range msgs { + args[k] = b.localizeMsg(localizer, msgs[k]) + } + for k := range i18nStrs { + args[k] = i18nStrs[k].GetStrInLang(langTag) } - result[langTag] = fmt.Sprintf(b.shouldLocalizeMsg(localizer, fmtMsg), strs...) + result[langTag] = fmt.Sprintf(b.localizeMsg(localizer, fmtMsg), args...) } return result } diff --git a/sqle/pkg/i18nPkg/i18nStr.go b/vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/i18nStr.go similarity index 98% rename from sqle/pkg/i18nPkg/i18nStr.go rename to vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/i18nStr.go index 4ab510469..82b80deca 100644 --- a/sqle/pkg/i18nPkg/i18nStr.go +++ b/vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/i18nStr.go @@ -9,12 +9,14 @@ import ( ) func ConvertStr2I18nAsDefaultLang(s string) I18nStr { + if s == "" { + return nil + } return map[language.Tag]string{DefaultLang: s} } func ConvertStrMap2I18nStr(s map[string]string) (I18nStr, error) { if len(s) == 0 { - // todo i18n old plugin return nil, nil } if _, exist := s[DefaultLang.String()]; !exist { diff --git a/sqle/pkg/i18nPkg/log.go b/vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/log.go similarity index 89% rename from sqle/pkg/i18nPkg/log.go rename to vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/log.go index 7b611c603..e088692dd 100644 --- a/sqle/pkg/i18nPkg/log.go +++ b/vendor/github.com/actiontech/dms/pkg/dms-common/i18nPkg/log.go @@ -6,7 +6,6 @@ import ( ) type Log interface { - //Warnf(string, ...any) Errorf(string, ...any) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 2365c5eb0..56c2351ec 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -53,7 +53,7 @@ github.com/StackExchange/wmi # github.com/acomagu/bufpipe v1.0.4 ## explicit; go 1.12 github.com/acomagu/bufpipe -# github.com/actiontech/dms v0.0.0-20240830025931-20d313b918e8 +# github.com/actiontech/dms v0.0.0-20240912110939-20f9825907f5 ## explicit; go 1.19 github.com/actiontech/dms/pkg/dms-common/api/accesstoken github.com/actiontech/dms/pkg/dms-common/api/base/v1 @@ -61,6 +61,7 @@ github.com/actiontech/dms/pkg/dms-common/api/dms/v1 github.com/actiontech/dms/pkg/dms-common/api/jwt github.com/actiontech/dms/pkg/dms-common/conf github.com/actiontech/dms/pkg/dms-common/dmsobject +github.com/actiontech/dms/pkg/dms-common/i18nPkg github.com/actiontech/dms/pkg/dms-common/pkg/aes github.com/actiontech/dms/pkg/dms-common/pkg/http github.com/actiontech/dms/pkg/dms-common/register