i18n: Add locale to backend (#102233)
This commit is contained in:
@@ -9,11 +9,12 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/kinds/preferences"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
pref "github.com/grafana/grafana/pkg/services/preference"
|
||||
)
|
||||
|
||||
func UpdatePreferencesFor(ctx context.Context,
|
||||
dashboardService dashboards.DashboardService, preferenceService pref.Service,
|
||||
dashboardService dashboards.DashboardService, preferenceService pref.Service, features featuremgmt.FeatureToggles,
|
||||
orgID, userID, teamId int64, dtoCmd *dtos.UpdatePrefsCmd) response.Response {
|
||||
if dtoCmd.Theme != "" && !pref.IsValidThemeID(dtoCmd.Theme) {
|
||||
return response.Error(http.StatusBadRequest, "Invalid theme", nil)
|
||||
@@ -49,6 +50,10 @@ func UpdatePreferencesFor(ctx context.Context,
|
||||
Navbar: dtoCmd.Navbar,
|
||||
}
|
||||
|
||||
if features.IsEnabled(ctx, featuremgmt.FlagLocaleFormatPreference) {
|
||||
saveCmd.Locale = dtoCmd.Locale
|
||||
}
|
||||
|
||||
if err := preferenceService.Save(ctx, &saveCmd); err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "Failed to save preferences", err)
|
||||
}
|
||||
@@ -58,7 +63,7 @@ func UpdatePreferencesFor(ctx context.Context,
|
||||
|
||||
func GetPreferencesFor(ctx context.Context,
|
||||
dashboardService dashboards.DashboardService, preferenceService pref.Service,
|
||||
orgID, userID, teamID int64) response.Response {
|
||||
features featuremgmt.FeatureToggles, orgID, userID, teamID int64) response.Response {
|
||||
prefsQuery := pref.GetPreferenceQuery{UserID: userID, OrgID: orgID, TeamID: teamID}
|
||||
|
||||
preference, err := preferenceService.Get(ctx, &prefsQuery)
|
||||
@@ -67,7 +72,6 @@ func GetPreferencesFor(ctx context.Context,
|
||||
}
|
||||
|
||||
var dashboardUID string
|
||||
|
||||
// when homedashboardID is 0, that means it is the default home dashboard, no UID would be returned in the response
|
||||
if preference.HomeDashboardID != 0 {
|
||||
query := dashboards.GetDashboardQuery{ID: preference.HomeDashboardID, OrgID: orgID}
|
||||
@@ -97,6 +101,12 @@ func GetPreferencesFor(ctx context.Context,
|
||||
dto.Language = &preference.JSONData.Language
|
||||
}
|
||||
|
||||
if features.IsEnabled(ctx, featuremgmt.FlagLocaleFormatPreference) {
|
||||
if preference.JSONData.Locale != "" {
|
||||
dto.Locale = &preference.JSONData.Locale
|
||||
}
|
||||
}
|
||||
|
||||
if preference.JSONData.Navbar.BookmarkUrls != nil {
|
||||
dto.Navbar = &preferences.NavbarPreference{
|
||||
BookmarkUrls: []string{},
|
||||
|
||||
Reference in New Issue
Block a user