fix(i18n): prioritize user settings over Accept-Language header

The i18n middleware runs before UserAuth, so user settings weren't
available when language was detected. Now GetLangFromContext checks
user settings first (set by UserAuth) before falling back to the
language set by middleware or Accept-Language header.
This commit is contained in:
CaIon
2026-02-05 00:20:47 +08:00
parent 42b5aeaae4
commit 67613e0642
8 changed files with 69 additions and 17 deletions

View File

@@ -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
}