mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 00:46:42 +00:00
Merge pull request #2842 from QuantumNous/feat/backend-i18n
feat: backend i18n
This commit is contained in:
@@ -11,6 +11,9 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ErrRedeemFailed is returned when redemption fails due to database error
|
||||
var ErrRedeemFailed = errors.New("redeem.failed")
|
||||
|
||||
type Redemption struct {
|
||||
Id int `json:"id"`
|
||||
UserId int `json:"user_id"`
|
||||
@@ -149,7 +152,7 @@ func Redeem(key string, userId int) (quota int, err error) {
|
||||
})
|
||||
if err != nil {
|
||||
common.SysError("redemption failed: " + err.Error())
|
||||
return 0, errors.New("兑换失败,请稍后重试")
|
||||
return 0, ErrRedeemFailed
|
||||
}
|
||||
RecordLog(userId, LogTypeTopup, fmt.Sprintf("通过兑换码充值 %s,兑换码ID %d", logger.LogQuota(redemption.Quota), redemption.Id))
|
||||
return redemption.Quota, nil
|
||||
|
||||
@@ -221,3 +221,13 @@ func updateUserSettingCache(userId int, setting string) error {
|
||||
}
|
||||
return common.RedisHSetField(getUserCacheKey(userId), "Setting", setting)
|
||||
}
|
||||
|
||||
// GetUserLanguage returns the user's language preference from cache
|
||||
// Uses the existing GetUserCache mechanism for efficiency
|
||||
func GetUserLanguage(userId int) string {
|
||||
userCache, err := GetUserCache(userId)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return userCache.GetSetting().Language
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user