I18n: Add default locale server config option (#51035)

* I18n: Set default locale in server config and expose in grafanaBootData

* put default locale behind feature flag

* update tests now that default locale is behind feature flag

* little bit of PR feedback

* update sample.ini
This commit is contained in:
Josh Hunt
2022-06-21 11:12:49 +01:00
committed by GitHub
parent 370d6a6f7b
commit dcf786f3a9
6 changed files with 142 additions and 30 deletions
+8 -4
View File
@@ -691,12 +691,16 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
return nil, err
}
// Read locale from accept-language
acceptLang := c.Req.Header.Get("Accept-Language")
// Set locale to the preference, otherwise fall back to the accept language header.
// In practice, because the preference has configuration-backed default, the header
// shouldn't frequently be used
acceptLangHeader := c.Req.Header.Get("Accept-Language")
locale := "en-US"
if len(acceptLang) > 0 {
parts := strings.Split(acceptLang, ",")
if hs.Features.IsEnabled(featuremgmt.FlagInternationalization) && prefs.JSONData.Locale != "" {
locale = prefs.JSONData.Locale
} else if len(acceptLangHeader) > 0 {
parts := strings.Split(acceptLangHeader, ",")
locale = parts[0]
}