Skip to content

Commit b37222d

Browse files
committed
feat(cli): i18n extract scaffolds an action's submitText beside a non-empty params
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzPbVCsG2npDkDqikd
1 parent 6a959c5 commit b37222d

2 files changed

Lines changed: 174 additions & 1 deletion

File tree

‎packages/cli/src/utils/i18n-extract.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@
8787
* objects.<name>._actions.<action>.confirmText
8888
* objects.<name>._actions.<action>.successMessage
8989
* objects.<name>._actions.<action>.disabledReason
90+
* objects.<name>._actions.<action>.submitText (only beside a non-empty `params`)
9091
* objects.<name>._actions.<action>.outcomeMessages.<outcome>
9192
* objects.<name>._actions.<action>.params.<param>.label / .helpText / .placeholder
9293
* objects.<name>._actions.<action>.params.<param>.options.<value>
9394
* objects.<name>._actions.<action>.resultDialog.title / .description / .acknowledge
9495
* objects.<name>._actions.<action>.resultDialog.fields.<path>
9596
* globalActions.<action>.label / .description / .confirmText / .successMessage
96-
* / .disabledReason
97+
* / .disabledReason / .submitText (beside a non-empty `params`)
9798
* globalActions.<action>.outcomeMessages.<outcome>
9899
* globalActions.<action>.params.<param>.* / .resultDialog.* (same shape as object actions)
99100
* apps.<app>.label / .description
@@ -748,6 +749,25 @@ function pushOptional(
748749
else out.push({ path, ...evidence, source, ...extra });
749750
}
750751

752+
/**
753+
* Emit `submitText`, the param dialog's submit button label, under an action's
754+
* translation root — OPTIONAL-not-derived like `description` (an action that
755+
* names no verb shows the console's own "Confirm"), and only for an action with
756+
* a non-empty `params`: that is the only action `translateAction` overlays the
757+
* key onto, because no other action opens the dialog the button sits in. A
758+
* paramless action gets no slot, so a translation filed there stays dangling.
759+
*/
760+
function pushActionSubmitText(
761+
out: ExpectedEntry[],
762+
actionRoot: string[],
763+
action: any,
764+
source: ExpectedEntry['source'],
765+
objectName: string | undefined,
766+
): void {
767+
if (!Array.isArray(action?.params) || action.params.length === 0) return;
768+
pushOptional(out, [...actionRoot, 'submitText'], action.submitText, source, { objectName });
769+
}
770+
751771
/**
752772
* Emit `params.<param>.{label,helpText,placeholder}` and
753773
* `params.<param>.options.<value>` entries under an action's translation root.
@@ -1506,6 +1526,7 @@ export function collectExpectedEntries(
15061526
pushOptional(out, [...aroot, 'confirmText'], actionCopy(action.confirmText), 'action', { objectName });
15071527
pushOptional(out, [...aroot, 'successMessage'], actionCopy(action.successMessage), 'action', { objectName });
15081528
pushOptional(out, [...aroot, 'disabledReason'], action.disabledReason, 'action', { objectName });
1529+
pushActionSubmitText(out, aroot, action, 'action', objectName);
15091530
pushActionOutcomeMessages(out, aroot, action, 'action', objectName);
15101531
pushActionParams(out, ['objects', objectName, '_actions', aname], action, 'action', objectName);
15111532
pushActionResultDialog(out, ['objects', objectName, '_actions', aname], action, 'action', objectName);
@@ -1603,6 +1624,7 @@ export function collectExpectedEntries(
16031624
// reason shows the console's own default sentence, so there is no gap to
16041625
// seed for it.
16051626
pushOptional(out, [...root, 'disabledReason'], action.disabledReason, kind, { objectName });
1627+
pushActionSubmitText(out, root, action, kind, objectName);
16061628
pushActionOutcomeMessages(out, root, action, kind, objectName);
16071629
pushActionParams(out, root, action, kind, objectName);
16081630
pushActionResultDialog(out, root, action, kind, objectName);
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license.
2+
//
3+
// The extractor half of `action.submitText`, the verb on the submit button of
4+
// the dialog an action opens to collect its `params`.
5+
//
6+
// `translateAction` overlays `objects.OBJECT._actions.ACTION.submitText`
7+
// (`globalActions.ACTION.submitText` for an object-less action) only onto an
8+
// action with a non-empty `params`, because no other action opens that dialog.
9+
// `os i18n extract` scaffolds the slot on exactly that population: beside a
10+
// non-empty `params` it is an optional slot like `description`, and anywhere
11+
// else there is no slot at all. The last test walks ONE fixture action through
12+
// all three surfaces — `ActionSchema` accepts it, the extractor emits its key,
13+
// the translation schema accepts the bundle written at that key — because each
14+
// half passing alone does not prove the addresses agree.
15+
16+
import { describe, it, expect } from 'vitest';
17+
import { collectExpectedEntries, extractTranslations } from '../src/utils/i18n-extract';
18+
import { computeI18nCoverage } from '../src/utils/i18n-coverage';
19+
import { ActionSchema } from '@objectstack/spec/ui';
20+
import { ObjectTranslationDataSchema } from '@objectstack/spec/system';
21+
22+
const paths = (config: any) => collectExpectedEntries(config).map((e) => e.path.join('.'));
23+
24+
const PARAMS = [{ name: 'subject', label: 'Subject', type: 'text' }];
25+
26+
describe('the extractor emits action-level `submitText` beside a non-empty `params`', () => {
27+
it('emits it for a TOP-LEVEL object action that declares one', () => {
28+
const keys = paths({
29+
actions: [{ name: 'send_email', objectName: 'crm_contact', label: 'Send Email', params: PARAMS, submitText: 'Send' }],
30+
});
31+
32+
expect(keys).toContain('objects.crm_contact._actions.send_email.submitText');
33+
});
34+
35+
it('emits it for a GLOBAL action that declares one', () => {
36+
const keys = paths({
37+
actions: [{ name: 'log_call', label: 'Log Call', params: PARAMS, submitText: 'Log Call' }],
38+
});
39+
40+
expect(keys).toContain('globalActions.log_call.submitText');
41+
});
42+
43+
it('emits it for an action declared INLINE on the object', () => {
44+
const keys = paths({
45+
objects: [
46+
{
47+
name: 'crm_contact',
48+
label: 'Contact',
49+
actions: [{ name: 'send_email', label: 'Send Email', params: PARAMS, submitText: 'Send' }],
50+
},
51+
],
52+
});
53+
54+
expect(keys).toContain('objects.crm_contact._actions.send_email.submitText');
55+
});
56+
57+
it('records a seed-less slot for an action with params that names no verb — the dialog keeps "Confirm"', () => {
58+
const config = {
59+
objects: [{ name: 'crm_contact', label: 'Contact', actions: [{ name: 'send_email', label: 'Send Email', params: PARAMS }] }],
60+
};
61+
const key = 'objects.crm_contact._actions.send_email.submitText';
62+
const entry = collectExpectedEntries(config).find((e) => e.path.join('.') === key);
63+
64+
expect(entry).toBeDefined();
65+
expect(entry?.inline).toBeUndefined();
66+
expect(entry?.sourceValue).toBeUndefined();
67+
68+
const { bundles } = extractTranslations(config, { defaultLocale: 'en', fill: 'default' });
69+
expect(bundles.en.objects?.crm_contact?._actions?.send_email).not.toHaveProperty('submitText');
70+
expect(computeI18nCoverage({ ...config, translations: [{ 'zh-CN': {} }] }).issues.map((i) => i.key))
71+
.not.toContain(key);
72+
});
73+
74+
it('emits NO slot for an action without params — no dialog opens, so there is no button to name', () => {
75+
for (const params of [undefined, []]) {
76+
const keys = paths({
77+
objects: [
78+
{
79+
name: 'crm_contact',
80+
label: 'Contact',
81+
actions: [{ name: 'archive', label: 'Archive', ...(params ? { params } : {}) }],
82+
},
83+
],
84+
actions: [{ name: 'refresh_all', label: 'Refresh', ...(params ? { params } : {}) }],
85+
});
86+
87+
expect(keys).toContain('objects.crm_contact._actions.archive.label');
88+
expect(keys).not.toContain('objects.crm_contact._actions.archive.submitText');
89+
expect(keys).toContain('globalActions.refresh_all.label');
90+
expect(keys).not.toContain('globalActions.refresh_all.submitText');
91+
}
92+
});
93+
94+
it('carries the declared verb into the bundle, and gates it until it is translated', () => {
95+
const config: any = {
96+
objects: [
97+
{
98+
name: 'crm_contact',
99+
label: 'Contact',
100+
actions: [{ name: 'send_email', label: 'Send Email', params: PARAMS, submitText: 'Send' }],
101+
},
102+
],
103+
translations: [
104+
{ 'zh-CN': { objects: { crm_contact: { label: '联系人', _actions: { send_email: { label: '发送邮件', params: { subject: { label: '主题' } } } } } } } },
105+
],
106+
};
107+
const key = 'objects.crm_contact._actions.send_email.submitText';
108+
109+
const entry = collectExpectedEntries(config).find((e) => e.path.join('.') === key);
110+
expect(entry?.source).toBe('action');
111+
expect(entry?.inline).toBe('Send');
112+
113+
const { bundles } = extractTranslations(config, { defaultLocale: 'en', fill: 'default' });
114+
expect(bundles.en.objects?.crm_contact?._actions?.send_email.submitText).toBe('Send');
115+
116+
expect(computeI18nCoverage(config).issues.map((i) => i.key)).toContain(key);
117+
config.translations[0]['zh-CN'].objects.crm_contact._actions.send_email.submitText = '发送';
118+
expect(computeI18nCoverage(config).issues.map((i) => i.key)).not.toContain(key);
119+
});
120+
});
121+
122+
describe('one fixture action, all three surfaces (submitText end-to-end)', () => {
123+
const authored = {
124+
name: 'send_email',
125+
objectName: 'crm_contact',
126+
label: 'Send Email',
127+
type: 'script',
128+
target: 'sendEmail',
129+
params: PARAMS,
130+
submitText: 'Send',
131+
};
132+
133+
it('parses as metadata, extracts to a key, and that key round-trips a bundle', () => {
134+
const parsed = ActionSchema.safeParse(authored);
135+
expect(parsed.success).toBe(true);
136+
expect(parsed.success && parsed.data.submitText).toBe('Send');
137+
138+
const { bundles } = extractTranslations({ actions: [authored] }, {
139+
defaultLocale: 'en',
140+
locales: ['zh-CN'],
141+
fill: 'empty',
142+
});
143+
const bundle: any = bundles['zh-CN'];
144+
expect(bundle.objects.crm_contact._actions.send_email).toHaveProperty('submitText');
145+
146+
bundle.objects.crm_contact._actions.send_email.submitText = '发送';
147+
const translated = ObjectTranslationDataSchema.safeParse(bundle.objects.crm_contact);
148+
expect(translated.success).toBe(true);
149+
expect(translated.success && translated.data._actions?.send_email?.submitText).toBe('发送');
150+
});
151+
});

0 commit comments

Comments
 (0)