Skip to content

Commit 0013672

Browse files
committed
feat(spec): an action's param dialog can name its own submit verb — submitText
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2fi9zfJhUTubyJYb6V
1 parent 549203d commit 0013672

6 files changed

Lines changed: 349 additions & 9 deletions

File tree

‎packages/lint/src/validate-translation-references.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3851,6 +3851,23 @@ describe('validateTranslationReferences — keyed children of an action entry (#
38513851
});
38523852
});
38533853

3854+
describe('submitText — the param dialog\'s button (#27944)', () => {
3855+
it('errors on a `submitText` under an action that declares no params, at both addresses', () => {
3856+
const findings = validateTranslationReferences(
3857+
actionStack({ ...onEnv({ plain_env: { submitText: '发送' } }), globalActions: { mint_token: { submitText: '生成' } } }),
3858+
);
3859+
expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([
3860+
[TRANSLATION_TARGET_UNKNOWN, 'error', `${ENV}.plain_env.submitText`],
3861+
[TRANSLATION_TARGET_UNKNOWN, 'error', `${GLOBAL}.mint_token.submitText`],
3862+
]);
3863+
expect(findings[0].message).toMatch(/^Translations carry a param dialog `submitText`, but action "plain_env" declares no `params`/);
3864+
});
3865+
3866+
it('accepts it under an action that collects params (the control)', () => {
3867+
expect(validateTranslationReferences(actionStack(onEnv({ archive_env: { submitText: '归档' } })))).toEqual([]);
3868+
});
3869+
});
3870+
38543871
describe('params.<name>.options.<value>', () => {
38553872
it('warns on an option key a declared param does not declare, as the field `options` leg does', () => {
38563873
const findings = validateTranslationReferences(
@@ -3927,7 +3944,7 @@ describe('validateTranslationReferences — keyed children of an action entry (#
39273944
};
39283945

39293946
type Address = 'bound' | 'global';
3930-
type Host = 'outcome' | 'dialog' | 'noDialog';
3947+
type Host = 'outcome' | 'dialog' | 'noDialog' | 'noParams';
39313948
/**
39323949
* Which declared action a ghost is written under, per address. `noDialog`
39333950
* names an action that declares no `resultDialog`: the dialog's leaves
@@ -3937,6 +3954,10 @@ describe('validateTranslationReferences — keyed children of an action entry (#
39373954
outcome: { bound: 'archive_env', global: 'check_updates' },
39383955
dialog: { bound: 'rotate_secret', global: 'mint_token' },
39393956
noDialog: { bound: 'plain_env', global: 'check_updates' },
3957+
// [#27944] An action with no `params` opens no param dialog, so its
3958+
// `submitText` has no button to land on (`coverageStack` gives
3959+
// `check_updates` params, so the global host is `mint_token`).
3960+
noParams: { bound: 'plain_env', global: 'mint_token' },
39403961
};
39413962
type Coverage =
39423963
| { kind: 'reference-checked'; host: Host; ghost: Record<string, unknown>; suffix: string; rule: string }
@@ -3948,6 +3969,13 @@ describe('validateTranslationReferences — keyed children of an action entry (#
39483969
confirmText: { kind: 'leaf-copy', why: 'prose' },
39493970
successMessage: { kind: 'leaf-copy', why: 'prose' },
39503971
disabledReason: { kind: 'leaf-copy', why: 'prose' },
3972+
submitText: {
3973+
kind: 'reference-checked',
3974+
host: 'noParams',
3975+
ghost: { submitText: 'x' },
3976+
suffix: '.submitText',
3977+
rule: TRANSLATION_TARGET_UNKNOWN,
3978+
},
39513979
outcomeMessages: {
39523980
kind: 'reference-checked',
39533981
host: 'outcome',
@@ -4050,6 +4078,7 @@ describe('validateTranslationReferences — keyed children of an action entry (#
40504078
description: 'x',
40514079
confirmText: 'x',
40524080
successMessage: 'x',
4081+
submitText: 'x',
40534082
outcomeMessages: address === 'bound' ? { archived: 'x' } : { up_to_date: 'x' },
40544083
params: { mode: { label: 'x', helpText: 'x', placeholder: 'x', options: { soft: 'x' } } },
40554084
},

‎packages/lint/src/validate-translation-references.ts‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,14 +2573,18 @@ interface ActionEntryContext {
25732573
* | `outcomeMessages.<outcome>` | the action's `outcomeMessages` keys | `resolveActionOutcomeMessages` |
25742574
* | `resultDialog.fields.<path>` | `resultDialog.fields[].path` | `resolveActionResultDialog` |
25752575
* | `resultDialog.title` / `.description` / `.acknowledge` | the action's `resultDialog`, present at all | `resolveActionResultDialog` |
2576+
* | `submitText` | a non-empty `params` (the param dialog) | `translateAction` |
25762577
*
25772578
* A dialog leaf under a DECLARED dialog is read whether or not the dialog
25782579
* authors that leaf itself — the resolver overlays a translated `title` onto a
25792580
* dialog that declares none — so declaring the dialog is the whole condition.
25802581
*
2581-
* The leaf keys beside them (`label`, `description`, `confirmText`,
2582-
* `successMessage`, `disabledReason`) are prose on a node that resolved, read
2583-
* whenever the action is, as on the object branch.
2582+
* `submitText` is the param dialog's button, the one leaf with a host of its
2583+
* own: the dialog opens only for a non-empty `params`, and `translateAction`
2584+
* overlays the key only then (#27944). The leaf keys beside them (`label`,
2585+
* `description`, `confirmText`, `successMessage`, `disabledReason`) are prose
2586+
* on a node that resolved, read whenever the action is, as on the object
2587+
* branch.
25842588
*
25852589
* ⛔ One vocabulary: a key naming a target the action does not declare is
25862590
* `translation-target-unknown` at `params`' severity; an OPTION key keyed off
@@ -2593,6 +2597,32 @@ function checkActionEntry(findings: TranslationRefFinding[], ctx: ActionEntryCon
25932597
checkActionOutcomeMessages(findings, ctx);
25942598
checkActionResultDialogLeaves(findings, ctx);
25952599
checkActionResultDialogFields(findings, ctx);
2600+
checkActionSubmitText(findings, ctx);
2601+
}
2602+
2603+
/**
2604+
* [#27944] `submitText` — the label of the param dialog's submit button. The
2605+
* dialog opens only for an action with a non-empty `params`, and
2606+
* `translateAction` overlays the key only for such an action, so under any
2607+
* other action the translation is read by nothing: the result-dialog leaves'
2608+
* rule (declaring the dialog is the whole condition), with `params` as the
2609+
* declaration.
2610+
*/
2611+
function checkActionSubmitText(findings: TranslationRefFinding[], ctx: ActionEntryContext): void {
2612+
if (!isRec(ctx.rawAction) || ctx.rawAction.submitText === undefined) return;
2613+
if (Array.isArray(ctx.action.params) && ctx.action.params.length > 0) return;
2614+
findings.push({
2615+
severity: TRANSLATION_TARGET_UNKNOWN_SEVERITY,
2616+
rule: TRANSLATION_TARGET_UNKNOWN,
2617+
where: `${ctx.where} · submit button`,
2618+
path: `${ctx.path}.submitText`,
2619+
message:
2620+
`Translations carry a param dialog \`submitText\`, but ${ctx.subject} declares no ` +
2621+
`\`params\`, so it opens no param dialog and nothing reads this label.`,
2622+
hint:
2623+
`Move the \`submitText\` translation under the action that collects the params, declare ` +
2624+
`\`params\` on this action first if it should open a dialog, or drop it.`,
2625+
});
25962626
}
25972627

25982628
/** Action-parameter translations are keyed by the param's `name`. */

‎packages/spec/src/system/i18n-resolver.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* objects.<object>._actions.<action_name>.confirmText
1717
* objects.<object>._actions.<action_name>.successMessage
1818
* objects.<object>._actions.<action_name>.disabledReason
19+
* objects.<object>._actions.<action_name>.submitText
1920
* objects.<object>._actions.<action_name>.outcomeMessages.<outcome>
2021
* objects.<object>._actions.<action_name>.params.<param_name>.label
2122
* objects.<object>._actions.<action_name>.params.<param_name>.helpText
@@ -47,8 +48,8 @@
4748
* object-less action (no `objectName`) reads only:
4849
*
4950
* globalActions.<action_name>.label / .description / .confirmText /
50-
* .successMessage / .disabledReason / .outcomeMessages.<outcome> /
51-
* .params.<param_name>.* / .resultDialog.*
51+
* .successMessage / .disabledReason / .submitText /
52+
* .outcomeMessages.<outcome> / .params.<param_name>.* / .resultDialog.*
5253
*
5354
* That is the declaration `TranslationDataSchema.globalActions` makes: global
5455
* translations are for object-less actions. A `globalActions` entry that names
@@ -228,6 +229,11 @@ export interface ActionLike {
228229
* action shows. Narrowed to `string` for the same reason `description` is.
229230
*/
230231
disabledReason?: string;
232+
/**
233+
* `ActionSchema.submitText` (#27944) — the param dialog's submit button
234+
* label. Narrowed to `string` for the same reason `description` is.
235+
*/
236+
submitText?: string;
231237
/**
232238
* `ActionSchema.outcomeMessages` — success copy per handler `outcome`,
233239
* narrowed to `string` values for the same reason `successMessage` is.
@@ -657,7 +663,7 @@ function actionTranslationNode(
657663
function lookupActionField(
658664
bundle: TranslationBundle | undefined,
659665
action: ActionLike,
660-
field: 'label' | 'description' | 'confirmText' | 'successMessage' | 'disabledReason',
666+
field: 'label' | 'description' | 'confirmText' | 'successMessage' | 'disabledReason' | 'submitText',
661667
opts?: ResolveOptions,
662668
): string | undefined {
663669
if (!bundle) return undefined;
@@ -1437,8 +1443,9 @@ export function translateView<T extends ViewLike>(
14371443
/**
14381444
* Apply the active locale to an action metadata document by overwriting
14391445
* `label`, `description`, `confirmText`, `successMessage`, `disabledReason`,
1440-
* each declared `outcomeMessages` entry, the `params[]` copy and the
1441-
* `resultDialog` copy with translated values when available. The
1446+
* `submitText` (for an action that declares `params`), each declared
1447+
* `outcomeMessages` entry, the `params[]` copy and the `resultDialog` copy
1448+
* with translated values when available. The
14421449
* original document is not mutated; a shallow copy is returned.
14431450
*
14441451
* ## Why `description` and `params` are overlaid HERE
@@ -1470,6 +1477,14 @@ export function translateAction<T extends ActionLike>(
14701477
// [#26619] Display-only copy, overlaid exactly like `description`: the
14711478
// bundle's sentence when there is one, else the authored value as written.
14721479
const disabledReason = lookupActionField(bundle, action, 'disabledReason', opts) ?? action.disabledReason;
1480+
// [#27944] The param dialog's button, overlaid like `description` — but only
1481+
// for an action that opens that dialog, a non-empty `params`, the way
1482+
// `resolveActionResultDialog` reads nothing for an action with no dialog.
1483+
// `ActionSchema` refuses the key anywhere else, so the guard only decides
1484+
// whether a bundle can give a button to a dialog that never opens: never.
1485+
const submitText = Array.isArray(action.params) && action.params.length > 0
1486+
? lookupActionField(bundle, action, 'submitText', opts) ?? action.submitText
1487+
: action.submitText;
14731488
const outcomeMessages = resolveActionOutcomeMessages(bundle, action, opts);
14741489
const resultDialog = resolveActionResultDialog(bundle, action, opts);
14751490
const params = translateActionParams(action, bundle, opts);
@@ -1480,6 +1495,7 @@ export function translateAction<T extends ActionLike>(
14801495
...(confirmText !== undefined ? { confirmText } : {}),
14811496
...(successMessage !== undefined ? { successMessage } : {}),
14821497
...(disabledReason !== undefined ? { disabledReason } : {}),
1498+
...(submitText !== undefined ? { submitText } : {}),
14831499
...(outcomeMessages !== action.outcomeMessages ? { outcomeMessages } : {}),
14841500
...(resultDialog !== undefined ? { resultDialog } : {}),
14851501
...(params !== action.params ? { params } : {}),

‎packages/spec/src/system/translation.zod.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ const actionTranslationSchema = (surface: string) => strictObject({
199199
success: 'successMessage', successText: 'successMessage', toast: 'successMessage',
200200
disabledMessage: 'disabledReason', disabledTooltip: 'disabledReason',
201201
disabledHint: 'disabledReason', disabledText: 'disabledReason',
202+
submitLabel: 'submitText', confirmLabel: 'submitText',
202203
parameters: 'params', args: 'params', inputs: 'params',
203204
result: 'resultDialog', dialog: 'resultDialog',
204205
},
@@ -216,6 +217,10 @@ const actionTranslationSchema = (surface: string) => strictObject({
216217
// `ActionSchema.disabledReason` (#26619) — the display-only reason a greyed
217218
// action shows; overlaid by `translateAction` like the copy keys above.
218219
disabledReason: z.string().optional().describe('Translated reason a greyed action shows (hover title and accessible description) while its `disabled` predicate is TRUE'),
220+
// `ActionSchema.submitText` (#27944) — the param dialog's submit button
221+
// label; overlaid by `translateAction` like `description`, the same
222+
// dialog's line under its title, for an action that declares `params`.
223+
submitText: z.string().optional().describe('Translated label of the submit button in the action\'s param dialog (the action must declare `params`; no renderer shows it yet)'),
219224
// `ActionSchema.outcomeMessages` (#21095) — one translated message per
220225
// declared outcome, keyed by the same snake_case outcome name, so a bundle
221226
// key that could never match a handler's `outcome` is refused here rather
@@ -453,6 +458,7 @@ export const ObjectTranslationDataSchema = lazySchema(() => strictObject({
453458
* objects.<object>._actions.<action_name>.confirmText
454459
* objects.<object>._actions.<action_name>.successMessage
455460
* objects.<object>._actions.<action_name>.disabledReason
461+
* objects.<object>._actions.<action_name>.submitText
456462
* objects.<object>._actions.<action_name>.outcomeMessages.<outcome>
457463
* objects.<object>._actions.<action_name>.params.<param_name>.label
458464
* objects.<object>._actions.<action_name>.params.<param_name>.helpText
@@ -981,6 +987,7 @@ const appTranslationDataShape = () => ({
981987
* globalActions.<action_name>.confirmText
982988
* globalActions.<action_name>.successMessage
983989
* globalActions.<action_name>.disabledReason
990+
* globalActions.<action_name>.submitText
984991
* globalActions.<action_name>.outcomeMessages.<outcome>
985992
* globalActions.<action_name>.params.<param_name>.label
986993
* globalActions.<action_name>.params.<param_name>.helpText

0 commit comments

Comments
 (0)