i18n: Add shortcut/command palette item to toggle pseudo locale (#105826)

This commit is contained in:
Tom Ratcliffe
2025-05-22 19:12:17 +03:00
committed by GitHub
parent e389407907
commit 71a60e2734
6 changed files with 41 additions and 5 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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,
+4 -1
View File
@@ -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());
}
}
@@ -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);
};
+1 -1
View File
@@ -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
@@ -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
}