diff --git a/_const/enum/cp_e/level.go b/_const/enum/cp_e/level.go index 8d49d2df9402f1a09cd46c530de32d02981543a3..3cbda5a20efea63c647507a360558317c4d66875 100644 --- a/_const/enum/cp_e/level.go +++ b/_const/enum/cp_e/level.go @@ -57,16 +57,16 @@ var ( CpPrivilegeActiveProfile: 240, CpPrivilegeMicEffect: 241, } - // cp特权描述 // todo 翻译 + // cp特权描述 CpPrivilegeDescMsgId = map[CpPrivilege]uint{ - CpPrivilegeSpace: 0, - CpPrivilegeBanner: 0, - CpPrivilegeMedal: 0, - CpPrivilegeCert: 0, - CpPrivilegeRoomEffect: 0, - CpPrivilegeHeadwear: 0, - CpPrivilegeActiveProfile: 0, - CpPrivilegeMicEffect: 0, + CpPrivilegeSpace: 264, + CpPrivilegeBanner: 265, + CpPrivilegeMedal: 266, + CpPrivilegeCert: 267, + CpPrivilegeRoomEffect: 268, + CpPrivilegeHeadwear: 269, + CpPrivilegeActiveProfile: 270, + CpPrivilegeMicEffect: 271, } // cp特权icon // todo ui CpPrivilegeIcon = map[CpPrivilege]string{ diff --git a/domain/model/cp_m/anniversary.go b/domain/model/cp_m/anniversary.go index 80a4c5302875d44cc7a795d3929ef908f83b848c..958498d01a373eaa6bc95827db167742b3150073 100644 --- a/domain/model/cp_m/anniversary.go +++ b/domain/model/cp_m/anniversary.go @@ -4,7 +4,9 @@ import ( "fmt" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" + "github.com/bluele/gcache" "hilo-user/_const/enum/cp_e" + "hilo-user/domain/model/res_m" "hilo-user/domain/model/user_m" "time" ) @@ -25,33 +27,46 @@ type CpAnniversary struct { // 初始化6个cp纪念日 // 1)我们在一起;2)XXX的生日;3)XXX的生日;4)第一次说我爱你;5)第一次亲吻;6)结婚纪念日 -// todo 翻译 -func InitCpAnniversary(model *domain.Model, cp CpRelationTmp) error { +func InitCpAnniversary(model *domain.Model, cp CpRelationTmp, lang string) error { users, err := user_m.GetUserMapByIds(model, []uint64{cp.UserId1, cp.UserId2}) if err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "我们在一起", time.Now().Unix(), true, 100); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(259, lang), time.Now().Unix(), true, 100); err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf("%s的生日", users[cp.UserId1].Nick), 0, true, 0); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId1].Nick), 0, true, 0); err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf("%s的生日", users[cp.UserId2].Nick), 0, true, 0); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId2].Nick), 0, true, 0); err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "第一次说我爱你", 0, false, 0); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(261, lang), 0, false, 0); err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "第一次亲吻", 0, false, 0); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(262, lang), 0, false, 0); err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, "结婚纪念日", 0, false, 0); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, GetTranslate(263, lang), 0, false, 0); err != nil { return err } return nil } +var translateCache = gcache.New(1000).LRU().Build() + +func GetTranslate(msgId uint, lang string) string { + key := fmt.Sprintf("%v-%v", msgId, lang) + if data, err := translateCache.Get(key); err == nil { + return data.(string) + } + if resMul, _ := res_m.GetResMultiTextBy(mysql.Db, msgId, lang); resMul != nil { + _ = translateCache.SetWithExpire(key, resMul.Content, time.Hour) + return resMul.Content + } + return "default" +} + // 添加cp纪念日 func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpRelationTmp, content string, ts int64, isRemind bool, sort int) error { return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{