This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch fix/lang
in repository https://gitbox.apache.org/repos/asf/answer.git

commit e35b9551597aa5979b624b342e7e923cee814988
Author: LinkinStars <[email protected]>
AuthorDate: Mon Dec 15 12:34:42 2025 +0800

    fix(lang): enhance language retrieval from gin context
---
 internal/base/handler/lang.go | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/internal/base/handler/lang.go b/internal/base/handler/lang.go
index 8886f063..202449e9 100644
--- a/internal/base/handler/lang.go
+++ b/internal/base/handler/lang.go
@@ -23,11 +23,22 @@ import (
        "context"
 
        "github.com/apache/answer/internal/base/constant"
+       "github.com/gin-gonic/gin"
        "github.com/segmentfault/pacman/i18n"
 )
 
 // GetLangByCtx get language from header
 func GetLangByCtx(ctx context.Context) i18n.Language {
+       if ginCtx, ok := ctx.(*gin.Context); ok {
+               acceptLanguage, ok := ginCtx.Get(constant.AcceptLanguageFlag)
+               if ok {
+                       if acceptLanguage, ok := 
acceptLanguage.(i18n.Language); ok {
+                               return acceptLanguage
+                       }
+                       return i18n.DefaultLanguage
+               }
+       }
+
        acceptLanguage, ok := 
ctx.Value(constant.AcceptLanguageContextKey).(i18n.Language)
        if ok {
                return acceptLanguage

Reply via email to