App menu: a Languages… row (after Store) opens the panel's Languages section; it shows only when the app says its panel has one (features.strings); English word wb.menu.strings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-10-01 04:52:27 +07:00
parent fe7f60cd8d
commit 10d86ef55c
6 changed files with 20 additions and 12 deletions

View file

@ -304,6 +304,7 @@ export function AppMenu({ trigger = true }: { trigger?: boolean } = {}) {
case 'zoom': return { kind: 'zoom', id: 'zoom' }; case 'zoom': return { kind: 'zoom', id: 'zoom' };
case 'plugins': return item(id, section(t('wb.panel.section.plugins')), 'plug', { run: () => shell.openPanelSection('plugins') }); case 'plugins': return item(id, section(t('wb.panel.section.plugins')), 'plug', { run: () => shell.openPanelSection('plugins') });
case 'store': return item(id, section(t('wb.panel.section.store')), 'bag', { run: () => shell.openPanelSection('store') }); case 'store': return item(id, section(t('wb.panel.section.store')), 'bag', { run: () => shell.openPanelSection('store') });
case 'strings': return item(id, section(menuText('strings')), 'globe', { run: () => shell.openPanelSection('languages') });
case 'workspaces': return item(id, t('wb.ws.title'), 'layout', { submenu: true, hint: workspaces.store.items.find(entry => entry.id === workspaces.active)?.name }); case 'workspaces': return item(id, t('wb.ws.title'), 'layout', { submenu: true, hint: workspaces.store.items.find(entry => entry.id === workspaces.active)?.name });
case 'find': return item(id, menuText('find'), 'search', { shortcut: 'Ctrl+F', disabled: !active || !isWeb(active), run: () => shell.shortcut('find') }); case 'find': return item(id, menuText('find'), 'search', { shortcut: 'Ctrl+F', disabled: !active || !isWeb(active), run: () => shell.shortcut('find') });
case 'shortcuts': return item(id, menuText('shortcuts'), 'keyboard', { run: () => (menu.shortcuts ? menu.shortcuts() : shell.shortcut('command-palette')) }); case 'shortcuts': return item(id, menuText('shortcuts'), 'keyboard', { run: () => (menu.shortcuts ? menu.shortcuts() : shell.shortcut('command-palette')) });
@ -433,7 +434,7 @@ export function AppMenu({ trigger = true }: { trigger?: boolean } = {}) {
const groups = menu.groups ?? DEFAULT_MENU; const groups = menu.groups ?? DEFAULT_MENU;
const env: MenuEnv = { const env: MenuEnv = {
decks: !!config.deck, languages: !!menu.languages, themes: !!config.themes, modes: modeList.length > 0, decks: !!config.deck, languages: !!menu.languages, themes: !!config.themes, modes: modeList.length > 0,
zoom: hasFeature('zoom'), find: hasFeature('find'), safeMode: hasFeature('safeMode'), store: hasFeature('store'), workspaces: hasFeature('workspaces'), developer: hasFeature('developer'), updates: hasFeature('updates'), zoom: hasFeature('zoom'), find: hasFeature('find'), safeMode: hasFeature('safeMode'), store: hasFeature('store'), strings: config.features?.strings === true, workspaces: hasFeature('workspaces'), developer: hasFeature('developer'), updates: hasFeature('updates'),
}; };
const rootRows = () => joinGroups(planMenu(groups, env).map(group => group.flatMap(entry => (typeof entry === 'string' ? [builtin(entry)] : specRows([entry]))))); const rootRows = () => joinGroups(planMenu(groups, env).map(group => group.flatMap(entry => (typeof entry === 'string' ? [builtin(entry)] : specRows([entry])))));
const labelOf = (id: string, rows: MenuRow[]) => rows.find((row): row is MenuItemRow => row.kind === 'item' && row.id === id)?.label ?? ''; const labelOf = (id: string, rows: MenuRow[]) => rows.find((row): row is MenuItemRow => row.kind === 'item' && row.id === id)?.label ?? '';

View file

@ -49,5 +49,6 @@
"wb.menu.reportTitle": "Report a problem", "wb.menu.reportTitle": "Report a problem",
"wb.menu.reportLede": "This is everything the report contains: versions and what is switched on. No account, no address, nothing from the pages you have open. Copy it, then paste it into your report.", "wb.menu.reportLede": "This is everything the report contains: versions and what is switched on. No account, no address, nothing from the pages you have open. Copy it, then paste it into your report.",
"wb.menu.reportOpen": "Open the issue page", "wb.menu.reportOpen": "Open the issue page",
"wb.menu.reportNoPage": "This app has no public issue page yet. Copy the text and send it to the developer." "wb.menu.reportNoPage": "This app has no public issue page yet. Copy the text and send it to the developer.",
"wb.menu.strings": "Languages"
} }

View file

@ -34,7 +34,7 @@ export const MENU_BUILTINS = [
'new-tab', 'split-right', 'split-down', 'new-column', 'new-tab', 'split-right', 'split-down', 'new-column',
'language', 'theme', 'mode', 'language', 'theme', 'mode',
'zoom', 'zoom',
'plugins', 'store', 'workspaces', 'plugins', 'store', 'strings', 'workspaces',
'find', 'shortcuts', 'palette', 'find', 'shortcuts', 'palette',
'developer', 'updates', 'safe-mode', 'report', 'about', 'settings', 'developer', 'updates', 'safe-mode', 'report', 'about', 'settings',
] as const; ] as const;
@ -131,7 +131,7 @@ export const DEFAULT_MENU: MenuGroups = [
['new-tab', 'split-right', 'split-down', 'new-column'], ['new-tab', 'split-right', 'split-down', 'new-column'],
['language', 'theme', 'mode'], ['language', 'theme', 'mode'],
['zoom'], ['zoom'],
['plugins', 'store', 'workspaces'], ['plugins', 'store', 'strings', 'workspaces'],
['find', 'shortcuts', 'palette'], ['find', 'shortcuts', 'palette'],
['developer', 'updates', 'safe-mode', 'report', 'about', 'settings'], ['developer', 'updates', 'safe-mode', 'report', 'about', 'settings'],
]; ];
@ -172,6 +172,8 @@ export type MenuEnv = {
/** `features.safeMode`: safe mode for one run (`safe_mode_get/set`, the host's own). */ /** `features.safeMode`: safe mode for one run (`safe_mode_get/set`, the host's own). */
safeMode: boolean; safeMode: boolean;
store: boolean; store: boolean;
/** `features.strings`: the panel has the Languages section (string packs). */
strings: boolean;
workspaces: boolean; workspaces: boolean;
developer: boolean; developer: boolean;
updates: boolean; updates: boolean;
@ -188,6 +190,7 @@ export function builtinAvailable(id: BuiltinMenuItem, env: MenuEnv): boolean {
case 'find': return env.find; case 'find': return env.find;
case 'safe-mode': return env.safeMode; case 'safe-mode': return env.safeMode;
case 'store': return env.store; case 'store': return env.store;
case 'strings': return env.strings;
case 'workspaces': return env.workspaces; case 'workspaces': return env.workspaces;
case 'developer': return env.developer; case 'developer': return env.developer;
case 'updates': return env.updates; case 'updates': return env.updates;

View file

@ -151,7 +151,9 @@ export type ShellSite = {
* app menu links to: the Store (`PanelSite.store`) and the updater (`PanelSite.updates`). Each is * app menu links to: the Store (`PanelSite.store`) and the updater (`PanelSite.updates`). Each is
* on unless set to false; off, the frame shows nothing of it. * on unless set to false; off, the frame shows nothing of it.
*/ */
features?: { workspaces?: boolean; sync?: boolean; developer?: boolean; pluginCommands?: boolean; zoom?: boolean; find?: boolean; safeMode?: boolean; store?: boolean; updates?: boolean }; features?: { workspaces?: boolean; sync?: boolean; developer?: boolean; pluginCommands?: boolean; zoom?: boolean; find?: boolean; safeMode?: boolean; store?: boolean; updates?: boolean;
/** The panel has the Languages section for string packs (`createStringPacksSection`, id `languages`): only when true. */
strings?: boolean };
/** /**
* The app menu (the titlebar's "Settings and more", Alt+F / F10): its rows in order (built-in * The app menu (the titlebar's "Settings and more", Alt+F / F10): its rows in order (built-in
* ones by name, the app's own as objects) and what the Language and Mode submenus need. Omit for * ones by name, the app's own as objects) and what the Language and Mode submenus need. Omit for

View file

@ -15,8 +15,8 @@ import {
import { buildItems } from '../src/frame/paletteModel.ts'; import { buildItems } from '../src/frame/paletteModel.ts';
const here = dirname(fileURLToPath(import.meta.url)); const here = dirname(fileURLToPath(import.meta.url));
const ALL: MenuEnv = { decks: true, languages: true, themes: true, modes: true, zoom: true, find: true, safeMode: true, store: true, workspaces: true, developer: true, updates: true }; const ALL: MenuEnv = { decks: true, languages: true, themes: true, modes: true, zoom: true, find: true, safeMode: true, store: true, strings: true, workspaces: true, developer: true, updates: true };
const NONE: MenuEnv = { decks: false, languages: false, themes: false, modes: false, zoom: false, find: false, safeMode: false, store: false, workspaces: false, developer: false, updates: false }; const NONE: MenuEnv = { decks: false, languages: false, themes: false, modes: false, zoom: false, find: false, safeMode: false, store: false, strings: false, workspaces: false, developer: false, updates: false };
const ids = (groups: ReturnType<typeof planMenu>) => groups.map(group => group.map(entry => (typeof entry === 'string' ? entry : entry.id))); const ids = (groups: ReturnType<typeof planMenu>) => groups.map(group => group.map(entry => (typeof entry === 'string' ? entry : entry.id)));
const items = (rows: MenuRow[]) => rows.filter((row): row is MenuItemRow => row.kind === 'item'); const items = (rows: MenuRow[]) => rows.filter((row): row is MenuItemRow => row.kind === 'item');
@ -36,7 +36,7 @@ test('a row the app cannot serve is left out, and a group left empty takes its r
// Each gate is its own. // Each gate is its own.
const gates: Array<[keyof MenuEnv, string]> = [ const gates: Array<[keyof MenuEnv, string]> = [
['decks', 'new-column'], ['languages', 'language'], ['themes', 'theme'], ['modes', 'mode'], ['zoom', 'zoom'], ['find', 'find'], ['safeMode', 'safe-mode'], ['decks', 'new-column'], ['languages', 'language'], ['themes', 'theme'], ['modes', 'mode'], ['zoom', 'zoom'], ['find', 'find'], ['safeMode', 'safe-mode'],
['store', 'store'], ['workspaces', 'workspaces'], ['developer', 'developer'], ['updates', 'updates'], ['store', 'store'], ['strings', 'strings'], ['workspaces', 'workspaces'], ['developer', 'developer'], ['updates', 'updates'],
]; ];
for (const [feature, row] of gates) { for (const [feature, row] of gates) {
const only = ids(planMenu(DEFAULT_MENU, { ...NONE, [feature]: true })).flat(); const only = ids(planMenu(DEFAULT_MENU, { ...NONE, [feature]: true })).flat();
@ -55,15 +55,15 @@ test('an app orders, removes and adds rows; its own rows follow their `when`', (
let drafts = true; let drafts = true;
const own: MenuItemSpec = { id: 'drafts', label: () => 'Drafts…', icon: 'draft', when: () => drafts, run() {} }; const own: MenuItemSpec = { id: 'drafts', label: () => 'Drafts…', icon: 'draft', when: () => drafts, run() {} };
const groups = menuWith(DEFAULT_MENU, 'workspaces', [own]); const groups = menuWith(DEFAULT_MENU, 'workspaces', [own]);
assert.deepEqual(ids(planMenu(groups, ALL))[3], ['plugins', 'store', 'workspaces', 'drafts']); assert.deepEqual(ids(planMenu(groups, ALL))[3], ['plugins', 'store', 'strings', 'workspaces', 'drafts']);
assert.deepEqual(ids(planMenu(menuWith(DEFAULT_MENU, 'plugins', [own], 'before'), ALL))[3], ['drafts', 'plugins', 'store', 'workspaces']); assert.deepEqual(ids(planMenu(menuWith(DEFAULT_MENU, 'plugins', [own], 'before'), ALL))[3], ['drafts', 'plugins', 'store', 'strings', 'workspaces']);
// Without its anchor the app's rows form a last group. // Without its anchor the app's rows form a last group.
assert.deepEqual(ids(planMenu(menuWith(DEFAULT_MENU, 'nothing', [own]), ALL)).at(-1), ['drafts']); assert.deepEqual(ids(planMenu(menuWith(DEFAULT_MENU, 'nothing', [own]), ALL)).at(-1), ['drafts']);
drafts = false; drafts = false;
assert.equal(ids(planMenu(groups, ALL)).flat().includes('drafts'), false); assert.equal(ids(planMenu(groups, ALL)).flat().includes('drafts'), false);
drafts = true; drafts = true;
assert.deepEqual(ids(planMenu(menuWithout(groups, 'store', 'zoom', 'drafts'), ALL)), [ assert.deepEqual(ids(planMenu(menuWithout(groups, 'store', 'zoom', 'drafts'), ALL)), [
['new-tab', 'split-right', 'split-down', 'new-column'], ['language', 'theme', 'mode'], ['plugins', 'workspaces'], ['find', 'shortcuts', 'palette'], ['developer', 'updates', 'safe-mode', 'report', 'about', 'settings'], ['new-tab', 'split-right', 'split-down', 'new-column'], ['language', 'theme', 'mode'], ['plugins', 'strings', 'workspaces'], ['find', 'shortcuts', 'palette'], ['developer', 'updates', 'safe-mode', 'report', 'about', 'settings'],
]); ]);
// Explicit order; a row listed twice shows once; an unknown name and an own row named like a built-in are ignored. // Explicit order; a row listed twice shows once; an unknown name and an own row named like a built-in are ignored.
const custom: MenuGroups = [['settings', 'new-tab', 'settings', 'nope' as never], [{ id: 'zoom', label: () => 'Fake zoom' }, own]]; const custom: MenuGroups = [['settings', 'new-tab', 'settings', 'nope' as never], [{ id: 'zoom', label: () => 'Fake zoom' }, own]];

View file

@ -1273,6 +1273,7 @@
"wb.install.err.stringsLarge": "String packs are limited to 2 MB.", "wb.install.err.stringsLarge": "String packs are limited to 2 MB.",
"wb.install.err.stringsNotInstalled": "The string pack was not installed", "wb.install.err.stringsNotInstalled": "The string pack was not installed",
"wb.strings.translate": "Translate mode", "wb.strings.translate": "Translate mode",
"wb.strings.translateHint": "Every {site} tab shows a bar: click a word to change it. Your edits apply in that tab after a reload, and “Copy pack file” gives you a pack to share. While it is on, words carry invisible markers." "wb.strings.translateHint": "Every {site} tab shows a bar: click a word to change it. Your edits apply in that tab after a reload, and “Copy pack file” gives you a pack to share. While it is on, words carry invisible markers.",
"wb.menu.strings": "Languages"
} }
} }