MCPcopy
hub / github.com/apache/answer / GetLangByCtx

Function GetLangByCtx

internal/base/handler/lang.go:31–47  ·  view source on GitHub ↗

GetLangByCtx get language from header

(ctx context.Context)

Source from the content-addressed store, hash-verified

29
30// GetLangByCtx get language from header
31func 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
45 }
46 return i18n.DefaultLanguage
47}

Callers 15

TranslateFunction · 0.92
EditUserProfileMethod · 0.92
AddCommentMethod · 0.92
RemoveCommentMethod · 0.92
UpdateCommentMethod · 0.92
SearchMethod · 0.92
VoteUpMethod · 0.92
VoteDownMethod · 0.92
RemoveQuestionMethod · 0.92
AddQuestionMethod · 0.92
AddQuestionByAnswerMethod · 0.92
UpdateQuestionMethod · 0.92

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected