i18n: rename locale to regionalFormat (#106585)

* locale -> regionalFormat, mirroring #102233

* set up regionalFormat to replace locale entirely

* replace locale with regionalFormat

* update reportInteraction arguments
simpson-query-service-sse
Luminessa Starlight 6 months ago committed by GitHub
parent c00caa2fb2
commit 09e8484bac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      kinds/preferences/preferences_kind.cue
  2. 4
      packages/grafana-data/src/types/config.ts
  3. 9
      packages/grafana-runtime/src/config.ts
  4. 8
      packages/grafana-schema/src/raw/preferences/x/preferences_types.gen.ts
  5. 1
      pkg/api/dtos/models.go
  6. 16
      pkg/api/dtos/prefs.go
  7. 30
      pkg/api/index.go
  8. 2
      pkg/api/preferences.go
  9. 2
      pkg/kinds/preferences/preferences_spec_gen.go
  10. 6
      pkg/services/preference/model.go
  11. 6
      pkg/services/preference/prefapi/api.go
  12. 12
      pkg/services/preference/prefimpl/pref.go
  13. 22
      pkg/services/preference/prefimpl/pref_test.go
  14. 20
      public/api-merged.json
  15. 4
      public/app/app.ts
  16. 30
      public/app/core/components/SharedPreferences/SharedPreferences.tsx
  17. 4
      public/app/core/internationalization/dates.ts
  18. 4
      public/app/core/services/context_srv.ts
  19. 20
      public/openapi3.json

@ -28,7 +28,7 @@ lineage: schemas: [{
language?: string language?: string
// Selected locale (beta) // Selected locale (beta)
locale?: string regionalFormat?: string
// Explore query history preferences // Explore query history preferences
queryHistory?: #QueryHistoryPreference queryHistory?: #QueryHistoryPreference

@ -129,7 +129,7 @@ export interface CurrentUserDTO {
gravatarUrl: string; gravatarUrl: string;
timezone: string; timezone: string;
weekStart: string; weekStart: string;
locale: string; regionalFormat: string;
language: string; language: string;
permissions?: Record<string, boolean>; permissions?: Record<string, boolean>;
analytics: AnalyticsSettings; analytics: AnalyticsSettings;
@ -251,7 +251,7 @@ export interface GrafanaConfig {
* Grafana's supported language. * Grafana's supported language.
*/ */
language: string | undefined; language: string | undefined;
locale: string; regionalFormat: string;
} }
export interface SqlConnectionLimits { export interface SqlConnectionLimits {

@ -213,10 +213,10 @@ export class GrafanaBootConfig implements GrafanaConfig {
language: string | undefined; language: string | undefined;
/** /**
* Locale used in Grafana's UI. Default to 'es-US' in the backend and overwritten when the user select a different one in SharedPreferences. * regionalFormat used in Grafana's UI. Default to 'es-US' in the backend and overwritten when the user select a different one in SharedPreferences.
* This is the locale that is used for date formatting and other locale-specific features. * This is the regionalFormat that is used for date formatting and other locale-specific features.
*/ */
locale: string; regionalFormat: string;
constructor(options: GrafanaBootConfig) { constructor(options: GrafanaBootConfig) {
this.bootData = options.bootData; this.bootData = options.bootData;
@ -253,8 +253,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
this.theme2 = getThemeById(this.bootData.user.theme); this.theme2 = getThemeById(this.bootData.user.theme);
this.bootData.user.lightTheme = this.theme2.isLight; this.bootData.user.lightTheme = this.theme2.isLight;
this.theme = this.theme2.v1; this.theme = this.theme2.v1;
this.regionalFormat = options.bootData.user.regionalFormat;
this.locale = options.bootData.user.locale;
} }
geomapDefaultBaseLayer?: MapLayerOptions<any> | undefined; geomapDefaultBaseLayer?: MapLayerOptions<any> | undefined;
listDashboardScopesEndpoint?: string | undefined; listDashboardScopesEndpoint?: string | undefined;

@ -46,10 +46,6 @@ export interface Preferences {
* Selected language (beta) * Selected language (beta)
*/ */
language?: string; language?: string;
/**
* Selected locale (beta)
*/
locale?: string;
/** /**
* Navigation preferences * Navigation preferences
*/ */
@ -58,6 +54,10 @@ export interface Preferences {
* Explore query history preferences * Explore query history preferences
*/ */
queryHistory?: QueryHistoryPreference; queryHistory?: QueryHistoryPreference;
/**
* Selected locale (beta)
*/
regionalFormat?: string;
/** /**
* light, dark, empty is default * light, dark, empty is default
*/ */

@ -45,6 +45,7 @@ type CurrentUser struct {
Timezone string `json:"timezone"` Timezone string `json:"timezone"`
WeekStart string `json:"weekStart"` WeekStart string `json:"weekStart"`
Locale string `json:"locale"` Locale string `json:"locale"`
RegionalFormat string `json:"regionalFormat"`
Language string `json:"language"` Language string `json:"language"`
HelpFlags1 user.HelpFlags1 `json:"helpFlags1"` HelpFlags1 user.HelpFlags1 `json:"helpFlags1"`
HasEditPermissionInFolders bool `json:"hasEditPermissionInFolders"` HasEditPermissionInFolders bool `json:"hasEditPermissionInFolders"`

@ -14,13 +14,13 @@ type UpdatePrefsCmd struct {
HomeDashboardID int64 `json:"homeDashboardId"` HomeDashboardID int64 `json:"homeDashboardId"`
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"` HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
// Enum: utc,browser // Enum: utc,browser
Timezone string `json:"timezone"` Timezone string `json:"timezone"`
WeekStart string `json:"weekStart"` WeekStart string `json:"weekStart"`
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"` QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
Language string `json:"language"` Language string `json:"language"`
Locale string `json:"locale"` RegionalFormat string `json:"regionalFormat"`
Cookies []pref.CookieType `json:"cookies,omitempty"` Cookies []pref.CookieType `json:"cookies,omitempty"`
Navbar *pref.NavbarPreference `json:"navbar,omitempty"` Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
} }
// swagger:model // swagger:model
@ -35,7 +35,7 @@ type PatchPrefsCmd struct {
Timezone *string `json:"timezone,omitempty"` Timezone *string `json:"timezone,omitempty"`
WeekStart *string `json:"weekStart,omitempty"` WeekStart *string `json:"weekStart,omitempty"`
Language *string `json:"language,omitempty"` Language *string `json:"language,omitempty"`
Locale *string `json:"locale,omitempty"` RegionalFormat *string `json:"regionalFormat,omitempty"`
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"` QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"` HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`
Cookies []pref.CookieType `json:"cookies,omitempty"` Cookies []pref.CookieType `json:"cookies,omitempty"`

@ -24,21 +24,21 @@ import (
) )
type URLPrefs struct { type URLPrefs struct {
Language string Language string
Locale string RegionalFormat string
Theme string Theme string
} }
// URL prefs take precedence over any saved user preferences // URL prefs take precedence over any saved user preferences
func getURLPrefs(c *contextmodel.ReqContext) URLPrefs { func getURLPrefs(c *contextmodel.ReqContext) URLPrefs {
language := c.Query("lang") language := c.Query("lang")
theme := c.Query("theme") theme := c.Query("theme")
locale := c.Query("locale") regionalFormat := c.Query("regionalFormat")
return URLPrefs{ return URLPrefs{
Language: language, Language: language,
Locale: locale, RegionalFormat: regionalFormat,
Theme: theme, Theme: theme,
} }
} }
@ -70,7 +70,8 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
// translating words in the interface // translating words in the interface
acceptLangHeader := c.Req.Header.Get("Accept-Language") acceptLangHeader := c.Req.Header.Get("Accept-Language")
locale := "en-US" // default to en formatting, but use the accept-lang header or user's preference 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) urlPrefs := getURLPrefs(c)
if urlPrefs.Language != "" { 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) { if hs.Features.IsEnabled(c.Req.Context(), featuremgmt.FlagLocaleFormatPreference) {
locale = "en" // default to "en", not "en-US", matching the locale code regionalFormat = "en" // default to "en", not "en-US", matching the regionalFormat code
if urlPrefs.Locale != "" { if urlPrefs.RegionalFormat != "" {
locale = urlPrefs.Locale regionalFormat = urlPrefs.RegionalFormat
} else if prefs.JSONData.Locale != "" { } else if prefs.JSONData.RegionalFormat != "" {
locale = prefs.JSONData.Locale regionalFormat = prefs.JSONData.RegionalFormat
} }
} }
@ -140,7 +141,8 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
LightTheme: theme.Type == "light", LightTheme: theme.Type == "light",
Timezone: prefs.Timezone, Timezone: prefs.Timezone,
WeekStart: weekStart, WeekStart: weekStart,
Locale: locale, Locale: locale, // << will be removed in favor of RegionalFormat
RegionalFormat: regionalFormat,
Language: language, Language: language,
HelpFlags1: c.HelpFlags1, HelpFlags1: c.HelpFlags1,
HasEditPermissionInFolders: hasEditPerm, HasEditPermissionInFolders: hasEditPerm,

@ -172,7 +172,7 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
HomeDashboardID: dtoCmd.HomeDashboardID, // nolint:staticcheck HomeDashboardID: dtoCmd.HomeDashboardID, // nolint:staticcheck
HomeDashboardUID: dtoCmd.HomeDashboardUID, HomeDashboardUID: dtoCmd.HomeDashboardUID,
Language: dtoCmd.Language, Language: dtoCmd.Language,
Locale: dtoCmd.Locale, RegionalFormat: dtoCmd.RegionalFormat,
QueryHistory: dtoCmd.QueryHistory, QueryHistory: dtoCmd.QueryHistory,
CookiePreferences: dtoCmd.Cookies, CookiePreferences: dtoCmd.Cookies,
Navbar: dtoCmd.Navbar, Navbar: dtoCmd.Navbar,

@ -26,7 +26,7 @@ type Spec struct {
// Selected language (beta) // Selected language (beta)
Language *string `json:"language,omitempty"` Language *string `json:"language,omitempty"`
// Selected locale (beta) // Selected locale (beta)
Locale *string `json:"locale,omitempty"` RegionalFormat *string `json:"regionalFormat,omitempty"`
// Explore query history preferences // Explore query history preferences
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"` QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
// Cookie preferences // Cookie preferences

@ -68,7 +68,7 @@ type SavePreferenceCommand struct {
WeekStart string `json:"weekStart,omitempty"` WeekStart string `json:"weekStart,omitempty"`
Theme string `json:"theme,omitempty"` Theme string `json:"theme,omitempty"`
Language string `json:"language,omitempty"` Language string `json:"language,omitempty"`
Locale string `json:"locale,omitempty"` RegionalFormat string `json:"regionalFormat,omitempty"`
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"` QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
CookiePreferences []CookieType `json:"cookiePreferences,omitempty"` CookiePreferences []CookieType `json:"cookiePreferences,omitempty"`
Navbar *NavbarPreference `json:"navbar,omitempty"` Navbar *NavbarPreference `json:"navbar,omitempty"`
@ -86,7 +86,7 @@ type PatchPreferenceCommand struct {
WeekStart *string `json:"weekStart,omitempty"` WeekStart *string `json:"weekStart,omitempty"`
Theme *string `json:"theme,omitempty"` Theme *string `json:"theme,omitempty"`
Language *string `json:"language,omitempty"` Language *string `json:"language,omitempty"`
Locale *string `json:"locale,omitempty"` RegionalFormat *string `json:"regionalFormat,omitempty"`
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"` QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
CookiePreferences []CookieType `json:"cookiePreferences,omitempty"` CookiePreferences []CookieType `json:"cookiePreferences,omitempty"`
Navbar *NavbarPreference `json:"navbar,omitempty"` Navbar *NavbarPreference `json:"navbar,omitempty"`
@ -94,7 +94,7 @@ type PatchPreferenceCommand struct {
type PreferenceJSONData struct { type PreferenceJSONData struct {
Language string `json:"language"` Language string `json:"language"`
Locale string `json:"locale"` RegionalFormat string `json:"regionalFormat"`
QueryHistory QueryHistoryPreference `json:"queryHistory"` QueryHistory QueryHistoryPreference `json:"queryHistory"`
CookiePreferences map[string]struct{} `json:"cookiePreferences"` CookiePreferences map[string]struct{} `json:"cookiePreferences"`
Navbar NavbarPreference `json:"navbar"` Navbar NavbarPreference `json:"navbar"`

@ -62,7 +62,7 @@ func UpdatePreferencesFor(ctx context.Context,
} }
if features.IsEnabled(ctx, featuremgmt.FlagLocaleFormatPreference) { if features.IsEnabled(ctx, featuremgmt.FlagLocaleFormatPreference) {
saveCmd.Locale = dtoCmd.Locale saveCmd.RegionalFormat = dtoCmd.RegionalFormat
} }
if err := preferenceService.Save(ctx, &saveCmd); err != nil { if err := preferenceService.Save(ctx, &saveCmd); err != nil {
@ -102,8 +102,8 @@ func GetPreferencesFor(ctx context.Context,
} }
if features.IsEnabled(ctx, featuremgmt.FlagLocaleFormatPreference) { if features.IsEnabled(ctx, featuremgmt.FlagLocaleFormatPreference) {
if preference.JSONData.Locale != "" { if preference.JSONData.RegionalFormat != "" {
dto.Locale = &preference.JSONData.Locale dto.RegionalFormat = &preference.JSONData.RegionalFormat
} }
} }

@ -72,8 +72,8 @@ func (s *Service) GetWithDefaults(ctx context.Context, query *pref.GetPreference
res.JSONData.Language = p.JSONData.Language res.JSONData.Language = p.JSONData.Language
} }
if p.JSONData.Locale != "" { if p.JSONData.RegionalFormat != "" {
res.JSONData.Locale = p.JSONData.Locale res.JSONData.RegionalFormat = p.JSONData.RegionalFormat
} }
if p.JSONData.QueryHistory.HomeTab != "" { if p.JSONData.QueryHistory.HomeTab != "" {
@ -192,11 +192,11 @@ func (s *Service) Patch(ctx context.Context, cmd *pref.PatchPreferenceCommand) e
preference.JSONData.Language = *cmd.Language preference.JSONData.Language = *cmd.Language
} }
if cmd.Locale != nil { if cmd.RegionalFormat != nil {
if preference.JSONData == nil { if preference.JSONData == nil {
preference.JSONData = &pref.PreferenceJSONData{} preference.JSONData = &pref.PreferenceJSONData{}
} }
preference.JSONData.Locale = *cmd.Locale preference.JSONData.RegionalFormat = *cmd.RegionalFormat
} }
if cmd.Navbar != nil && cmd.Navbar.BookmarkUrls != nil { if cmd.Navbar != nil && cmd.Navbar.BookmarkUrls != nil {
@ -296,8 +296,8 @@ func parseCookiePreferences(prefs []pref.CookieType) (map[string]struct{}, error
func preferenceData(cmd *pref.SavePreferenceCommand) (*pref.PreferenceJSONData, error) { func preferenceData(cmd *pref.SavePreferenceCommand) (*pref.PreferenceJSONData, error) {
jsonData := &pref.PreferenceJSONData{ jsonData := &pref.PreferenceJSONData{
Language: cmd.Language, Language: cmd.Language,
Locale: cmd.Locale, RegionalFormat: cmd.RegionalFormat,
} }
if cmd.Navbar != nil { if cmd.Navbar != nil {
jsonData.Navbar = *cmd.Navbar jsonData.Navbar = *cmd.Navbar

@ -94,8 +94,8 @@ func TestGetWithDefaults_withUserAndOrgPrefs(t *testing.T) {
WeekStart: &weekStartOne, WeekStart: &weekStartOne,
HomeDashboardUID: "test-uid", HomeDashboardUID: "test-uid",
JSONData: &pref.PreferenceJSONData{ JSONData: &pref.PreferenceJSONData{
Language: "en-GB", Language: "en-GB",
Locale: "en", RegionalFormat: "en",
}, },
}, },
pref.Preference{ pref.Preference{
@ -107,8 +107,8 @@ func TestGetWithDefaults_withUserAndOrgPrefs(t *testing.T) {
Timezone: "browser", Timezone: "browser",
WeekStart: &weekStartTwo, WeekStart: &weekStartTwo,
JSONData: &pref.PreferenceJSONData{ JSONData: &pref.PreferenceJSONData{
Language: "en-AU", Language: "en-AU",
Locale: "es", RegionalFormat: "es",
}, },
}, },
) )
@ -124,8 +124,8 @@ func TestGetWithDefaults_withUserAndOrgPrefs(t *testing.T) {
HomeDashboardID: 4, // nolint:staticcheck HomeDashboardID: 4, // nolint:staticcheck
HomeDashboardUID: "test-uid4", HomeDashboardUID: "test-uid4",
JSONData: &pref.PreferenceJSONData{ JSONData: &pref.PreferenceJSONData{
Language: "en-AU", Language: "en-AU",
Locale: "es", RegionalFormat: "es",
}, },
} }
if diff := cmp.Diff(expected, preference); diff != "" { if diff := cmp.Diff(expected, preference); diff != "" {
@ -145,8 +145,8 @@ func TestGetWithDefaults_withUserAndOrgPrefs(t *testing.T) {
HomeDashboardID: 1, // nolint:staticcheck HomeDashboardID: 1, // nolint:staticcheck
HomeDashboardUID: "test-uid", HomeDashboardUID: "test-uid",
JSONData: &pref.PreferenceJSONData{ JSONData: &pref.PreferenceJSONData{
Language: "en-GB", Language: "en-GB",
Locale: "en", RegionalFormat: "en",
}, },
} }
if diff := cmp.Diff(expected, preference); diff != "" { if diff := cmp.Diff(expected, preference); diff != "" {
@ -168,7 +168,7 @@ func TestGetDefaults_JSONData(t *testing.T) {
Language: "en-GB", Language: "en-GB",
} }
orgPreferencesWithLocaleJsonData := pref.PreferenceJSONData{ orgPreferencesWithLocaleJsonData := pref.PreferenceJSONData{
Locale: "en", RegionalFormat: "en",
} }
team2PreferencesJsonData := pref.PreferenceJSONData{} team2PreferencesJsonData := pref.PreferenceJSONData{}
team1PreferencesJsonData := pref.PreferenceJSONData{} team1PreferencesJsonData := pref.PreferenceJSONData{}
@ -254,8 +254,8 @@ func TestGetDefaults_JSONData(t *testing.T) {
require.Equal(t, &pref.Preference{ require.Equal(t, &pref.Preference{
WeekStart: &weekStart, WeekStart: &weekStart,
JSONData: &pref.PreferenceJSONData{ JSONData: &pref.PreferenceJSONData{
Locale: "en", RegionalFormat: "en",
QueryHistory: queryPreference, QueryHistory: queryPreference,
}, },
}, preference) }, preference)
}) })

@ -18052,15 +18052,15 @@
"language": { "language": {
"type": "string" "type": "string"
}, },
"locale": {
"type": "string"
},
"navbar": { "navbar": {
"$ref": "#/definitions/NavbarPreference" "$ref": "#/definitions/NavbarPreference"
}, },
"queryHistory": { "queryHistory": {
"$ref": "#/definitions/QueryHistoryPreference" "$ref": "#/definitions/QueryHistoryPreference"
}, },
"regionalFormat": {
"type": "string"
},
"theme": { "theme": {
"type": "string", "type": "string",
"enum": [ "enum": [
@ -18680,16 +18680,16 @@
"description": "Selected language (beta)", "description": "Selected language (beta)",
"type": "string" "type": "string"
}, },
"locale": {
"description": "Selected locale (beta)",
"type": "string"
},
"navbar": { "navbar": {
"$ref": "#/definitions/NavbarPreference" "$ref": "#/definitions/NavbarPreference"
}, },
"queryHistory": { "queryHistory": {
"$ref": "#/definitions/QueryHistoryPreference" "$ref": "#/definitions/QueryHistoryPreference"
}, },
"regionalFormat": {
"description": "Selected locale (beta)",
"type": "string"
},
"theme": { "theme": {
"description": "light, dark, empty is default", "description": "light, dark, empty is default",
"type": "string" "type": "string"
@ -22296,15 +22296,15 @@
"language": { "language": {
"type": "string" "type": "string"
}, },
"locale": {
"type": "string"
},
"navbar": { "navbar": {
"$ref": "#/definitions/NavbarPreference" "$ref": "#/definitions/NavbarPreference"
}, },
"queryHistory": { "queryHistory": {
"$ref": "#/definitions/QueryHistoryPreference" "$ref": "#/definitions/QueryHistoryPreference"
}, },
"regionalFormat": {
"type": "string"
},
"theme": { "theme": {
"type": "string", "type": "string",
"enum": [ "enum": [

@ -127,7 +127,7 @@ export class GrafanaApp {
// Let iframe container know grafana has started loading // Let iframe container know grafana has started loading
window.parent.postMessage('GrafanaAppInit', '*'); window.parent.postMessage('GrafanaAppInit', '*');
const regionalFormat = config.featureToggles.localeFormatPreference const regionalFormat = config.featureToggles.localeFormatPreference
? config.locale ? config.regionalFormat
: config.bootData.user.language; : config.bootData.user.language;
const initI18nPromise = initializeI18n( const initI18nPromise = initializeI18n(
@ -149,7 +149,7 @@ export class GrafanaApp {
// This needs to be done after the `initEchoSrv` since it is being used under the hood. // This needs to be done after the `initEchoSrv` since it is being used under the hood.
startMeasure('frontend_app_init'); startMeasure('frontend_app_init');
setLocale(config.locale); setLocale(config.regionalFormat);
setWeekStart(config.bootData.user.weekStart); setWeekStart(config.bootData.user.weekStart);
setPanelRenderer(PanelRenderer); setPanelRenderer(PanelRenderer);
setPluginPage(PluginPage); setPluginPage(PluginPage);

@ -68,7 +68,7 @@ function getLanguageOptions(): ComboboxOption[] {
return options; return options;
} }
function getLocaleOptions(): ComboboxOption[] { function getRegionalFormatOptions(): ComboboxOption[] {
const localeOptions = LOCALES.map((v) => ({ const localeOptions = LOCALES.map((v) => ({
value: v.code, value: v.code,
label: v.name, label: v.name,
@ -90,7 +90,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
service: PreferencesService; service: PreferencesService;
themeOptions: ComboboxOption[]; themeOptions: ComboboxOption[];
languageOptions: ComboboxOption[]; languageOptions: ComboboxOption[];
localeOptions: ComboboxOption[]; regionalFormatOptions: ComboboxOption[];
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
@ -103,7 +103,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
timezone: '', timezone: '',
weekStart: '', weekStart: '',
language: '', language: '',
locale: '', regionalFormat: '',
queryHistory: { homeTab: '' }, queryHistory: { homeTab: '' },
navbar: { bookmarkUrls: [] }, navbar: { bookmarkUrls: [] },
}; };
@ -118,7 +118,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
group: theme.isExtra ? t('shared-preferences.theme.experimental', 'Experimental') : undefined, group: theme.isExtra ? t('shared-preferences.theme.experimental', 'Experimental') : undefined,
})); }));
this.languageOptions = getLanguageOptions(); this.languageOptions = getLanguageOptions();
this.localeOptions = getLocaleOptions(); this.regionalFormatOptions = getRegionalFormatOptions();
// Add default option // Add default option
this.themeOptions.unshift({ value: '', label: t('shared-preferences.theme.default-label', 'Default') }); this.themeOptions.unshift({ value: '', label: t('shared-preferences.theme.default-label', 'Default') });
@ -137,7 +137,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
timezone: prefs.timezone, timezone: prefs.timezone,
weekStart: prefs.weekStart, weekStart: prefs.weekStart,
language: prefs.language, language: prefs.language,
locale: prefs.locale, regionalFormat: prefs.regionalFormat,
queryHistory: prefs.queryHistory, queryHistory: prefs.queryHistory,
navbar: prefs.navbar, navbar: prefs.navbar,
}); });
@ -148,7 +148,8 @@ export class SharedPreferences extends PureComponent<Props, State> {
const confirmationResult = this.props.onConfirm ? await this.props.onConfirm() : true; const confirmationResult = this.props.onConfirm ? await this.props.onConfirm() : true;
if (confirmationResult) { if (confirmationResult) {
const { homeDashboardUID, theme, timezone, weekStart, language, locale, queryHistory, navbar } = this.state; const { homeDashboardUID, theme, timezone, weekStart, language, regionalFormat, queryHistory, navbar } =
this.state;
reportInteraction('grafana_preferences_save_button_clicked', { reportInteraction('grafana_preferences_save_button_clicked', {
preferenceType: this.props.preferenceType, preferenceType: this.props.preferenceType,
theme, theme,
@ -162,7 +163,7 @@ export class SharedPreferences extends PureComponent<Props, State> {
timezone, timezone,
weekStart, weekStart,
language, language,
locale, regionalFormat,
queryHistory, queryHistory,
navbar, navbar,
}) })
@ -209,17 +210,18 @@ export class SharedPreferences extends PureComponent<Props, State> {
}); });
}; };
onLocaleChanged = (locale: string) => { onLocaleChanged = (regionalFormat: string) => {
this.setState({ locale }); this.setState({ regionalFormat });
reportInteraction('grafana_preferences_locale_changed', { reportInteraction('grafana_preferences_regional_format_changed', {
toLocale: locale, toRegionalFormat: regionalFormat,
preferenceType: this.props.preferenceType, preferenceType: this.props.preferenceType,
}); });
}; };
render() { render() {
const { theme, timezone, weekStart, homeDashboardUID, language, isLoading, isSubmitting, locale } = this.state; const { theme, timezone, weekStart, homeDashboardUID, language, isLoading, isSubmitting, regionalFormat } =
this.state;
const { disabled } = this.props; const { disabled } = this.props;
const styles = getStyles(); const styles = getStyles();
const currentThemeOption = this.themeOptions.find((x) => x.value === theme) ?? this.themeOptions[0]; const currentThemeOption = this.themeOptions.find((x) => x.value === theme) ?? this.themeOptions[0];
@ -343,9 +345,9 @@ export class SharedPreferences extends PureComponent<Props, State> {
data-testid="User preferences locale drop down" data-testid="User preferences locale drop down"
> >
<Combobox <Combobox
value={this.localeOptions.find((loc) => loc.value === locale)?.value || ''} value={this.regionalFormatOptions.find((loc) => loc.value === regionalFormat)?.value || ''}
onChange={(locale: ComboboxOption | null) => this.onLocaleChanged(locale?.value ?? '')} onChange={(locale: ComboboxOption | null) => this.onLocaleChanged(locale?.value ?? '')}
options={this.localeOptions} options={this.regionalFormatOptions}
placeholder={t('shared-preferences.fields.locale-preference-placeholder', 'Choose region')} placeholder={t('shared-preferences.fields.locale-preference-placeholder', 'Choose region')}
id="locale-preference-select" id="locale-preference-select"
/> />

@ -22,7 +22,7 @@ export const formatDate = deepMemoize(
return formatDate(new Date(value), format); return formatDate(new Date(value), format);
} }
const currentLocale = isLocaleEnabled ? config.locale : getLanguage(); const currentLocale = isLocaleEnabled ? config.regionalFormat : getLanguage();
const dateFormatter = createDateTimeFormatter(currentLocale, format); const dateFormatter = createDateTimeFormatter(currentLocale, format);
return dateFormatter.format(value); return dateFormatter.format(value);
@ -31,7 +31,7 @@ export const formatDate = deepMemoize(
export const formatDuration = deepMemoize( export const formatDuration = deepMemoize(
(duration: Intl.DurationInput, options: Intl.DurationFormatOptions = {}): string => { (duration: Intl.DurationInput, options: Intl.DurationFormatOptions = {}): string => {
const currentLocale = isLocaleEnabled ? config.locale : getLanguage(); const currentLocale = isLocaleEnabled ? config.regionalFormat : getLanguage();
const dateFormatter = createDurationFormatter(currentLocale, options); const dateFormatter = createDurationFormatter(currentLocale, options);
return dateFormatter.format(duration); return dateFormatter.format(duration);

@ -38,7 +38,7 @@ export class User implements Omit<CurrentUserInternal, 'lightTheme'> {
gravatarUrl: string; gravatarUrl: string;
timezone: string; timezone: string;
weekStart: string; weekStart: string;
locale: string; regionalFormat: string;
language: string; language: string;
helpFlags1: number; helpFlags1: number;
hasEditPermissionInFolders: boolean; hasEditPermissionInFolders: boolean;
@ -65,7 +65,7 @@ export class User implements Omit<CurrentUserInternal, 'lightTheme'> {
this.hasEditPermissionInFolders = false; this.hasEditPermissionInFolders = false;
this.email = ''; this.email = '';
this.name = ''; this.name = '';
this.locale = ''; this.regionalFormat = '';
this.language = ''; this.language = '';
this.weekStart = ''; this.weekStart = '';
this.gravatarUrl = ''; this.gravatarUrl = '';

@ -8102,15 +8102,15 @@
"language": { "language": {
"type": "string" "type": "string"
}, },
"locale": {
"type": "string"
},
"navbar": { "navbar": {
"$ref": "#/components/schemas/NavbarPreference" "$ref": "#/components/schemas/NavbarPreference"
}, },
"queryHistory": { "queryHistory": {
"$ref": "#/components/schemas/QueryHistoryPreference" "$ref": "#/components/schemas/QueryHistoryPreference"
}, },
"regionalFormat": {
"type": "string"
},
"theme": { "theme": {
"enum": [ "enum": [
"light", "light",
@ -8730,16 +8730,16 @@
"description": "Selected language (beta)", "description": "Selected language (beta)",
"type": "string" "type": "string"
}, },
"locale": {
"description": "Selected locale (beta)",
"type": "string"
},
"navbar": { "navbar": {
"$ref": "#/components/schemas/NavbarPreference" "$ref": "#/components/schemas/NavbarPreference"
}, },
"queryHistory": { "queryHistory": {
"$ref": "#/components/schemas/QueryHistoryPreference" "$ref": "#/components/schemas/QueryHistoryPreference"
}, },
"regionalFormat": {
"description": "Selected locale (beta)",
"type": "string"
},
"theme": { "theme": {
"description": "light, dark, empty is default", "description": "light, dark, empty is default",
"type": "string" "type": "string"
@ -12345,15 +12345,15 @@
"language": { "language": {
"type": "string" "type": "string"
}, },
"locale": {
"type": "string"
},
"navbar": { "navbar": {
"$ref": "#/components/schemas/NavbarPreference" "$ref": "#/components/schemas/NavbarPreference"
}, },
"queryHistory": { "queryHistory": {
"$ref": "#/components/schemas/QueryHistoryPreference" "$ref": "#/components/schemas/QueryHistoryPreference"
}, },
"regionalFormat": {
"type": "string"
},
"theme": { "theme": {
"enum": [ "enum": [
"light", "light",

Loading…
Cancel
Save