We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f88ff2e + e35b955 commit c6b4ca4Copy full SHA for c6b4ca4
internal/base/handler/lang.go
@@ -23,11 +23,22 @@ import (
23
"context"
24
25
"github.com/apache/answer/internal/base/constant"
26
+ "github.com/gin-gonic/gin"
27
"github.com/segmentfault/pacman/i18n"
28
)
29
30
// GetLangByCtx get language from header
31
func GetLangByCtx(ctx context.Context) i18n.Language {
32
+ if ginCtx, ok := ctx.(*gin.Context); ok {
33
+ acceptLanguage, ok := ginCtx.Get(constant.AcceptLanguageFlag)
34
+ if ok {
35
+ if acceptLanguage, ok := acceptLanguage.(i18n.Language); ok {
36
+ return acceptLanguage
37
+ }
38
+ return i18n.DefaultLanguage
39
40
41
+
42
acceptLanguage, ok := ctx.Value(constant.AcceptLanguageContextKey).(i18n.Language)
43
if ok {
44
return acceptLanguage
0 commit comments