diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 93fb04200a3..55285548803 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -486,7 +486,7 @@ playwright.config.ts @grafana/plugins-platform-frontend /public/app/core/components/TimelineChart/ @grafana/dataviz-squad /public/app/core/components/Form/ @grafana/grafana-frontend-platform /public/app/core/components/OptionsUI/ @grafana/dashboards-squad @grafana/dataviz-squad -/public/app/mock-api-utils.ts @grafana/grafana-frontend-platform +/public/app/dev-utils.ts @grafana/grafana-frontend-platform /public/app/core/history/ @grafana/observability-traces-and-profiling /public/app/features/admin/ @grafana/identity-access-team diff --git a/public/app/core/lifecycle-hooks.ts b/public/app/core/lifecycle-hooks.ts index 1cf2cce1fb8..07cfe490beb 100644 --- a/public/app/core/lifecycle-hooks.ts +++ b/public/app/core/lifecycle-hooks.ts @@ -1,5 +1,5 @@ import { initDevFeatures } from 'app/dev'; -import { notifyIfMockApiEnabled } from 'app/mock-api-utils'; +import { notifyIfMockApiEnabled } from 'app/dev-utils'; /** * Lifecycle tasks that need to be run prior to app initialization, diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index b7a1ea64501..3ff866f92c9 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -2,10 +2,10 @@ import { LegacyGraphHoverClearEvent, SetPanelAttentionEvent, locationUtil } from import { LocationService } from '@grafana/runtime'; import appEvents from 'app/core/app_events'; import { getExploreUrl } from 'app/core/utils/explore'; +import { toggleMockApiAndReload, togglePseudoLocale } from 'app/dev-utils'; import { SaveDashboardDrawer } from 'app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer'; import { ShareModal } from 'app/features/dashboard/components/ShareModal/ShareModal'; import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; -import { toggleMockApiAndReload } from 'app/mock-api-utils'; import { getTimeSrv } from '../../features/dashboard/services/TimeSrv'; import { @@ -58,7 +58,10 @@ export class KeybindingSrv { this.bind('c r', () => toggleTheme(true)); if (process.env.NODE_ENV === 'development') { + // 'change mock' this.bind('c m', () => toggleMockApiAndReload()); + // 'change pseudo locale' + this.bind('c p l', () => togglePseudoLocale()); } } diff --git a/public/app/mock-api-utils.ts b/public/app/dev-utils.ts similarity index 68% rename from public/app/mock-api-utils.ts rename to public/app/dev-utils.ts index b530978d013..478af4f8f64 100644 --- a/public/app/mock-api-utils.ts +++ b/public/app/dev-utils.ts @@ -1,6 +1,8 @@ +import { DEFAULT_LANGUAGE, PSEUDO_LOCALE } from '@grafana/i18n'; import store from 'app/core/store'; import { sendAppNotification } from './core/copy/appNotification'; +import { PreferencesService } from './core/services/PreferencesService'; import { AppNotificationSeverity } from './types'; export const STORAGE_MOCK_API_KEY = 'grafana.dev.mockApi'; @@ -41,3 +43,22 @@ export const notifyIfMockApiEnabled = () => { ); } }; + +export const togglePseudoLocale = async () => { + const prefsService = new PreferencesService('user'); + const prefs = await prefsService.load(); + + const isPseudoEnabled = prefs.language === PSEUDO_LOCALE; + + const action = isPseudoEnabled ? 'Disabling' : 'Enabling'; + sendAppNotification(`${action} pseudo locale`, 'Reloading...', AppNotificationSeverity.Info); + + await prefsService.update({ + ...prefs, + language: isPseudoEnabled ? DEFAULT_LANGUAGE : PSEUDO_LOCALE, + }); + + setTimeout(() => { + window.location.reload(); + }, 200); +}; diff --git a/public/app/dev.ts b/public/app/dev.ts index 19c46dbca8d..7ce4811e39a 100644 --- a/public/app/dev.ts +++ b/public/app/dev.ts @@ -1,6 +1,6 @@ import * as React from 'react'; -import { potentiallySetupMockApi } from './mock-api-utils'; +import { potentiallySetupMockApi } from './dev-utils'; export async function initDevFeatures() { // if why-render is in url enable why did you render react extension diff --git a/public/app/features/commandPalette/actions/staticActions.ts b/public/app/features/commandPalette/actions/staticActions.ts index 9e0ebcec665..7f4f7d0adb3 100644 --- a/public/app/features/commandPalette/actions/staticActions.ts +++ b/public/app/features/commandPalette/actions/staticActions.ts @@ -5,7 +5,7 @@ import { t } from '@grafana/i18n/internal'; import { enrichHelpItem } from 'app/core/components/AppChrome/MegaMenu/utils'; import { performInviteUserClick, shouldRenderInviteUserButton } from 'app/core/components/InviteUserButton/utils'; import { changeTheme } from 'app/core/services/theme'; -import { currentMockApiState, toggleMockApiAndReload } from 'app/mock-api-utils'; +import { currentMockApiState, toggleMockApiAndReload, togglePseudoLocale } from 'app/dev-utils'; import { useSelector } from '../../../types'; import { CommandPaletteAction } from '../types'; @@ -116,6 +116,18 @@ function getGlobalActions(): CommandPaletteAction[] { priority: PREFERENCES_PRIORITY, perform: toggleMockApiAndReload, }); + + actions.push({ + id: 'preferences/dev/pseudo-locale', + section, + name: 'Toggle pseudo locale', + subtitle: 'Toggles between default language and pseudo locale', + keywords: 'pseudo locale', + priority: PREFERENCES_PRIORITY, + perform: () => { + togglePseudoLocale(); + }, + }); // eslint-enable @grafana/no-untranslated-strings }