i18n: rename locale to regionalFormat (#106585)

* locale -> regionalFormat, mirroring #102233

* set up regionalFormat to replace locale entirely

* replace locale with regionalFormat

* update reportInteraction arguments
This commit is contained in:
Luminessa Starlight
2025-06-16 21:53:55 +02:00
committed by GitHub
parent c00caa2fb2
commit 09e8484bac
19 changed files with 103 additions and 99 deletions
+1
View File
@@ -45,6 +45,7 @@ type CurrentUser struct {
Timezone string `json:"timezone"`
WeekStart string `json:"weekStart"`
Locale string `json:"locale"`
RegionalFormat string `json:"regionalFormat"`
Language string `json:"language"`
HelpFlags1 user.HelpFlags1 `json:"helpFlags1"`
HasEditPermissionInFolders bool `json:"hasEditPermissionInFolders"`
+8 -8
View File
@@ -14,13 +14,13 @@ type UpdatePrefsCmd struct {
HomeDashboardID int64 `json:"homeDashboardId"`
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
// Enum: utc,browser
Timezone string `json:"timezone"`
WeekStart string `json:"weekStart"`
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
Language string `json:"language"`
Locale string `json:"locale"`
Cookies []pref.CookieType `json:"cookies,omitempty"`
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
Timezone string `json:"timezone"`
WeekStart string `json:"weekStart"`
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
Language string `json:"language"`
RegionalFormat string `json:"regionalFormat"`
Cookies []pref.CookieType `json:"cookies,omitempty"`
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
}
// swagger:model
@@ -35,7 +35,7 @@ type PatchPrefsCmd struct {
Timezone *string `json:"timezone,omitempty"`
WeekStart *string `json:"weekStart,omitempty"`
Language *string `json:"language,omitempty"`
Locale *string `json:"locale,omitempty"`
RegionalFormat *string `json:"regionalFormat,omitempty"`
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
Cookies []pref.CookieType `json:"cookies,omitempty"`
+16 -14
View File
@@ -24,21 +24,21 @@ import (
)
type URLPrefs struct {
Language string
Locale string
Theme string
Language string
RegionalFormat string
Theme string
}
// URL prefs take precedence over any saved user preferences
func getURLPrefs(c *contextmodel.ReqContext) URLPrefs {
language := c.Query("lang")
theme := c.Query("theme")
locale := c.Query("locale")
regionalFormat := c.Query("regionalFormat")
return URLPrefs{
Language: language,
Locale: locale,
Theme: theme,
Language: language,
RegionalFormat: regionalFormat,
Theme: theme,
}
}
@@ -70,7 +70,8 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
// translating words in the interface
acceptLangHeader := c.Req.Header.Get("Accept-Language")
locale := "en-US" // default to en formatting, but use the accept-lang header or user's preference
language := "" // frontend will set the default language
var regionalFormat string
language := "" // frontend will set the default language
urlPrefs := getURLPrefs(c)
if urlPrefs.Language != "" {
@@ -85,11 +86,11 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
}
if hs.Features.IsEnabled(c.Req.Context(), featuremgmt.FlagLocaleFormatPreference) {
locale = "en" // default to "en", not "en-US", matching the locale code
if urlPrefs.Locale != "" {
locale = urlPrefs.Locale
} else if prefs.JSONData.Locale != "" {
locale = prefs.JSONData.Locale
regionalFormat = "en" // default to "en", not "en-US", matching the regionalFormat code
if urlPrefs.RegionalFormat != "" {
regionalFormat = urlPrefs.RegionalFormat
} else if prefs.JSONData.RegionalFormat != "" {
regionalFormat = prefs.JSONData.RegionalFormat
}
}
@@ -140,7 +141,8 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
LightTheme: theme.Type == "light",
Timezone: prefs.Timezone,
WeekStart: weekStart,
Locale: locale,
Locale: locale, // << will be removed in favor of RegionalFormat
RegionalFormat: regionalFormat,
Language: language,
HelpFlags1: c.HelpFlags1,
HasEditPermissionInFolders: hasEditPerm,
+1 -1
View File
@@ -172,7 +172,7 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
HomeDashboardID: dtoCmd.HomeDashboardID, // nolint:staticcheck
HomeDashboardUID: dtoCmd.HomeDashboardUID,
Language: dtoCmd.Language,
Locale: dtoCmd.Locale,
RegionalFormat: dtoCmd.RegionalFormat,
QueryHistory: dtoCmd.QueryHistory,
CookiePreferences: dtoCmd.Cookies,
Navbar: dtoCmd.Navbar,