GetLangByCtx get language from header
(ctx context.Context)
| 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 |
| 45 | } |
| 46 | return i18n.DefaultLanguage |
| 47 | } |
no test coverage detected